conlang: Import items into scope with use!

grammar:
- Improve specification of `Path`
- Add `Use` and `UseTree` rules
- Add `Use` as a variant of ItemKind

cl-token:
- Add new keywords `use` and `as`

cl-ast:
- Add nodes for Use and UseTree
- Add new ItemKind for Use
- Implement traversal in Visit and Fold

cl-interpret:
- Mark ItemKind::Use with a todo

cl-parser:
- Update to match grammar

cl-typeck:
- Update to match changes in AST
- Mark UseTrees as NameCollectable and TypeResolvable, but leave as todos
This commit is contained in:
2024-04-20 14:51:54 -05:00
parent 9dc0cc7841
commit efd442bbfa
11 changed files with 192 additions and 11 deletions

View File

@@ -15,7 +15,7 @@ Meta = Identifier ('=' Literal | '(' (Literal ',')* Literal? ')')? ;
Item = Attrs Visibility ItemKind ;
ItemKind = Const | Static | Module
| Function | Struct | Enum
| Alias | Impl ;
| Alias | Impl | Use ;
(* item *)
@@ -45,6 +45,10 @@ Alias = "type" Identifier ('=' Ty)? ';' ;
Impl = "impl" Path '{' Item* '}' ;
(* TODO: Impl Trait for Target*)
Use = "use" UseTree ;
UseTree = Path '{' (UseTree ',')* UseTree? '}'
| Path "as" Identifier
| Path | '*' ;
(* type *)
Ty = Never | Empty | Path | TyTuple | TyRef | TyFn ;
@@ -57,7 +61,8 @@ TyFn = "fn" TyTuple ('->' Ty)? ;
(* path *)
Path = '::'? PathPart ('::' PathPart)* ;
Path = PathPart ('::' PathPart)*
| '::' (PathPart ('::' PathPart)*)? ;
PathPart = "super" | "self" | Identifier ;
Identifier = IDENTIFIER ;