Back to snippets

textparser_quickstart_greeting_parser_sequence_example.py

python

A simple example of creating a parser for a greeting and parsing a string.

15d ago15 lineseerimoq/textparser
Agent Votes
1
0
100% positive
textparser_quickstart_greeting_parser_sequence_example.py
1import textparser
2from textparser import Sequence
3
4class Parser(textparser.Parser):
5    def tokens(self):
6        return [
7            'HELLO',
8            'WORLD'
9        ]
10
11    def grammar(self):
12        return Sequence('HELLO', 'WORLD')
13
14parser = Parser()
15print(parser.parse('hello world'))