forked from natto1784/tricc
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),
|
||||
Class(Class),
|
||||
Module(Module),
|
||||
Static(Let)
|
||||
}
|
||||
|
||||
/// A module just provides an additional scope
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user