pydsl provides verbs, actions that can be executed with any grammar and some data


checker -> grammar_spec -> data -> bool Checker(grammar definition , input) -> bool

Checks if an input conforms a Grammar. Returns True or False.

>>> from pydsl.Grammar import RegularExpression
>>> integer = RegularExpression("^[0123456789]*$")
>>> from pydsl.Check import check
>>> check(integer,"abc")
>>> check(integer,"1234")
Another example:
        class Checker:
            def __init__(self, grammarspec):
                self.grammarspec = grammarspec
            def check (self, data):
                return True


Receives an input and generates an expanded tree known as a parse tree


Lexer(grammar definition, input) -> TokenList (using yield) yields tokens from the input


Guesser(data, memory) -> grammarlist returns the list of grammars that accepts the input data


Validate(grammar definition, input) -> TokenList, Given an input that doesn't belong to a grammar, reports what needs to be fixed in the input to belong to that grammar, the nearest alternative

What's the pydsl approach?

It uses the expanded definition of the input through Parsers. A tree of valid invalid nodes is generates, at the moment you'll need to inspect the tree

>>> from pydsl.Grammar import RegularExpression
>>> from pydsl.File.BNF import load_bnf_file
>>> integer = RegularExpression("^[0123456789]*$")
>>> date = load_bnf_file("pydsl/contrib/grammar/Date.bnf", {'integer':integer, 'DayOfMonth':load_python_file('pydsl/contrib/grammar/')})
>>> from pydsl.Validate import validate
>>> validate(date,"123")
>>> validate(date,"123,3")
>>> validate(date,"123/3")
>>> validate(date,"123/3/13")
>>> validate(date,"12/3/13")


Checks if any slice of the input matches the grammar Extract(grammar definition, input) -> Tokenlist returns a list of segments (tokens) that are accepted words


First(grammar definition) -> returns a set with every possible starting element