Commit 25a090d9 authored by Igor Dejanovic's avatar Igor Dejanovic

Improved default semantic action.

Converting terminal to a string as a default action.
parent 6e82b6ca
...@@ -706,8 +706,13 @@ class SemanticAction(object): ...@@ -706,8 +706,13 @@ class SemanticAction(object):
This is the default implementation used if no semantic action is This is the default implementation used if no semantic action is
defined. defined.
""" """
if isinstance(node, Terminal):
# Default for Terminal is to convert to string.
retval = str(node)
else:
retval = node
# Special case. If only one child exist return it. # Special case. If only one child exist return it.
if len(nodes)==1: if len(nodes) == 1:
retval = nodes[0] retval = nodes[0]
else: else:
# If there is only one non-string child return # If there is only one non-string child return
...@@ -726,7 +731,7 @@ class SemanticAction(object): ...@@ -726,7 +731,7 @@ class SemanticAction(object):
else: else:
# Return the only non-string child # Return the only non-string child
retval = last_non_str retval = last_non_str
# If there is only one non-string child return
return retval return retval
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment