Reference¶
Parsing¶
-
class
axaxaxas.
ParseRule
(head, symbols, *, penalty=0)¶ Represents a single production in a context free grammar.
-
class
axaxaxas.
ParseTree
(rule, children=None)¶ Tree structure representing a sucessfully parsed rule
-
class
axaxaxas.
ParseRuleSet
¶ Stores a set of
ParseRule
, with fast retrieval by rule head-
is_anonymous
(head)¶ Returns true if a given head symbol should be omitted from error reporting
-
-
axaxaxas.
parse
(rule_set, head, tokens, *, fail_if_empty=True)¶ Parses a stream of
tokens
according to the grammer inrule_set
by attempting to match the non-terminal specified byhead
.
Errors¶
-
class
axaxaxas.
ParseError
(message, start_index, end_index)¶ Base parse error
-
class
axaxaxas.
AmbiguousParseError
(message, start_index, end_index, values)¶ Indicates that there were multiple possible parses in a context that requires only one
-
class
axaxaxas.
NoParseError
(message, start_index, end_index, encountered, expected_terminals, expected)¶ Indicates there were no possible parses
-
class
axaxaxas.
InfiniteParseError
(message, start_index, end_index)¶ Indicates there were infinite possible parses
Building¶
-
class
axaxaxas.
BuilderContext
¶ Contains information about the location and rule currently being parsed. The exact meaning is specific to each method of
Builder
.-
rule
¶ The relevant
ParseRule
. Can beNone
formerge_vertical
calls at the top level.
-
symbol_index
¶ context.rule.symbols[context.symbol_index]
indicates the relevant symbol of the rule. Notesymbol_index
may belen(context.rule.symbols)
in some circumstances.
-
start_index
¶ The first token in the relevant range of tokens.
-
end_index
¶ After the last token in the relevant range of tokens.
-
-
class
axaxaxas.
Builder
¶ Abstract base class for constructing parse trees and other objects from a
ParseForest
. See Builders for more details.-
begin_multiple
(context, prev_value)¶ Called when a
plus
orstar
symbols is enountered
-
end_multiple
(context, prev_value)¶ Called when there are no more matches for a
plus
orstar
symbol
-
end_rule
(context, prev_value)¶ Called when a new rule is completed
-
extend
(context, prev_value, extension_value)¶ Called when a symbol is matched. Potentially multiple times for a
star
orplus
symbol
-
merge
(context, values)¶ Called when there are multiple possible parses, unless
merge_vertical
andmerge_horizontal
is overriden.
-
merge_vertical
(context, values)¶ Called when multiple possible
ParseRule
objects could match a non terminal
-
skip_optional
(context, prev_value)¶ Called when an
optional
symbol is skipped over
-
start_rule
(context)¶ Called when a new rule is started
-
terminal
(context, token)¶ Called when a terminal is matched
-
-
axaxaxas.
make_list_builder
(builder)¶ Takes a
Builder
which lacks an implementation formerge_horizontal
andmerge_vertical
, and returns a newBuilder
that will accumulate all possible built parse trees into a list
-
axaxaxas.
make_iter_builder
(builder)¶ Takes a
Builder
which lacks an implemenation formerge_horizontal
andmerge_vertical
, and returns a newBuilder
that will accumulate all possible built parse trees into an iterator.
Symbols¶
-
class
axaxaxas.
Symbol
(*, star=False, optional=False, plus=False, name=None, greedy=False, lazy=False)¶ Base class for non-terminals and terminals, this is used when defining ParseRule objects
-
class
axaxaxas.
NonTerminal
(head, prefer_early=False, prefer_late=False, **kwargs)¶ Represents a non-terminal symbol in the grammar, matching tokens according to any ParseRules with the specified
head