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
badf467a
Commit
badf467a
authored
Sep 06, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved debug messages.
parent
e8bec15a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
5 deletions
+28
-5
__init__.py
arpeggio/__init__.py
+28
-5
No files found.
arpeggio/__init__.py
View file @
badf467a
...
@@ -172,7 +172,8 @@ class ParsingExpression(object):
...
@@ -172,7 +172,8 @@ class ParsingExpression(object):
def
_parse_intro
(
self
,
parser
):
def
_parse_intro
(
self
,
parser
):
if
parser
.
debug
:
if
parser
.
debug
:
print
(
">> Entering rule {}"
.
format
(
self
.
name
))
print
(
">> Entering rule {} in {} at position {} => {}"
.
format
(
self
.
name
,
parser
.
in_rule
,
parser
.
position
,
parser
.
context
()))
parser
.
_in_parse_intro
=
True
parser
.
_in_parse_intro
=
True
...
@@ -215,7 +216,7 @@ class ParsingExpression(object):
...
@@ -215,7 +216,7 @@ class ParsingExpression(object):
if
parser
.
debug
:
if
parser
.
debug
:
print
(
"** Cache hit for [{}, {}] = '{}' : new_pos={}"
print
(
"** Cache hit for [{}, {}] = '{}' : new_pos={}"
.
format
(
self
.
name
,
c_pos
,
str
(
result
),
str
(
new_pos
)))
.
format
(
self
.
name
,
c_pos
,
str
(
result
),
str
(
new_pos
)))
print
(
"<< Leaving rule {}"
.
format
(
self
.
name
))
#
print("<< Leaving rule {}".format(self.name))
# If NoMatch is recorded at this position raise.
# If NoMatch is recorded at this position raise.
if
isinstance
(
result
,
NoMatch
):
if
isinstance
(
result
,
NoMatch
):
...
@@ -233,6 +234,15 @@ class ParsingExpression(object):
...
@@ -233,6 +234,15 @@ class ParsingExpression(object):
# the new last.
# the new last.
_last_pexpression
=
parser
.
_last_pexpression
_last_pexpression
=
parser
.
_last_pexpression
parser
.
_last_pexpression
=
self
parser
.
_last_pexpression
=
self
if
self
.
rule_name
:
# If we are entering root rule
# remember previous root rule name and set
# this one on the parser to be available for
# debugging messages
previous_root_rule_name
=
parser
.
in_rule
parser
.
in_rule
=
self
.
rule_name
try
:
try
:
result
=
self
.
_parse
(
parser
)
result
=
self
.
_parse
(
parser
)
...
@@ -249,6 +259,10 @@ class ParsingExpression(object):
...
@@ -249,6 +259,10 @@ class ParsingExpression(object):
if
parser
.
debug
:
if
parser
.
debug
:
print
(
"<< Leaving rule {}"
.
format
(
self
.
name
))
print
(
"<< Leaving rule {}"
.
format
(
self
.
name
))
# If leaving root rule restore previous root rule name.
if
self
.
rule_name
:
parser
.
in_rule
=
previous_root_rule_name
# For root rules flatten non-terminal/list
# For root rules flatten non-terminal/list
if
self
.
root
and
result
and
not
isinstance
(
result
,
Terminal
):
if
self
.
root
and
result
and
not
isinstance
(
result
,
Terminal
):
if
not
isinstance
(
result
,
NonTerminal
):
if
not
isinstance
(
result
,
NonTerminal
):
...
@@ -833,7 +847,9 @@ class SemanticAction(object):
...
@@ -833,7 +847,9 @@ class SemanticAction(object):
last_non_str
=
c
last_non_str
=
c
else
:
else
:
# If there is multiple non-string objects
# If there is multiple non-string objects
# by default convert non-terminal to unicode
# by default convert non-terminal to string
if
parser
.
debug
:
print
(
"*** Warning: Multiple non-string objects found in applying default semantic action. Converting non-terminal to string."
)
retval
=
str
(
node
)
retval
=
str
(
node
)
break
break
else
:
else
:
...
@@ -915,6 +931,11 @@ class Parser(object):
...
@@ -915,6 +931,11 @@ class Parser(object):
self
.
sem_actions
=
{}
self
.
sem_actions
=
{}
self
.
parse_tree
=
None
self
.
parse_tree
=
None
# Keep track of root rule we are currently in.
# Used for debugging purposes
self
.
in_rule
=
''
self
.
_in_parse_comment
=
False
self
.
_in_parse_comment
=
False
self
.
_in_parse_intro
=
False
self
.
_in_parse_intro
=
False
...
@@ -1089,15 +1110,17 @@ class Parser(object):
...
@@ -1089,15 +1110,17 @@ class Parser(object):
if
not
position
:
if
not
position
:
position
=
self
.
position
position
=
self
.
position
if
length
:
if
length
:
ret
urn
"{}*{}*{}"
.
format
(
ret
val
=
"{}*{}*{}"
.
format
(
str
(
self
.
input
[
max
(
position
-
10
,
0
):
position
]),
str
(
self
.
input
[
max
(
position
-
10
,
0
):
position
]),
str
(
self
.
input
[
position
:
position
+
length
]),
str
(
self
.
input
[
position
:
position
+
length
]),
str
(
self
.
input
[
position
+
length
:
position
+
10
]))
str
(
self
.
input
[
position
+
length
:
position
+
10
]))
else
:
else
:
ret
urn
"{}*{}"
.
format
(
ret
val
=
"{}*{}"
.
format
(
str
(
self
.
input
[
max
(
position
-
10
,
0
):
position
]),
str
(
self
.
input
[
max
(
position
-
10
,
0
):
position
]),
str
(
self
.
input
[
position
:
position
+
10
]))
str
(
self
.
input
[
position
:
position
+
10
]))
return
retval
.
replace
(
'
\n
'
,
' '
)
.
replace
(
'
\r
'
,
''
)
def
_skip_ws
(
self
):
def
_skip_ws
(
self
):
"""
"""
Skiping whitespace characters.
Skiping whitespace characters.
...
...
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