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
25a090d9
Commit
25a090d9
authored
Jun 30, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved default semantic action.
Converting terminal to a string as a default action.
parent
6e82b6ca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
18 deletions
+23
-18
__init__.py
arpeggio/__init__.py
+23
-18
No files found.
arpeggio/__init__.py
View file @
25a090d9
...
...
@@ -706,27 +706,32 @@ class SemanticAction(object):
This is the default implementation used if no semantic action is
defined.
"""
# Special case. If only one child exist return it.
if
len
(
nodes
)
==
1
:
retval
=
nodes
[
0
]
if
isinstance
(
node
,
Terminal
):
# Default for Terminal is to convert to string.
retval
=
str
(
node
)
else
:
# If there is only one non-string child return
# that by default. This will support e.g. bracket
# removals.
last_non_str
=
None
for
c
in
nodes
:
if
not
isstr
(
c
):
if
last_non_str
is
None
:
last_non_str
=
c
else
:
# If there is multiple non-string objects
# by default convert non-terminal to unicode
retval
=
str
(
node
)
break
retval
=
node
# Special case. If only one child exist return it.
if
len
(
nodes
)
==
1
:
retval
=
nodes
[
0
]
else
:
# Return the only non-string child
retval
=
last_non_str
# If there is only one non-string child return
# that by default. This will support e.g. bracket
# removals.
last_non_str
=
None
for
c
in
nodes
:
if
not
isstr
(
c
):
if
last_non_str
is
None
:
last_non_str
=
c
else
:
# If there is multiple non-string objects
# by default convert non-terminal to unicode
retval
=
str
(
node
)
break
else
:
# Return the only non-string child
retval
=
last_non_str
return
retval
...
...
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