ast: make static an entity
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
@@ -12,6 +12,7 @@ pub enum Entity {
|
|||||||
Fn(Fn),
|
Fn(Fn),
|
||||||
Class(Class),
|
Class(Class),
|
||||||
Module(Module),
|
Module(Module),
|
||||||
|
Static(Let)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A module just provides an additional scope
|
/// A module just provides an additional scope
|
||||||
|
@@ -136,8 +136,8 @@ pub struct Lexer<'a> {
|
|||||||
/// A peekable double ended queue for the tokens
|
/// A peekable double ended queue for the tokens
|
||||||
tokens: VecDeque<Token>,
|
tokens: VecDeque<Token>,
|
||||||
/// Current line number
|
/// Current line number
|
||||||
pub line: usize,
|
pub(crate) line: usize,
|
||||||
pub col: usize,
|
pub(crate) col: usize,
|
||||||
/// Start character index for the current token
|
/// Start character index for the current token
|
||||||
start: usize,
|
start: usize,
|
||||||
/// End character index for the current token
|
/// End character index for the current token
|
||||||
|
@@ -9,21 +9,22 @@ use crate::lexer::{
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
/// entity ::= module | class | fn
|
/// entity ::= module | class | fn | static
|
||||||
pub(super) fn parse_entity(&mut self) -> Option<Entity> {
|
pub(super) fn parse_entity(&mut self) -> Option<Entity> {
|
||||||
use TokenKeyword::*;
|
use TokenKeyword::*;
|
||||||
let token = self.peek_token();
|
let token = self.peek_token();
|
||||||
|
|
||||||
if let TokenKind::Keyword(keyword) = &token.kind {
|
if let TokenKind::Keyword(keyword) = &token.kind {
|
||||||
match keyword {
|
Some(match keyword {
|
||||||
Module => Some(Entity::Module(self.parse_module()?)),
|
Module => Entity::Module(self.parse_module()?),
|
||||||
Class => Some(Entity::Class(self.parse_class()?)),
|
Class => Entity::Class(self.parse_class()?),
|
||||||
Fn => Some(Entity::Fn(self.parse_fn()?)),
|
Fn => Entity::Fn(self.parse_fn()?),
|
||||||
|
Static => Entity::Static(self.parse_static()?),
|
||||||
_ => {
|
_ => {
|
||||||
self.error_expected_peek("entity");
|
self.error_expected_peek("entity");
|
||||||
None
|
return None;
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
} else {
|
} else {
|
||||||
self.error_expected_peek("entity");
|
self.error_expected_peek("entity");
|
||||||
None
|
None
|
||||||
|
Reference in New Issue
Block a user