Grammar Base Class: Module grammar

This class provide the composition mechanism.

Inheritance diagram of pyrser.grammar

class pyrser.grammar.MetaGrammar[source]

Bases: pyrser.parsing.base.MetaBasicParser

Metaclass for all grammars.

static __new__(metacls, name, bases, namespace)[source]
class pyrser.grammar.Grammar(content: str='', stream_name: str=None, raise_diagnostic=True)[source]

Bases: pyrser.parsing.base.Parser

Base class for all grammars.

This class turn any class A that inherit it into a grammar. Taking the description of the grammar in parameter it will add all what is what is needed for A to parse it.

grammar = None
entry = None
dsl_parser

alias of EBNF

after_parse(self, node: Node) → Node[source]

If you want to do some stuff after parsing, overload this...

_do_parse(self, entry: str) → Node[source]
parse(self, source: str= None, entry: str= None) → Node[source]

Parse source using the grammar

parse_file(self, filename: str, entry: str= None) → Node[source]

Parse filename using the grammar

pyrser.grammar.build_grammar(inherit: tuple, scope: dict) → Grammar[source]
pyrser.grammar.from_string(bnf: str, entry= None, optional_inherit) → Grammar[source]

Create a Grammar from a string

pyrser.grammar.from_file(fn: str, entry= None, optional_inherit) → Grammar[source]

Create a Grammar from a file