Bool, Abool and Nil values are no longer tokens

This commit is contained in:
Erin 2022-03-01 18:57:03 +01:00 committed by ondra05
parent 55a455d110
commit a3c0e65f6b
3 changed files with 7 additions and 36 deletions

View file

@ -30,6 +30,12 @@ pub fn ablescript_consts() -> HashMap<String, Variable> {
), ),
("OCTOTHORPE", Str("#".to_owned())), // It's an octothorpe ("OCTOTHORPE", Str("#".to_owned())), // It's an octothorpe
("ANSWER", Int(ANSWER)), ("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() .into_iter()
.map(|(name, value)| (name.to_owned(), Variable::from_value(value))) .map(|(name, value)| (name.to_owned(), Variable::from_value(value)))

View file

@ -113,14 +113,6 @@ pub enum Token {
Rickroll, Rickroll,
// Literals // Literals
/// True, False
#[regex("true|false", get_value)]
Bool(bool),
/// Always, Sometimes, Never
#[regex("always|sometimes|never", get_abool)]
Abool(Abool),
/// String /// String
#[regex(r"/\*([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*]*\*/)", get_string)] #[regex(r"/\*([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*]*\*/)", get_string)]
String(String), String(String),
@ -136,9 +128,6 @@ pub enum Token {
#[regex(r"owo .*")] #[regex(r"owo .*")]
Comment, Comment,
#[regex("nul")]
Nul,
#[regex(r"[ \t\n\f]+", logos::skip)] #[regex(r"[ \t\n\f]+", logos::skip)]
#[error] #[error]
Error, Error,
@ -156,15 +145,6 @@ fn get_string(lexer: &mut Lexer<Token>) -> String {
.to_owned() .to_owned()
} }
fn get_abool(lexer: &mut Lexer<Token>) -> Option<Abool> {
match lexer.slice() {
"always" => Some(Abool::Always),
"sometimes" => Some(Abool::Sometimes),
"never" => Some(Abool::Never),
_ => None,
}
}
fn get_ident(lexer: &mut Lexer<Token>) -> String { fn get_ident(lexer: &mut Lexer<Token>) -> String {
lexer.slice().to_owned() lexer.slice().to_owned()
} }

View file

@ -97,9 +97,6 @@ impl<'source> Parser<'source> {
Token::Identifier(_) Token::Identifier(_)
| Token::String(_) | Token::String(_)
| Token::Integer(_) | Token::Integer(_)
| Token::Abool(_)
| Token::Bool(_)
| Token::Nul
| Token::Not | Token::Not
| Token::LeftBracket | Token::LeftBracket
| Token::LeftParen => Ok(Stmt::new( | Token::LeftParen => Ok(Stmt::new(
@ -167,14 +164,6 @@ impl<'source> Parser<'source> {
}), }),
start..self.lexer.span().end, 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( Token::Integer(i) => Ok(Expr::new(
ExprKind::Literal(Value::Int(i)), ExprKind::Literal(Value::Int(i)),
start..self.lexer.span().end, start..self.lexer.span().end,
@ -187,10 +176,6 @@ impl<'source> Parser<'source> {
})), })),
start..self.lexer.span().end, start..self.lexer.span().end,
)), )),
Token::Nul => Ok(Expr::new(
ExprKind::Literal(Value::Nul),
start..self.lexer.span().end,
)),
Token::LeftBracket => match buf.take() { Token::LeftBracket => match buf.take() {
Some(buf) => Ok(Expr::new( Some(buf) => Ok(Expr::new(