use proc_macro2::{ TokenStream, Ident, Literal }; #[derive(Debug)] pub struct Grammar { pub doc: Option, pub visibility: Option, pub name: Ident, pub args: Vec<(Ident, TokenStream)>, pub items: Vec, pub input_type: TokenStream, } impl Grammar { pub fn iter_rules(&self) -> impl Iterator { self.items.iter().filter_map(|item| { match item { Item::Rule(r) => Some(r), _ => None } }) } } #[derive(Debug)] pub enum Item { Use(TokenStream), Rule(Rule), } #[derive(Debug)] pub struct Rule { pub name: Ident, pub ty_params: Option>, pub params: Vec, pub expr: Expr, pub ret_type: Option, pub doc: Option, pub visibility: Option, pub cached: bool, } #[derive(Debug)] pub struct RuleParam { pub name: Ident, pub ty: RuleParamTy, } #[derive(Debug)] pub enum RuleParamTy { Rust(TokenStream), Rule(TokenStream), } #[derive(Debug, Clone)] pub struct TaggedExpr { pub name: Option, pub expr: Expr, } #[derive(Debug, Clone)] pub enum Expr { LiteralExpr(Literal), PatternExpr(TokenStream), RuleExpr(Ident, Vec), MethodExpr(Ident, TokenStream), ChoiceExpr(Vec), OptionalExpr(Box), Repeat(Box, BoundedRepeat, /*sep*/ Option>), PosAssertExpr(Box), NegAssertExpr(Box), ActionExpr(Vec, /*action*/ Option, /*cond*/ bool), MatchStrExpr(Box), PositionExpr, QuietExpr(Box), FailExpr(Literal), PrecedenceExpr{ levels: Vec }, MarkerExpr(bool), } #[derive(Debug, Clone)] pub enum RuleArg { Rust(TokenStream), Peg(Expr), } #[derive(Debug, Clone)] pub struct PrecedenceLevel { pub operators: Vec, } #[derive(Debug, Clone)] pub struct PrecedenceOperator { pub elements: Vec, pub action: TokenStream, } #[derive(Debug, Clone)] pub enum BoundedRepeat { None, Plus, Exact(TokenStream), Both(Option, Option), }