Bool, Abool and Nil values are no longer tokens

pull/6/head
ondra05 2022-03-01 18:57:03 +01:00
parent 8c369d5cfc
commit 816cb9ac82
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
("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)))

View File

@ -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<Token>) -> String {
.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 {
lexer.slice().to_owned()
}

View File

@ -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)?,