handball/src/grammar.lalrpop

33 lines
556 B
Plaintext

use crate::{Token, Tree, Val};
grammar<'s>();
pub(crate) Trees = Tree*;
Tree: Tree<'s> = {
"(" <Trees> ")" => Tree::Branch(<>),
Val => Tree::Leaf(<>)
}
Val: Val<'s> = {
"@int" => Val::Int(<>),
"@float" => Val::Float(<>),
"@id" => Val::Ident(<>),
}
extern {
type Location = usize;
type Error = crate::LexError;
enum Token<'s> {
"(" => Token::Lparen,
")" => Token::Rparen,
"@id" => Token::Ident(<&'s str>),
"@int" => Token::Int(<i64>),
"@float" => Token::Float(<f64>),
}
}