use std::str::FromStr; use crate::lexer::{Token, LexicalError}; use crate::ast::{Ast, 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 Ast: Ast = { "(" )+> ")" => Ast::List(Span(l, r, file_id), elems), => x, => x, => Ast::Value(Span(l, r, file_id), x), "comment" => Ast::Comment(Span(l, r, file_id)), }; Keyword: Ast = => Ast::Keyword(Span(l, r, file_id), x.to_string()); Symbol: Ast = => Ast::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