From b975bc52d09fe91951eaae944bfe417ea6e6c3eb Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 1 Mar 2022 18:57:03 +0100 Subject: [PATCH] Bool, Abool and Nil values are no longer tokens --- ablescript/src/consts.rs | 6 ++++++ ablescript/src/lexer.rs | 20 -------------------- ablescript/src/parser.rs | 17 +---------------- 3 files changed, 7 insertions(+), 36 deletions(-) diff --git a/ablescript/src/consts.rs b/ablescript/src/consts.rs index e09b781..edc4968 100644 --- a/ablescript/src/consts.rs +++ b/ablescript/src/consts.rs @@ -30,6 +30,12 @@ pub fn ablescript_consts() -> HashMap { ), ("OCTOTHORPE", Str("#".to_owned())), // It's an octothorpe ("ANSWER", Int(ANSWER)), + ("nul", Nul), + ("true", Bool(true)), + ("false", Bool(false)), + ("always", Abool(crate::variables::Abool::Always)), + ("sometimes", Abool(crate::variables::Abool::Sometimes)), + ("never", Abool(crate::variables::Abool::Never)), ] .into_iter() .map(|(name, value)| (name.to_owned(), Variable::from_value(value))) diff --git a/ablescript/src/lexer.rs b/ablescript/src/lexer.rs index 480c073..1ae88ab 100644 --- a/ablescript/src/lexer.rs +++ b/ablescript/src/lexer.rs @@ -113,14 +113,6 @@ pub enum Token { Rickroll, // Literals - /// True, False - #[regex("true|false", get_value)] - Bool(bool), - - /// Always, Sometimes, Never - #[regex("always|sometimes|never", get_abool)] - Abool(Abool), - /// String #[regex(r"/\*([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*]*\*/)", get_string)] String(String), @@ -136,9 +128,6 @@ pub enum Token { #[regex(r"owo .*")] Comment, - #[regex("nul")] - Nul, - #[regex(r"[ \t\n\f]+", logos::skip)] #[error] Error, @@ -156,15 +145,6 @@ fn get_string(lexer: &mut Lexer) -> String { .to_owned() } -fn get_abool(lexer: &mut Lexer) -> Option { - match lexer.slice() { - "always" => Some(Abool::Always), - "sometimes" => Some(Abool::Sometimes), - "never" => Some(Abool::Never), - _ => None, - } -} - fn get_ident(lexer: &mut Lexer) -> String { lexer.slice().to_owned() } diff --git a/ablescript/src/parser.rs b/ablescript/src/parser.rs index d9612f3..52a8577 100644 --- a/ablescript/src/parser.rs +++ b/ablescript/src/parser.rs @@ -97,9 +97,6 @@ impl<'source> Parser<'source> { Token::Identifier(_) | Token::String(_) | Token::Integer(_) - | Token::Abool(_) - | Token::Bool(_) - | Token::Nul | Token::Not | Token::LeftBracket | Token::LeftParen => Ok(Stmt::new( @@ -167,14 +164,6 @@ impl<'source> Parser<'source> { }), start..self.lexer.span().end, )), - Token::Abool(a) => Ok(Expr::new( - ExprKind::Literal(Value::Abool(a)), - start..self.lexer.span().end, - )), - Token::Bool(b) => Ok(Expr::new( - ExprKind::Literal(Value::Bool(b)), - start..self.lexer.span().end, - )), Token::Integer(i) => Ok(Expr::new( ExprKind::Literal(Value::Int(i)), start..self.lexer.span().end, @@ -187,11 +176,7 @@ impl<'source> Parser<'source> { })), start..self.lexer.span().end, )), - Token::Nul => Ok(Expr::new( - ExprKind::Literal(Value::Nul), - start..self.lexer.span().end, - )), - + Token::LeftBracket => match buf.take() { Some(buf) => Ok(Expr::new( self.index_flow(buf)?,