Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Production Test Suite - base
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Production Test Suite - base
Commits
04b120f3
Commit
04b120f3
authored
May 17, 2011
by
Juan David González Cobas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add parser for arbitrary sequence execution
supports normal sequencing, ranges, loops and nesting
parent
fed955e7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
parse.py
parse.py
+61
-0
No files found.
parse.py
0 → 100644
View file @
04b120f3
#! /usr/bin/env python
# coding: utf8
import
sys
from
ply
import
lex
,
yacc
tokens
=
(
'NUMBER'
,
'REPEAT'
,
'LPAREN'
,
'RPAREN'
,
'DASH'
,
)
t_NUMBER
=
r'[0-9]+'
t_REPEAT
=
r'repeat'
t_LPAREN
=
r'\('
t_RPAREN
=
r'\)'
t_DASH
=
r'-'
t_ignore
=
'
\t
'
def
t_error
(
t
):
print
'Illegal character [
%
s]'
%
t
.
value
[
0
]
t
.
lexer
.
skip
(
1
)
lexer
=
lex
.
lex
()
def
p_battery_sequence
(
p
):
'''battery : batch
| batch battery'''
if
len
(
p
)
==
2
:
p
[
0
]
=
[
p
[
1
]
]
else
:
p
[
0
]
=
[
p
[
1
]
]
+
p
[
2
]
def
p_batch_single
(
p
):
'batch : tst'
p
[
0
]
=
p
[
1
]
def
p_batch_loop
(
p
):
'batch : REPEAT NUMBER LPAREN battery RPAREN'
p
[
0
]
=
[
'loop'
,
p
[
2
]
]
+
p
[
4
]
def
p_batch_range
(
p
):
'batch : tst DASH tst'
p
[
0
]
=
[
'range'
,
p
[
1
],
p
[
3
]
]
def
p_tst
(
p
):
'tst : NUMBER'
p
[
0
]
=
p
[
1
]
def
p_error
(
p
):
print
'syntax error!'
parser
=
yacc
.
yacc
()
if
__name__
==
'__main__'
:
result
=
parser
.
parse
(
sys
.
argv
[
1
])
print
result
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment