pub struct ParserSpec<T: Token + Send + Sync + 'static> { /* private fields */ }Implementations§
Source§impl<T: Token + Send + Sync + 'static> ParserSpec<T>
impl<T: Token + Send + Sync + 'static> ParserSpec<T>
Sourcepub fn new() -> ParserSpec<T>
pub fn new() -> ParserSpec<T>
Examples found in repository?
examples/token_spec.rs (line 33)
32fn token_spec() -> Result<ParserSpec<CToken>, SpecificationError<CToken>> {
33 let mut spec = ParserSpec::new();
34 add_null_assoc!(spec, PrecedenceLevel::Root, (CToken::Number("".to_string()), CToken::Ident("".to_string())) => |_, token: CToken, _| {
35 Ok(Node::Simple(token.clone()))
36 });
37 add_left_assoc!(spec, PrecedenceLevel::First, (CToken::Add, CToken::Sub) => |parser, token, lbp, node| {
38 Ok(Node::Composite { token: token.clone(), children: vec![node, parser.parse_expr(lbp)?] } )
39 } );
40 add_left_assoc!(spec, PrecedenceLevel::Second, (CToken::Mul, CToken::Div, CToken::Mod) => |parser, token, lbp, node| {
41 Ok(Node::Composite { token: token.clone(), children: vec![node, parser.parse_expr(lbp)?] } )
42 } );
43 add_null_assoc!(spec, PrecedenceLevel::First, (CToken::LParens) => |parser, _, lbp| {
44 let res = parser.parse_expr(lbp)?;
45 parser.consume(CToken::RParens)?;
46 Ok(res)
47 });
48 Ok(spec)
49}pub fn add_null_assoc( &mut self, token: impl Into<T>, bp: PrecedenceLevel, func: NullDenotation<T>, ) -> Result<(), SpecificationError<T>>
pub fn add_left_assoc( &mut self, token: impl Into<T>, bp: PrecedenceLevel, func: LeftDenotation<T>, ) -> Result<(), SpecificationError<T>>
pub fn add_left_right_assoc( &mut self, token: impl Into<T>, lbp: PrecedenceLevel, rbp: PrecedenceLevel, func: LeftDenotation<T>, ) -> Result<(), SpecificationError<T>>
pub fn add_null_associations( &mut self, tokens: impl IntoIterator<Item = impl Into<T>>, bp: PrecedenceLevel, func: NullDenotation<T>, ) -> Result<(), SpecificationError<T>>
pub fn add_left_associations( &mut self, tokens: impl IntoIterator<Item = impl Into<T>>, bp: PrecedenceLevel, func: LeftDenotation<T>, ) -> Result<(), SpecificationError<T>>
pub fn add_left_right_associations( &mut self, tokens: impl IntoIterator<Item = impl Into<T>>, lbp: PrecedenceLevel, rbp: PrecedenceLevel, func: LeftDenotation<T>, ) -> Result<(), SpecificationError<T>>
Sourcepub fn maps(
self,
) -> (HashMap<Discriminant<T>, NullInfo<T>>, HashMap<Discriminant<T>, LeftInfo<T>>)
pub fn maps( self, ) -> (HashMap<Discriminant<T>, NullInfo<T>>, HashMap<Discriminant<T>, LeftInfo<T>>)
Consumes a spec and gets the HashMaps used for mapping tokens to syntax rules. This avoids clones and allocations/deallocations of potentially large HashMaps when creating a Parser from the maps.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ParserSpec<T>
impl<T> RefUnwindSafe for ParserSpec<T>
impl<T> Send for ParserSpec<T>
impl<T> Sync for ParserSpec<T>
impl<T> Unpin for ParserSpec<T>
impl<T> UnwindSafe for ParserSpec<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more