Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
arpeggio-gm
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
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
backend
arpeggio-gm
Commits
a3f51c06
Commit
a3f51c06
authored
Jul 07, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating tests
parent
8f2ef644
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
22 additions
and
154 deletions
+22
-154
input.txt
tests/input.txt
+0
-103
test_speed.py
tests/test_speed.py
+0
-30
test_decorator_combine.py
tests/unit/test_decorator_combine.py
+1
-1
test_exporter.py
tests/unit/test_exporter.py
+2
-2
test_parsing_expressions.py
tests/unit/test_parsing_expressions.py
+10
-10
test_peg_parser.py
tests/unit/test_peg_parser.py
+3
-3
test_python_parser.py
tests/unit/test_python_parser.py
+6
-5
No files found.
tests/input.txt
deleted
100644 → 0
View file @
8f2ef644
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
tests/test_speed.py
deleted
100644 → 0
View file @
8f2ef644
# -*- coding: utf-8 -*-
#######################################################################
# Name: test_speed
# Purpose: Performance test of arpeggio parser
# Author: Igor R. Dejanović <igor DOT dejanovic AT gmail DOT com>
# Copyright: (c) 2014 Igor R. Dejanović <igor DOT dejanovic AT gmail DOT com>
# License: MIT License
#######################################################################
import
timeit
,
sys
if
__name__
==
"__main__"
:
setup
=
'''
from arpeggio import OneOrMore, ZeroOrMore, EndOfFile, ParserPython, Optional
from arpeggio import RegExMatch as _
def number(): return _(r'
\
d*
\
.
\
d*|
\
d+')
def factor(): return [(Optional(["+","-"]), number), ("(", expression, ")")]
def term(): return factor, ZeroOrMore(["*","/"], factor)
def expression(): return term, ZeroOrMore(["+", "-"], term)
def calcfile(): return OneOrMore(expression), EndOfFile
parser = ParserPython(calcfile, reduce_tree=True)
with open("input.txt", "r") as f:
input = f.read()
'''
print
timeit
.
timeit
(
"parser.parse(input)"
,
setup
=
setup
,
number
=
20
)
# 7.06 s
tests/unit/test_decorator_combine.py
View file @
a3f51c06
...
...
@@ -22,7 +22,7 @@ class TestDecoratorCombine(TestCase):
# This will result in Terminal node
def
my_rule
():
return
Combine
(
ZeroOrMore
(
"a"
),
OneOrMore
(
"b"
))
parser
=
ParserPython
(
root
,
debug
=
True
)
parser
=
ParserPython
(
root
)
input1
=
"abbb."
...
...
tests/unit/test_exporter.py
View file @
a3f51c06
...
...
@@ -12,7 +12,7 @@ from unittest import TestCase
from
arpeggio.export
import
PMDOTExporter
,
PTDOTExporter
# Grammar
from
arpeggio
import
Optional
,
ZeroOrMore
,
OneOrMore
,
E
ndOfFile
,
ParserPython
,
Sequence
,
NonTerminal
from
arpeggio
import
Optional
,
ZeroOrMore
,
OneOrMore
,
E
OF
,
ParserPython
,
Sequence
,
NonTerminal
from
arpeggio
import
RegExMatch
as
_
...
...
@@ -21,7 +21,7 @@ def factor(): return Optional(["+","-"]), [number,
(
"("
,
expression
,
")"
)]
def
term
():
return
factor
,
ZeroOrMore
([
"*"
,
"/"
],
factor
)
def
expression
():
return
term
,
ZeroOrMore
([
"+"
,
"-"
],
term
)
def
calc
():
return
OneOrMore
(
expression
),
E
ndOfFile
def
calc
():
return
OneOrMore
(
expression
),
E
OF
class
TestPythonParser
(
TestCase
):
...
...
tests/unit/test_parsing_expressions.py
View file @
a3f51c06
...
...
@@ -21,7 +21,7 @@ class TestParsingExpression(TestCase):
parsed
=
parser
.
parse
(
"a b c"
)
self
.
assertEqual
(
str
(
parsed
),
"a
b
c"
)
self
.
assertEqual
(
str
(
parsed
),
"a
| b |
c"
)
self
.
assertEqual
(
repr
(
parsed
),
"[ 'a' [0], 'b' [2], 'c' [4] ]"
)
def
test_ordered_choice
(
self
):
...
...
@@ -32,11 +32,11 @@ class TestParsingExpression(TestCase):
parsed
=
parser
.
parse
(
"b"
)
self
.
assertEqual
(
str
(
parsed
),
"b"
)
self
.
assertEqual
(
str
(
parsed
),
"b
|
"
)
self
.
assertEqual
(
repr
(
parsed
),
"[ 'b' [0], EOF [1] ]"
)
parsed
=
parser
.
parse
(
"c"
)
self
.
assertEqual
(
str
(
parsed
),
"c"
)
self
.
assertEqual
(
str
(
parsed
),
"c
|
"
)
self
.
assertEqual
(
repr
(
parsed
),
"[ 'c' [0], EOF [1] ]"
)
self
.
assertRaises
(
NoMatch
,
lambda
:
parser
.
parse
(
"ab"
))
...
...
@@ -50,13 +50,13 @@ class TestParsingExpression(TestCase):
parsed
=
parser
.
parse
(
"aaaaaaa"
)
self
.
assertEqual
(
str
(
parsed
),
"a
aaaaaa
"
)
self
.
assertEqual
(
str
(
parsed
),
"a
| a | a | a | a | a | a |
"
)
self
.
assertEqual
(
repr
(
parsed
),
"[ 'a' [0], 'a' [1], 'a' [2], 'a' [3], 'a' [4], 'a' [5], 'a' [6], EOF [7] ]"
)
parsed
=
parser
.
parse
(
""
)
self
.
assertEqual
(
str
(
parsed
),
""
)
self
.
assertEqual
(
repr
(
parsed
),
"
[ EOF [0]
]"
)
self
.
assertEqual
(
repr
(
parsed
),
"
EOF [0
]"
)
self
.
assertRaises
(
NoMatch
,
lambda
:
parser
.
parse
(
"bbb"
))
...
...
@@ -68,7 +68,7 @@ class TestParsingExpression(TestCase):
parsed
=
parser
.
parse
(
"aaaaaaa"
)
self
.
assertEqual
(
str
(
parsed
),
"a
aaaaa
a"
)
self
.
assertEqual
(
str
(
parsed
),
"a
| a | a | a | a | a |
a"
)
self
.
assertEqual
(
repr
(
parsed
),
"[ 'a' [0], 'a' [1], 'a' [2], 'a' [3], 'a' [4], 'a' [5], 'a' [6] ]"
)
self
.
assertRaises
(
NoMatch
,
lambda
:
parser
.
parse
(
""
))
...
...
@@ -82,12 +82,12 @@ class TestParsingExpression(TestCase):
parsed
=
parser
.
parse
(
"ab"
)
self
.
assertEqual
(
str
(
parsed
),
"a
b
"
)
self
.
assertEqual
(
str
(
parsed
),
"a
| b |
"
)
self
.
assertEqual
(
repr
(
parsed
),
"[ 'a' [0], 'b' [1], EOF [2] ]"
)
parsed
=
parser
.
parse
(
"b"
)
self
.
assertEqual
(
str
(
parsed
),
"b"
)
self
.
assertEqual
(
str
(
parsed
),
"b
|
"
)
self
.
assertEqual
(
repr
(
parsed
),
"[ 'b' [0], EOF [1] ]"
)
self
.
assertRaises
(
NoMatch
,
lambda
:
parser
.
parse
(
"aab"
))
...
...
@@ -103,7 +103,7 @@ class TestParsingExpression(TestCase):
parser
=
ParserPython
(
grammar
)
parsed
=
parser
.
parse
(
"ab"
)
self
.
assertEqual
(
str
(
parsed
),
"a
b
"
)
self
.
assertEqual
(
str
(
parsed
),
"a
| b |
"
)
self
.
assertEqual
(
repr
(
parsed
),
"[ 'a' [0], 'b' [1], EOF [2] ]"
)
# 'And' will try to match 'b' and fail so 'c' will never get matched
...
...
@@ -119,7 +119,7 @@ class TestParsingExpression(TestCase):
parsed
=
parser
.
parse
(
"ac"
)
self
.
assertEqual
(
str
(
parsed
),
"a
c
"
)
self
.
assertEqual
(
str
(
parsed
),
"a
| c |
"
)
self
.
assertEqual
(
repr
(
parsed
),
"[ 'a' [0], 'c' [1], EOF [2] ]"
)
# Not will will fail on 'b'
...
...
tests/unit/test_peg_parser.py
View file @
a3f51c06
...
...
@@ -37,8 +37,8 @@ class TestPEGParser(TestCase):
result
=
parser
.
parse
(
input
)
self
.
assertTrue
(
isinstance
(
result
,
NonTerminal
))
self
.
assertEqual
(
str
(
result
),
"4
+5*7/3.45*-45*(2.56+32)/-56*(2-1.34)
"
)
self
.
assertEqual
(
repr
(
result
),
"[ [ [ [ number '4' [0] ] ], '+' [1], [ [ number '5' [2] ], '*' [3], [ number '7' [4] ], '/' [5], [ number '3.45' [6] ], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ [ [ number '2.56' [16] ] ], '+' [20], [ [ number '32' [21] ] ] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ [ [ number '2' [30] ] ], '-' [31], [ [ number '1.34' [32] ]
] ], ')' [36] ] ] ], EOF [37] ]"
)
self
.
assertEqual
(
str
(
result
),
"4
| + | 5 | * | 7 | / | 3.45 | * | - | 45 | * | ( | 2.56 | + | 32 | ) | / | - | 56 | * | ( | 2 | - | 1.34 | ) |
"
)
self
.
assertEqual
(
repr
(
result
),
"[ [ number '4' [0], '+' [1], [ number '5' [2], '*' [3], number '7' [4], '/' [5], number '3.45' [6], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ number '2.56' [16], '+' [20], number '32' [21] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ number '2' [30], '-' [31], number '1.34' [32
] ], ')' [36] ] ] ], EOF [37] ]"
)
def
test_reduce_tree
(
self
):
...
...
@@ -48,5 +48,5 @@ class TestPEGParser(TestCase):
self
.
assertTrue
(
isinstance
(
result
,
NonTerminal
))
self
.
assertEqual
(
str
(
result
),
"4
+5*7/3.45*-45*(2.56+32)/-56*(2-1.34)
"
)
self
.
assertEqual
(
str
(
result
),
"4
| + | 5 | * | 7 | / | 3.45 | * | - | 45 | * | ( | 2.56 | + | 32 | ) | / | - | 56 | * | ( | 2 | - | 1.34 | ) |
"
)
self
.
assertEqual
(
repr
(
result
),
"[ [ number '4' [0], '+' [1], [ number '5' [2], '*' [3], number '7' [4], '/' [5], number '3.45' [6], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ number '2.56' [16], '+' [20], number '32' [21] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ number '2' [30], '-' [31], number '1.34' [32] ], ')' [36] ] ] ], EOF [37] ]"
)
tests/unit/test_python_parser.py
View file @
a3f51c06
...
...
@@ -10,7 +10,8 @@
from
unittest
import
TestCase
# Grammar
from
arpeggio
import
Optional
,
ZeroOrMore
,
OneOrMore
,
EndOfFile
,
ParserPython
,
Sequence
,
NonTerminal
from
arpeggio
import
Optional
,
ZeroOrMore
,
OneOrMore
,
EOF
,
ParserPython
,
\
Sequence
,
NonTerminal
from
arpeggio
import
RegExMatch
as
_
...
...
@@ -19,7 +20,7 @@ def factor(): return Optional(["+","-"]), [number,
(
"("
,
expression
,
")"
)]
def
term
():
return
factor
,
ZeroOrMore
([
"*"
,
"/"
],
factor
)
def
expression
():
return
term
,
ZeroOrMore
([
"+"
,
"-"
],
term
)
def
calc
():
return
OneOrMore
(
expression
),
E
ndOfFile
def
calc
():
return
OneOrMore
(
expression
),
E
OF
class
TestPythonParser
(
TestCase
):
...
...
@@ -41,8 +42,8 @@ class TestPythonParser(TestCase):
result
=
parser
.
parse
(
input
)
self
.
assertTrue
(
isinstance
(
result
,
NonTerminal
))
self
.
assertEqual
(
str
(
result
),
"4
+5*7/3.45*-45*(2.56+32)/-56*(2-1.34)
"
)
self
.
assertEqual
(
repr
(
result
),
"[ [
[ [ number '4' [0] ] ], '+' [1], [ [ number '5' [2] ], '*' [3], [ number '7' [4] ], '/' [5], [ number '3.45' [6] ], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ [ [ number '2.56' [16] ] ], '+' [20], [ [ number '32' [21] ] ] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ [ [ number '2' [30] ] ], '-' [31], [ [ number '1.34' [32] ]
] ], ')' [36] ] ] ], EOF [37] ]"
)
self
.
assertEqual
(
str
(
result
),
"4
| + | 5 | * | 7 | / | 3.45 | * | - | 45 | * | ( | 2.56 | + | 32 | ) | / | - | 56 | * | ( | 2 | - | 1.34 | ) |
"
)
self
.
assertEqual
(
repr
(
result
),
"[ [
number '4' [0], '+' [1], [ number '5' [2], '*' [3], number '7' [4], '/' [5], number '3.45' [6], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ number '2.56' [16], '+' [20], number '32' [21] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ number '2' [30], '-' [31], number '1.34' [32
] ], ')' [36] ] ] ], EOF [37] ]"
)
def
test_reduce_tree
(
self
):
...
...
@@ -52,6 +53,6 @@ class TestPythonParser(TestCase):
self
.
assertTrue
(
isinstance
(
result
,
NonTerminal
))
self
.
assertEqual
(
str
(
result
),
"4
+5*7/3.45*-45*(2.56+32)/-56*(2-1.34)
"
)
self
.
assertEqual
(
str
(
result
),
"4
| + | 5 | * | 7 | / | 3.45 | * | - | 45 | * | ( | 2.56 | + | 32 | ) | / | - | 56 | * | ( | 2 | - | 1.34 | ) |
"
)
self
.
assertEqual
(
repr
(
result
),
"[ [ number '4' [0], '+' [1], [ number '5' [2], '*' [3], number '7' [4], '/' [5], number '3.45' [6], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ number '2.56' [16], '+' [20], number '32' [21] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ number '2' [30], '-' [31], number '1.34' [32] ], ')' [36] ] ] ], EOF [37] ]"
)
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