geneticengine.grammar.ponyge2
Parse PonyGE2 BNF grammars into GeneticEngine grammar classes.
Attributes
Exceptions
Raised when a PonyGE2 grammar cannot be converted. |
Classes
The generated GeneticEngine structure for a PonyGE2 grammar. |
Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parse PonyGE2 BNF text or a grammar file. |
|
Parse a PonyGE2 grammar file. |
Module Contents
- exception geneticengine.grammar.ponyge2.PonyGE2GrammarError
Bases:
ValueErrorRaised when a PonyGE2 grammar cannot be converted.
Initialize self. See help(type(self)) for accurate signature.
- class geneticengine.grammar.ponyge2.PonyGE2Grammar
The generated GeneticEngine structure for a PonyGE2 grammar.
- nodes: list[type]
- starting_symbol: type
- nonterminals: dict[str, type]
- productions: dict[str, list[type]]
- to_geneticengine()
Return the generated node classes and starting symbol.
- Return type:
tuple[list[type], type]
- geneticengine.grammar.ponyge2._RULE
- geneticengine.grammar.ponyge2._NONTERMINAL
- geneticengine.grammar.ponyge2._remove_comments(source)
- Parameters:
source (str)
- Return type:
str
- geneticengine.grammar.ponyge2._split_alternatives(body)
- Parameters:
body (str)
- Return type:
list[str]
- geneticengine.grammar.ponyge2._parse_rules(source)
- Parameters:
source (str)
- Return type:
list[_Rule]
- geneticengine.grammar.ponyge2._read_source(source)
- Parameters:
source (str | pathlib.Path)
- Return type:
str
- geneticengine.grammar.ponyge2._quoted_terminal(token)
- Parameters:
token (str)
- Return type:
str
- geneticengine.grammar.ponyge2._tokenize_alternative(alternative)
- Parameters:
alternative (str)
- Return type:
list[tuple[str, str]]
- geneticengine.grammar.ponyge2._class_name(symbol, used)
- Parameters:
symbol (str)
used (set[str])
- Return type:
str
- geneticengine.grammar.ponyge2._terminal_type(value)
- Parameters:
value (str)
- Return type:
Any
- geneticengine.grammar.ponyge2._range_type(specification, constants)
- Parameters:
specification (str)
constants (Mapping[str, int])
- Return type:
Any
- geneticengine.grammar.ponyge2.parse_ponyge2_grammar(source, *, ge_constants=None)
Parse PonyGE2 BNF text or a grammar file.
The first rule is the starting symbol. Ordinary terminals become fixed
VarRangestring fields.GE_RANGE:nbecomes an integer field inrange(n); named ranges can be supplied throughge_constants.- Parameters:
source (str | pathlib.Path)
ge_constants (Mapping[str, int] | None)
- Return type:
- geneticengine.grammar.ponyge2.load_ponyge2_grammar(path, *, ge_constants=None)
Parse a PonyGE2 grammar file.
- Parameters:
path (str | pathlib.Path)
ge_constants (Mapping[str, int] | None)
- Return type: