Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Architecture Note: Omitted Keywords
The `crate` and `super` keywords were not added to the compiler because they
are unnecessary at this stage. Typically, they are used to resolve relative
paths during import parsing. However, in our architecture, the prefix before
the first `::` in a `use` statement is always an dependency root path. Since all
dependency root paths are unique and strictly bound to specific paths, the resolver
can always unambiguously resolve the path without needing relative pointers.
4 changes: 4 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,10 @@ impl AbstractSyntaxTree for Item {
parse::Item::Function(function) => {
Function::analyze(function, ty, scope).map(Self::Function)
}
parse::Item::Use(use_decl) => Err(RichError::new(
Error::CannotCompile("The `use` keyword is not supported yet.".to_string()),
*use_decl.span(),
)),
parse::Item::Module => Ok(Self::Module),
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub type Tokens<'src> = Vec<(Token<'src>, crate::error::Span)>;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Token<'src> {
// Keywords
Pub,
Use,
Fn,
Let,
Type,
Expand Down Expand Up @@ -66,6 +68,8 @@ pub enum Token<'src> {
impl<'src> fmt::Display for Token<'src> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Token::Pub => write!(f, "pub"),
Token::Use => write!(f, "use"),
Token::Fn => write!(f, "fn"),
Token::Let => write!(f, "let"),
Token::Type => write!(f, "type"),
Expand Down Expand Up @@ -138,6 +142,8 @@ pub fn lexer<'src>(
choice((just("assert!"), just("panic!"), just("dbg!"), just("list!"))).map(Token::Macro);

let keyword = text::ident().map(|s| match s {
"pub" => Token::Pub,
"use" => Token::Use,
"fn" => Token::Fn,
"let" => Token::Let,
"type" => Token::Type,
Expand Down Expand Up @@ -247,7 +253,7 @@ pub fn lex<'src>(input: &'src str) -> (Option<Tokens<'src>>, Vec<crate::error::R
pub fn is_keyword(s: &str) -> bool {
matches!(
s,
"fn" | "let" | "type" | "mod" | "const" | "match" | "true" | "false"
"pub" | "use" | "fn" | "let" | "type" | "mod" | "const" | "match" | "true" | "false"
)
}

Expand Down
Loading
Loading