ast: make static an entity

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-08-13 22:20:51 +05:30
parent f7ec10646b
commit 360687f3c0
3 changed files with 11 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ pub enum Entity {
Fn(Fn),
Class(Class),
Module(Module),
Static(Let)
}
/// A module just provides an additional scope

View File

@@ -136,8 +136,8 @@ pub struct Lexer<'a> {
/// A peekable double ended queue for the tokens
tokens: VecDeque<Token>,
/// Current line number
pub line: usize,
pub col: usize,
pub(crate) line: usize,
pub(crate) col: usize,
/// Start character index for the current token
start: usize,
/// End character index for the current token

View File

@@ -9,21 +9,22 @@ use crate::lexer::{
use std::rc::Rc;
impl<'a> Parser<'a> {
/// entity ::= module | class | fn
/// entity ::= module | class | fn | static
pub(super) fn parse_entity(&mut self) -> Option<Entity> {
use TokenKeyword::*;
let token = self.peek_token();
if let TokenKind::Keyword(keyword) = &token.kind {
match keyword {
Module => Some(Entity::Module(self.parse_module()?)),
Class => Some(Entity::Class(self.parse_class()?)),
Fn => Some(Entity::Fn(self.parse_fn()?)),
Some(match keyword {
Module => Entity::Module(self.parse_module()?),
Class => Entity::Class(self.parse_class()?),
Fn => Entity::Fn(self.parse_fn()?),
Static => Entity::Static(self.parse_static()?),
_ => {
self.error_expected_peek("entity");
None
return None;
}
}
})
} else {
self.error_expected_peek("entity");
None