use std::str::FromStr; use crate::lexer::{Token, LexicalError}; use crate::expr::{Expr, Span}; grammar(file_id: usize); extern { type Location = usize; type Error = LexicalError; enum Token { "(" => Token::LPren, ")" => Token::RPren, "true" => Token::True, "false" => Token::False, "string" => Token::StrLit(), "number" => Token::NumLit(), "symbol" => Token::Symbol(), "keyword" => Token::Keyword(), "comment" => Token::Comment, } } pub Expr: Expr = { "(" )+> ")" => Expr::List(Span(l, r, file_id), elems), => x, => x, => Expr::Value(Span(l, r, file_id), x), "comment" => Expr::Comment(Span(l, r, file_id)), }; Keyword: Expr = => Expr::Keyword(Span(l, r, file_id), x.to_string()); Symbol: Expr = => Expr::Symbol(Span(l, r, file_id), x.to_string()); Value: String = { => <>, => <>, => <>, }; StrLit: String = { => { x[1..x.len() - 1].to_owned() }, }; Num: String = <"number"> => <>.to_string(); Bool: String = { "true" => "true".to_string(), "false" => "false".to_string(), } // vim:shiftwidth=4