This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This requires users to explicitly specify the package in which such hidden identifiers should be scoped. Note: 1) Hid is not called Hidden because this was already taken. Maybe in a big API rework some renaming would be handy. 2) We do not allow "" to mean the anonymous packages, as this will allow using this to mean the "top-level" package in the future, which will be the common case. 3) When converting from AST identifiers, we could see if it is bound to a certain package already and then use that scope. This does not conflict with the current API. Change-Id: If3438b84b2f6032072342abe58cde1e1bafdc4f3 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9185 Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
- Loading branch information
Showing
9 changed files
with
182 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2021 CUE Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cue_test | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"cuelang.org/go/cue" | ||
"cuelang.org/go/internal/cuetxtar" | ||
"github.com/rogpeppe/go-internal/txtar" | ||
) | ||
|
||
func load(file string) *cue.Instance { | ||
dir, _ := ioutil.TempDir("", "*") | ||
defer os.RemoveAll(dir) | ||
|
||
inst := cue.Build(cuetxtar.Load(txtar.Parse([]byte(file)), dir))[0] | ||
if err := inst.Err; err != nil { | ||
panic(err) | ||
} | ||
return inst | ||
} | ||
|
||
func ExampleHid() { | ||
const file = ` | ||
-- cue.mod/module.cue -- | ||
module: "acme.com" | ||
-- main.cue -- | ||
import "acme.com/foo:bar" | ||
bar | ||
_foo: int // scoped in main (anonymous) package | ||
baz: _foo | ||
-- foo/bar.cue -- | ||
package bar | ||
_foo: int // scoped within imported package | ||
bar: _foo | ||
` | ||
|
||
v := load(file).Value() | ||
|
||
v = v.FillPath(cue.MakePath(cue.Hid("_foo", "acme.com/foo:bar")), 1) | ||
v = v.FillPath(cue.MakePath(cue.Hid("_foo", "_")), 2) | ||
fmt.Println(v.LookupPath(cue.ParsePath("bar")).Int64()) | ||
fmt.Println(v.LookupPath(cue.ParsePath("baz")).Int64()) | ||
|
||
// Output: | ||
// 1 <nil> | ||
// 2 <nil> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters