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
ecf34778
Commit
ecf34778
authored
Aug 07, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed PTNode.rule->rule_name. rule is now a reference to ParsingExpression.
parent
1c76b784
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
19 deletions
+19
-19
__init__.py
arpeggio/__init__.py
+0
-0
peg.py
arpeggio/peg.py
+7
-7
test_peg_parser.py
tests/unit/test_peg_parser.py
+1
-1
test_ptnode_navigation_expressions.py
tests/unit/test_ptnode_navigation_expressions.py
+3
-3
test_python_parser.py
tests/unit/test_python_parser.py
+1
-1
test_reduce_tree.py
tests/unit/test_reduce_tree.py
+7
-7
No files found.
arpeggio/__init__.py
View file @
ecf34778
This diff is collapsed.
Click to expand it.
arpeggio/peg.py
View file @
ecf34778
...
...
@@ -81,14 +81,14 @@ class PEGSemanticAction(SemanticAction):
# If resolved rule hasn't got the same name it
# should be cloned and preserved in the peg_rules cache
if
resolved_rule
.
rule
!=
n
.
rule_name
:
if
resolved_rule
.
rule
_name
!=
n
.
rule_name
:
resolved_rule
=
copy
.
copy
(
resolved_rule
)
resolved_rule
.
rule
=
n
.
rule_name
parser
.
peg_rules
[
resolved_rule
.
rule
]
=
resolved_rule
resolved_rule
.
rule
_name
=
n
.
rule_name
parser
.
peg_rules
[
resolved_rule
.
rule
_name
]
=
resolved_rule
if
parser
.
debug
:
print
(
"Resolving: cloned to {} = > {}"
\
.
format
(
resolved_rule
.
rule
,
resolved_rule
.
name
))
.
format
(
resolved_rule
.
rule
_name
,
resolved_rule
.
name
))
node
.
nodes
[
i
]
=
resolved_rule
...
...
@@ -111,7 +111,7 @@ class SemRule(PEGSemanticAction):
retval
=
Sequence
(
nodes
=
children
[
1
:])
else
:
retval
=
children
[
1
]
retval
.
rule
=
rule_name
retval
.
rule
_name
=
rule_name
retval
.
root
=
True
if
not
hasattr
(
parser
,
"peg_rules"
):
...
...
@@ -230,14 +230,14 @@ class ParserPEG(Parser):
# visualization
if
self
.
debug
:
from
arpeggio.export
import
PMDOTExporter
root_rule
=
self
.
parser_model
.
rule
root_rule
=
self
.
parser_model
.
rule
_name
PMDOTExporter
()
.
exportFile
(
self
.
parser_model
,
"{}_peg_parser_model.dot"
.
format
(
root_rule
))
# Comments should be optional and there can be more of them
if
self
.
comments_model
:
# and not isinstance(self.comments_model, ZeroOrMore):
self
.
comments_model
.
root
=
True
self
.
comments_model
.
rule
=
comment_rule_name
self
.
comments_model
.
rule
_name
=
comment_rule_name
def
_parse
(
self
):
return
self
.
parser_model
.
parse
(
self
)
...
...
tests/unit/test_peg_parser.py
View file @
ecf34778
...
...
@@ -24,7 +24,7 @@ def test_construct_parser():
parser
=
ParserPEG
(
grammar
,
'calc'
)
assert
parser
.
parser_model
.
rule
==
'calc'
assert
parser
.
parser_model
.
rule
_name
==
'calc'
assert
isinstance
(
parser
.
parser_model
,
Sequence
)
assert
parser
.
parser_model
.
nodes
[
0
]
.
name
==
'OneOrMore'
...
...
tests/unit/test_ptnode_navigation_expressions.py
View file @
ecf34778
...
...
@@ -34,9 +34,9 @@ def test_lookup_single():
assert
isinstance
(
result
,
ParseTreeNode
)
assert
isinstance
(
result
.
bar
,
NonTerminal
)
# dot access
assert
result
.
bar
.
rule
==
'bar'
assert
result
.
bar
.
rule
_name
==
'bar'
# Index access
assert
result
[
1
]
.
rule
==
'bar'
assert
result
[
1
]
.
rule
_name
==
'bar'
# There are six children from result
assert
len
(
result
)
==
6
...
...
@@ -52,7 +52,7 @@ def test_lookup_single():
# For example this returns all bum from all bar in result
assert
len
(
result
.
bar
.
bum
)
==
2
# Verify that proper bum are returned
assert
result
.
bar
.
bum
[
0
]
.
rule
==
'bum'
assert
result
.
bar
.
bum
[
0
]
.
rule
_name
==
'bum'
assert
result
.
bar
.
bum
[
1
]
.
position
==
18
# Access to terminal
...
...
tests/unit/test_python_parser.py
View file @
ecf34778
...
...
@@ -29,7 +29,7 @@ def test_pp_construction():
'''
parser
=
ParserPython
(
calc
)
assert
parser
.
parser_model
.
rule
==
'calc'
assert
parser
.
parser_model
.
rule
_name
==
'calc'
assert
isinstance
(
parser
.
parser_model
,
Sequence
)
assert
parser
.
parser_model
.
nodes
[
0
]
.
desc
==
'OneOrMore'
...
...
tests/unit/test_reduce_tree.py
View file @
ecf34778
...
...
@@ -31,21 +31,21 @@ def test_reduce_tree():
# PTDOTExporter().exportFile(result, 'test_reduce_tree_pt.dot')
assert
result
[
0
]
.
rule
==
'first'
assert
result
[
0
]
.
rule
_name
==
'first'
assert
isinstance
(
result
[
0
],
NonTerminal
)
assert
result
[
3
]
.
rule
==
'first'
assert
result
[
0
][
0
]
.
rule
==
'fourth'
assert
result
[
3
]
.
rule
_name
==
'first'
assert
result
[
0
][
0
]
.
rule
_name
==
'fourth'
# Check reduction for direct OrderedChoice
assert
result
[
2
][
0
]
.
rule
==
'third'
assert
result
[
2
][
0
]
.
rule
_name
==
'third'
parser
=
ParserPython
(
grammar
,
reduce_tree
=
True
)
result
=
parser
.
parse
(
input
)
# PTDOTExporter().exportFile(result, 'test_reduce_tree_pt.dot')
assert
result
[
0
]
.
rule
==
'fourth'
assert
result
[
0
]
.
rule
_name
==
'fourth'
assert
isinstance
(
result
[
0
],
Terminal
)
assert
result
[
3
]
.
rule
==
'fourth'
assert
result
[
3
]
.
rule
_name
==
'fourth'
# Check reduction for direct OrderedChoice
assert
result
[
2
][
0
]
.
rule
==
'third_str'
assert
result
[
2
][
0
]
.
rule
_name
==
'third_str'
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