-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_01.py
More file actions
34 lines (24 loc) · 792 Bytes
/
parser_01.py
File metadata and controls
34 lines (24 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from core import State, Event, StateMachine
from pyparsing import (
Word, alphas, alphanums, nums, Literal, Group,
ZeroOrMore, OneOrMore, oneOf, StringEnd,
Optional, Suppress, Keyword, Regex,
quotedString, delimitedList, Combine,
ParseException, dblSlashComment, Regex
)
_tail = Suppress('--')
_arrow = Suppress('->')
state = Word(alphas, alphanums+'_')
code = Regex('[A-Z0-9]{4}')
transition = state + _tail + code + _arrow + state
transitions = OneOrMore(transition)
action = state + _arrow + code
actions = ZeroOrMore(action)
script = transitions + actions + StringEnd()
script.ignore(dblSlashComment)
filename = sys.argv[1]
with open(filename, 'r') as source:
items = script.parseFile(source)