Trait teleparse::AbstractSyntaxTree

source ·
pub trait AbstractSyntaxTree: Sized + ToSpan + 'static {
    type L: Lexicon + 'static;

    // Required methods
    fn build_first(builder: &mut FirstBuilder<Self::L>);
    fn check_left_recursive(
        seen: &mut BTreeSet<TypeId>,
        stack: &mut Vec<String>,
        set: &mut BTreeSet<TypeId>,
        first: &First<Self::L>,
    ) -> Result<(), GrammarError>;
    fn check_first_conflict(
        seen: &mut BTreeSet<TypeId>,
        first: &First<Self::L>,
    ) -> Result<(), GrammarError>;
    fn build_follow(builder: &mut FollowBuilder<Self::L>);
    fn check_first_follow_conflict(
        seen: &mut BTreeSet<TypeId>,
        first: &First<Self::L>,
        follow: &Follow<Self::L>,
    ) -> Result<(), GrammarError>;
    fn build_jump(
        seen: &mut BTreeSet<TypeId>,
        first: &First<Self::L>,
        jump: &mut Jump<Self::L>,
    );
    fn parse_ast<'s>(
        parser: &mut Parser<'s, Self::L>,
        meta: &Metadata<Self::L>,
    ) -> Result<Self, Self::L>;

    // Provided methods
    fn type_id() -> TypeId { ... }
    fn debug() -> Cow<'static, str> { ... }
    fn check_self_first_follow_conflict(
        first: &First<Self::L>,
        follow: &Follow<Self::L>,
    ) -> Result<(), GrammarError> { ... }
}
Expand description

An AST node

See module-level documentation for more information.

Required Associated Types§

source

type L: Lexicon + 'static

The token type of the AST node

Required Methods§

source

fn build_first(builder: &mut FirstBuilder<Self::L>)

Add the rules for this AST node (recursively) to the FIRST function builder.

Note this may not terminate if the grammar is left-recursive

source

fn check_left_recursive( seen: &mut BTreeSet<TypeId>, stack: &mut Vec<String>, set: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

Check if the grammar at this AST node is left-recursive

Left-recursion will lead to infinite recursion when parsing, so it is not allowed

source

fn check_first_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

Check for conflicts in the FIRST set of this AST node

source

fn build_follow(builder: &mut FollowBuilder<Self::L>)

Add the rules for this AST node (recursively) to the FOLLOW function builder.

source

fn check_first_follow_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, follow: &Follow<Self::L>, ) -> Result<(), GrammarError>

Check for conflicts in the FIRST and FOLLOW set of this AST node recursively

source

fn build_jump( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, jump: &mut Jump<Self::L>, )

Recursively build the parsing table for this AST node.

See Predictive parsing table for more information.

source

fn parse_ast<'s>( parser: &mut Parser<'s, Self::L>, meta: &Metadata<Self::L>, ) -> Result<Self, Self::L>

Parse this AST node from the input stream

Provided Methods§

source

fn type_id() -> TypeId

Get the unique type id of the AST node, which represents one production in the grammar (multiple production in case of a union/enum)

source

fn debug() -> Cow<'static, str>

Get the type name for the AST node for debugging

source

fn check_self_first_follow_conflict( first: &First<Self::L>, follow: &Follow<Self::L>, ) -> Result<(), GrammarError>

Check if epsilon is in FIRST(t) and FIRST(t) intersect FOLLOW(t)

This is used in derived AST implementations to check for conflicts

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<A: AbstractSyntaxTree, B: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>> AbstractSyntaxTree for (A, B)

§

type L = <A as AbstractSyntaxTree>::L

source§

fn build_first(builder: &mut FirstBuilder<Self::L>)

source§

fn check_left_recursive( seen: &mut BTreeSet<TypeId>, stack: &mut Vec<String>, set: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn check_first_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_follow(builder: &mut FollowBuilder<Self::L>)

source§

fn check_first_follow_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, follow: &Follow<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_jump( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, jump: &mut Jump<Self::L>, )

source§

fn debug() -> Cow<'static, str>

source§

fn parse_ast<'s>( parser: &mut Parser<'s, Self::L>, meta: &Metadata<Self::L>, ) -> Result<Self, Self::L>

source§

impl<A: AbstractSyntaxTree, B: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>, C: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>> AbstractSyntaxTree for (A, B, C)

§

type L = <A as AbstractSyntaxTree>::L

source§

fn build_first(builder: &mut FirstBuilder<Self::L>)

source§

fn check_left_recursive( seen: &mut BTreeSet<TypeId>, stack: &mut Vec<String>, set: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn check_first_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_follow(builder: &mut FollowBuilder<Self::L>)

source§

fn check_first_follow_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, follow: &Follow<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_jump( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, jump: &mut Jump<Self::L>, )

source§

fn debug() -> Cow<'static, str>

source§

fn parse_ast<'s>( parser: &mut Parser<'s, Self::L>, meta: &Metadata<Self::L>, ) -> Result<Self, Self::L>

source§

impl<A: AbstractSyntaxTree, B: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>, C: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>, D: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>> AbstractSyntaxTree for (A, B, C, D)

§

type L = <A as AbstractSyntaxTree>::L

source§

fn build_first(builder: &mut FirstBuilder<Self::L>)

source§

fn check_left_recursive( seen: &mut BTreeSet<TypeId>, stack: &mut Vec<String>, set: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn check_first_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_follow(builder: &mut FollowBuilder<Self::L>)

source§

fn check_first_follow_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, follow: &Follow<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_jump( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, jump: &mut Jump<Self::L>, )

source§

fn debug() -> Cow<'static, str>

source§

fn parse_ast<'s>( parser: &mut Parser<'s, Self::L>, meta: &Metadata<Self::L>, ) -> Result<Self, Self::L>

source§

impl<A: AbstractSyntaxTree, B: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>, C: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>, D: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>, E: AbstractSyntaxTree<L = <A as AbstractSyntaxTree>::L>> AbstractSyntaxTree for (A, B, C, D, E)

§

type L = <A as AbstractSyntaxTree>::L

source§

fn build_first(builder: &mut FirstBuilder<Self::L>)

source§

fn check_left_recursive( seen: &mut BTreeSet<TypeId>, stack: &mut Vec<String>, set: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn check_first_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_follow(builder: &mut FollowBuilder<Self::L>)

source§

fn check_first_follow_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, follow: &Follow<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_jump( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, jump: &mut Jump<Self::L>, )

source§

fn debug() -> Cow<'static, str>

source§

fn parse_ast<'s>( parser: &mut Parser<'s, Self::L>, meta: &Metadata<Self::L>, ) -> Result<Self, Self::L>

source§

impl<AST: AbstractSyntaxTree> AbstractSyntaxTree for Box<AST>

§

type L = <AST as AbstractSyntaxTree>::L

source§

fn type_id() -> TypeId

source§

fn debug() -> Cow<'static, str>

source§

fn build_first(builder: &mut FirstBuilder<Self::L>)

source§

fn check_left_recursive( seen: &mut BTreeSet<TypeId>, stack: &mut Vec<String>, set: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn check_first_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_follow(builder: &mut FollowBuilder<Self::L>)

source§

fn check_first_follow_conflict( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, follow: &Follow<Self::L>, ) -> Result<(), GrammarError>

source§

fn build_jump( seen: &mut BTreeSet<TypeId>, first: &First<Self::L>, jump: &mut Jump<Self::L>, )

source§

fn parse_ast<'s>( parser: &mut Parser<'s, Self::L>, meta: &Metadata<Self::L>, ) -> SynResult<Self, Self::L>

Implementors§