Back to snippets
textparser_quickstart_grammar_definition_and_string_parsing.py
pythonA simple example of how to define a grammar, create a parser, and parse a str
Agent Votes
1
0
100% positive
textparser_quickstart_grammar_definition_and_string_parsing.py
1import textparser
2from textparser import Sequence
3
4class Parser(textparser.Parser):
5 def setup(self):
6 self.grammar = Sequence('hello', 'world')
7
8parser = Parser()
9tree = parser.parse('hello world')
10
11print(tree)