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
34f0ba2b
Commit
34f0ba2b
authored
Feb 10, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing bug in determining position where NonTerminal was recognized.
parent
58e82c62
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
+15
-8
__init__.py
arpeggio/__init__.py
+15
-8
No files found.
arpeggio/__init__.py
View file @
34f0ba2b
...
@@ -152,19 +152,26 @@ class ParsingExpression(object):
...
@@ -152,19 +152,26 @@ class ParsingExpression(object):
if
parser
.
debug
:
if
parser
.
debug
:
print
"Parsing
%
s"
%
self
.
name
print
"Parsing
%
s"
%
self
.
name
parser
.
_skip_ws
()
parser
.
_skip_ws
()
# Set the begining position in input stream of
# this parsing expression
self
.
c_pos
=
parser
.
position
self
.
c_pos
=
parser
.
position
def
parse
(
self
,
parser
):
def
parse
(
self
,
parser
):
self
.
_parse_intro
(
parser
)
self
.
_parse_intro
(
parser
)
#Memoization.
# Current position could change in recursive calls
#If this position is already parsed by this parser expression than use
# so save it.
#the result
c_pos
=
self
.
c_pos
if
self
.
c_pos
in
self
.
result_cache
:
# Memoization.
# If this position is already parsed by this parser expression than use
# the result
if
c_pos
in
self
.
result_cache
:
if
parser
.
debug
:
if
parser
.
debug
:
print
"Result for [
%
s,
%
s] founded in result_cache."
%
\
print
"Result for [
%
s,
%
s] founded in result_cache."
%
\
(
self
,
self
.
c_pos
)
(
self
,
self
.
c_pos
)
result
,
new_pos
=
self
.
result_cache
[
self
.
c_pos
]
result
,
new_pos
=
self
.
result_cache
[
c_pos
]
parser
.
position
=
new_pos
parser
.
position
=
new_pos
return
result
return
result
...
@@ -180,15 +187,15 @@ class ParsingExpression(object):
...
@@ -180,15 +187,15 @@ class ParsingExpression(object):
if
self
.
root
:
if
self
.
root
:
result
=
flatten
(
result
)
result
=
flatten
(
result
)
if
len
(
result
)
>
1
:
if
len
(
result
)
>
1
:
result
=
NonTerminal
(
self
.
rule
,
self
.
c_pos
,
result
)
result
=
NonTerminal
(
self
.
rule
,
c_pos
,
result
)
else
:
else
:
result
=
result
[
0
]
result
=
result
[
0
]
else
:
else
:
if
self
.
root
:
if
self
.
root
:
result
=
NonTerminal
(
self
.
rule
,
self
.
c_pos
,
result
)
result
=
NonTerminal
(
self
.
rule
,
c_pos
,
result
)
# Result caching for use by memoization.
# Result caching for use by memoization.
self
.
result_cache
[
self
.
c_pos
]
=
(
result
,
parser
.
position
)
self
.
result_cache
[
c_pos
]
=
(
result
,
parser
.
position
)
return
result
return
result
...
...
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