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
2
Merge Requests
2
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
郭家华
arpeggio-gm
Commits
6d7fe26e
Commit
6d7fe26e
authored
Jan 23, 2011
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for eliminating single child nonterminals from parse trees.
parent
96096407
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
__init__.py
arpeggio/__init__.py
+23
-6
No files found.
arpeggio/__init__.py
View file @
6d7fe26e
...
...
@@ -125,9 +125,19 @@ class ParsingExpression(object):
parser
.
nm
.
_up
=
False
result
=
self
.
_parse
(
parser
)
if
self
.
root
and
result
:
result
=
NonTerminal
(
self
.
rule
,
self
.
c_pos
,
result
)
if
result
:
if
parser
.
reduce_tree
:
if
isinstance
(
result
,
list
):
if
self
.
root
:
result
=
flatten
(
result
)
if
len
(
result
)
>
1
:
result
=
NonTerminal
(
self
.
rule
,
self
.
c_pos
,
result
)
else
:
result
=
result
[
0
]
else
:
if
self
.
root
:
result
=
NonTerminal
(
self
.
rule
,
self
.
c_pos
,
result
)
# Result caching for use by memoization.
self
.
result_cache
[
self
.
c_pos
]
=
(
result
,
parser
.
position
)
...
...
@@ -519,9 +529,15 @@ class SemanticAction(object):
# Parsers
class
Parser
(
object
):
def
__init__
(
self
,
skipws
=
True
,
ws
=
DEFAULT_WS
):
def
__init__
(
self
,
skipws
=
True
,
ws
=
DEFAULT_WS
,
reduce_tree
=
False
):
'''
@skipws - if True whitespaces will not be part of parse tree.
@ws - rule for matching ws
@reduce_tree - if true nonterminals with single child will be eliminated.
'''
self
.
skipws
=
skipws
self
.
ws
=
ws
self
.
reduce_tree
=
reduce_tree
self
.
comments_model
=
None
self
.
sem_actions
=
{}
...
...
@@ -649,8 +665,9 @@ class Parser(object):
class
ParserPython
(
Parser
):
def
__init__
(
self
,
language_def
,
comment_def
=
None
,
skipws
=
True
,
ws
=
DEFAULT_WS
):
super
(
ParserPython
,
self
)
.
__init__
(
skipws
,
ws
)
def
__init__
(
self
,
language_def
,
comment_def
=
None
,
skipws
=
True
,
ws
=
DEFAULT_WS
,
\
reduce_tree
=
False
):
super
(
ParserPython
,
self
)
.
__init__
(
skipws
,
ws
,
reduce_tree
)
self
.
_init_caches
()
...
...
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