Skip to content

Commit

Permalink
feat(parser): support for mutable variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Mar 7, 2024
1 parent a436b6b commit 60a202b
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/fuse-ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub enum BindingPatternKind {
pub struct BindingIdentifier {
pub span: Span,
pub atom: Atom,
pub mutable: bool,
}

#[serializable]
Expand Down
4 changes: 2 additions & 2 deletions crates/fuse-ast/src/ast_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ impl AstFactory {
}
}

pub fn binding_identifier(&self, span: Span, atom: Atom) -> BindingIdentifier {
BindingIdentifier { span, atom }
pub fn binding_identifier(&self, span: Span, atom: Atom, mutable: bool) -> BindingIdentifier {
BindingIdentifier { span, atom, mutable }
}

pub fn atom(&self, value: &str) -> Atom {
Expand Down
1 change: 1 addition & 0 deletions crates/fuse-parser/src/lexer/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl<'a> Lexer<'a> {
}
'm' => {
"atch" => TokenKind::Match,
"ut" => TokenKind::Mut,
}
'n' => {
"ever" => TokenKind::Never,
Expand Down
2 changes: 2 additions & 0 deletions crates/fuse-parser/src/lexer/token_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ pub enum TokenKind {
In,
Let,
Match,
Mut,
Never,
Nil,
Not,
Pub,
Or,
Own,
Repeat,
Return,
/// Lower case `self`
Expand Down
4 changes: 3 additions & 1 deletion crates/fuse-parser/src/parsers/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ impl<'a> Parser<'a> {

span = self.end_span(span);

let mutable = self.consume_if(TokenKind::Mut).is_some();

let atom = self.ast.atom(name);

self.ast.binding_identifier(span, atom)
self.ast.binding_identifier(span, atom, mutable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Some(Chunk(
end: 15,
),
atom: Atom("a"),
mutable: false,
)),
type_annotation: None,
optional: false,
Expand All @@ -57,6 +58,7 @@ Some(Chunk(
end: 18,
),
atom: Atom("b"),
mutable: false,
)),
type_annotation: None,
optional: false,
Expand All @@ -74,6 +76,7 @@ Some(Chunk(
end: 21,
),
atom: Atom("c"),
mutable: false,
)),
type_annotation: None,
optional: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Some(Chunk(
end: 9,
),
atom: Atom("a"),
mutable: false,
)),
type_annotation: None,
optional: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Some(Chunk(
end: 4,
),
atom: Atom("a"),
mutable: false,
)),
type_annotation: None,
optional: false,
Expand All @@ -51,6 +52,7 @@ Some(Chunk(
end: 7,
),
atom: Atom("b"),
mutable: false,
)),
type_annotation: None,
optional: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Some(Chunk(
end: 8,
),
atom: Atom("value"),
mutable: false,
)),
type_annotation: None,
optional: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Some(Chunk(
end: 6,
),
atom: Atom("id"),
mutable: false,
)),
type_annotation: None,
optional: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Some(Chunk(
end: 6,
),
atom: Atom("id"),
mutable: false,
)),
type_annotation: None,
optional: false,
Expand Down

0 comments on commit 60a202b

Please sign in to comment.