Add pub and use keywords and parse them#256
Add pub and use keywords and parse them#256KyrylR merged 1 commit intoBlockstreamResearch:dev/importsfrom
pub and use keywords and parse them#256Conversation
src/lexer.rs
Outdated
| pub type Spanned<T> = (T, SimpleSpan); | ||
| pub type Tokens<'src> = Vec<(Token<'src>, crate::error::Span)>; | ||
|
|
||
| /// # Architecture Note: Omitted Keywords |
There was a problem hiding this comment.
It explains why the compiler does not need the super and crate keywords at all.
src/parse.rs
Outdated
| TypeAlias(TypeAlias), | ||
| /// A function. | ||
| Function(Function), | ||
| /// Use keyword to load other items |
src/parse.rs
Outdated
| /// Definition of a declaration | ||
| #[derive(Clone, Debug)] | ||
| #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] | ||
| pub struct UseDecl { | ||
| visibility: Visibility, | ||
| path: Vec<Identifier>, | ||
| items: UseItems, | ||
| span: Span, | ||
| } | ||
|
|
||
| impl UseDecl { | ||
| /// Access the visibility of the use declaration. | ||
| pub fn visibility(&self) -> &Visibility { | ||
| &self.visibility | ||
| } | ||
|
|
||
| /// Access the visibility of the function. | ||
| pub fn path(&self) -> &Vec<Identifier> { | ||
| &self.path | ||
| } | ||
|
|
||
| /// Access the visibility of the function. | ||
| pub fn items(&self) -> &UseItems { | ||
| &self.items | ||
| } | ||
|
|
||
| /// Access the span of the use declaration. | ||
| pub fn span(&self) -> &Span { | ||
| &self.span | ||
| } | ||
| } |
There was a problem hiding this comment.
Let's not add docs for self-explanatory fns
src/parse.rs
Outdated
| } | ||
|
|
||
| impl Function { | ||
| /// Access the visibility of the function. |
src/ast.rs
Outdated
| parse::Item::Function(function) => { | ||
| Function::analyze(function, ty, scope).map(Self::Function) | ||
| } | ||
| parse::Item::Use(_) => todo!(), |
There was a problem hiding this comment.
Let's do the reject gracefully, just in case
src/parse.rs
Outdated
e378410 to
5bcf426
Compare
5bcf426 to
4c8ee5e
Compare
| #[derive(Clone, Debug)] | ||
| #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] | ||
| pub struct UseDecl { | ||
| visibility: Visibility, | ||
| path: Vec<Identifier>, | ||
| items: UseItems, | ||
| span: Span, | ||
| } |
There was a problem hiding this comment.
Could you add a rust doc explaining what is an intention for those fields?
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
| #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] | ||
| pub enum UseItems { | ||
| Single(Identifier), | ||
| List(Vec<Identifier>), | ||
| } |
src/parse.rs
Outdated
| #[derive(Clone, Debug, PartialEq, Eq, Hash, Default)] | ||
| #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] | ||
| pub enum Visibility { | ||
| Public, | ||
| #[default] | ||
| Private, | ||
| } |
There was a problem hiding this comment.
Could you move this above UseDecl?
577e0a7 to
2328407
Compare
|
Pls add description |
|
Why |
|
Why |
2328407 to
0656bb2
Compare
I have updated this code to require at least three path segments. This is necessary because we cannot load specific functionality without at least three items in the path. The first is the alias, the second is the specific file, and the third is the specific function or item being imported. This logic enforced in the following segment of let path = Identifier::parser()
.then_ignore(just(Token::DoubleColon))
.repeated()
.at_least(2)
.collect::<Vec<_>>(); |
0656bb2 to
5fcfb76
Compare
5fcfb76 to
0f853eb
Compare
This PR introduces the baseline architecture for dependency and import resolution. As part of the larger module system roadmap, this is a scoped implementation focused strictly on parsing
usestatements and visibility.