polytracker.grammars¶
grammars classes¶
Completion¶
- class polytracker.grammars.Completion(prediction: Prediction, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int)¶
Bases:
EarleyState
- __init__(prediction: Prediction, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int)¶
- add_predecessor(left_sibling: EarleyState)¶
- completed_by: Set[EarleyState]¶
- predecessors: FrozenSet[EarleyState]¶
- prediction: Prediction¶
- property production: Production¶
- to_tree() MutableParseTree[Union[Production, Rule, Terminal]] ¶
CorruptedGrammarError¶
DisconnectedGrammarError¶
EarleyParser¶
EarleyQueue¶
- class polytracker.grammars.EarleyQueue(parser: EarleyParser)¶
Bases:
object
- __init__(parser: EarleyParser)¶
- add(state: S, left_sibling: Optional[EarleyState] = None) S ¶
- complete_state(state: EarleyState, completed: EarleyState)¶
- remove(*states: Union[EarleyState, Iterable]) int ¶
EarleyState¶
- class polytracker.grammars.EarleyState(prediction: Prediction, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int)¶
Bases:
object
- __init__(prediction: Prediction, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int)¶
- add_predecessor(left_sibling: EarleyState)¶
- predecessors: FrozenSet[EarleyState]¶
- prediction: Prediction¶
- property production: Production¶
- abstract to_tree() MutableParseTree[Union[Production, Rule, Terminal]] ¶
EmptyProduction¶
- class polytracker.grammars.EmptyProduction(production: Production, prediction: Prediction, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int)¶
Bases:
EarleyState
- __init__(production: Production, prediction: Prediction, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int)¶
- add_predecessor(left_sibling: EarleyState)¶
- predecessors: FrozenSet[EarleyState]¶
- prediction: Prediction¶
- property production: Production¶
- to_tree() MutableParseTree[Union[Production, Rule, Terminal]] ¶
Grammar¶
- class polytracker.grammars.Grammar¶
Bases:
object
- __init__()¶
- dependency_graph() DiGraph[Production] ¶
- find_partial_trees(sentence: bytes, start: Optional[Production] = None) Iterator[ParseTree[Union[Production, Rule, Terminal]]] ¶
Enumerates all partial parse trees that could result in the given starting sentence fragment.
- remove(production: Union[str, Production]) bool ¶
GrammarError¶
Match¶
- class polytracker.grammars.Match(parser: EarleyParser)¶
Bases:
object
- __init__(parser: EarleyParser)¶
MissingProductionError¶
PartialMatch¶
- class polytracker.grammars.PartialMatch(tree: ParseTree[Union[Production, Rule, Terminal]], remaining_symbols: Tuple[Union[str, Terminal], ...], remaining_bytes: bytes)¶
Bases:
object
Prediction¶
- class polytracker.grammars.Prediction(production: Production, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int, rule: Rule)¶
Bases:
EarleyState
- __init__(production: Production, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int, rule: Rule)¶
- add_predecessor(left_sibling: EarleyState)¶
- predecessors: FrozenSet[EarleyState]¶
- prediction: Prediction¶
- property production: Production¶
- to_tree() MutableParseTree[Union[Production, Rule, Terminal]] ¶
Production¶
- class polytracker.grammars.Production(grammar: Grammar, name: str, *rules: Rule)¶
Bases:
object
- _propagate_terminals()¶
Calculates if this production can produce a terminal. If a rule calls another terminal whose _can_produce_terminal member is None, assume that it is False
- partial_match(sentence: bytes) Iterator[PartialMatch] ¶
Enumerates all partial parse trees and remaining symbols that match the given sentence
- remove_recursive_rules() Set[Rule] ¶
Removes and returns all rules that solely recursively call this same production
- property used_by: Iterable[Production]¶
Rule¶
ScannedTerminal¶
- class polytracker.grammars.ScannedTerminal(prediction: Prediction, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int, terminal: Terminal)¶
Bases:
EarleyState
- __init__(prediction: Prediction, parsed: Tuple[Union[str, Terminal], ...], expected: Tuple[Union[str, Terminal], ...], index: int, terminal: Terminal)¶
- add_predecessor(left_sibling: EarleyState)¶
- predecessors: FrozenSet[EarleyState]¶
- prediction: Prediction¶
- property production: Production¶
- to_tree() MutableParseTree[Union[Production, Rule, Terminal]] ¶
grammars functions¶
extract¶
- polytracker.grammars.extract(traces: Iterable[ProgramTrace], simplify: bool = False) Grammar ¶
extract a grammar from a set of traces
parse_tree_to_grammar¶
- polytracker.grammars.parse_tree_to_grammar(tree: NonGeneralizedParseTree) Grammar ¶
production_name¶
- polytracker.grammars.production_name(event: TraceEvent) str ¶
to_dot¶
- polytracker.grammars.to_dot(graph: DiGraph, comment: Optional[str] = None) Digraph ¶
- Parameters:
comment – comment for the graph
- Returns:
Graphviz DiGraph
This function creates a dot object which can be saved to disk and converted to PDF its a visualization of the chain fragment, useful for visualizing a reorg.
trace_to_grammar¶
- polytracker.grammars.trace_to_grammar(trace: ProgramTrace) Grammar ¶