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
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
backend
arpeggio-gm
Commits
2c9baecf
Commit
2c9baecf
authored
Oct 14, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit 'ad28ee'
parents
ffac9653
ad28ee33
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
46 deletions
+38
-46
__init__.py
arpeggio/__init__.py
+38
-46
No files found.
arpeggio/__init__.py
View file @
2c9baecf
...
...
@@ -181,39 +181,8 @@ class ParsingExpression(object):
processed
.
add
(
node
)
node
.
clear_cache
(
processed
)
def
_parse_intro
(
self
,
parser
):
if
parser
.
debug
:
print
(
">> Entering rule {} in {} at position {} => {}"
.
format
(
self
.
name
,
parser
.
in_rule
,
parser
.
position
,
parser
.
context
()))
parser
.
_in_parse_intro
=
True
# Skip whitespaces and parse comments if we are not
# in the lexical rule
if
not
parser
.
_in_lex_rule
:
parser
.
_skip_ws
()
if
parser
.
comments_model
and
not
parser
.
_in_parse_comment
:
parser
.
_in_parse_comment
=
True
try
:
while
True
:
parser
.
comments
.
append
(
parser
.
comments_model
.
parse
(
parser
))
parser
.
_skip_ws
()
except
NoMatch
:
# NoMatch in comment matching is perfectly
# legal and no action should be taken.
pass
finally
:
parser
.
_in_parse_comment
=
False
parser
.
_in_parse_intro
=
False
def
parse
(
self
,
parser
):
if
not
parser
.
_in_parse_intro
:
self
.
_parse_intro
(
parser
)
# Current position could change in recursive calls
# so save it.
c_pos
=
parser
.
position
...
...
@@ -285,7 +254,7 @@ class ParsingExpression(object):
# If the result is not parse tree node it must be a plain list
# so create a new NonTerminal.
if
not
isinstance
(
result
,
ParseTreeNode
):
result
=
NonTerminal
(
self
,
c_pos
,
result
)
result
=
NonTerminal
(
self
,
result
)
# Result caching for use by memoization.
self
.
result_cache
[
c_pos
]
=
(
result
,
parser
.
position
)
...
...
@@ -566,8 +535,37 @@ class Match(ParsingExpression):
else
:
return
"
%
s(
%
s)"
%
(
self
.
__class__
.
__name__
,
self
.
to_match
)
def
_parse_intro
(
self
,
parser
):
if
parser
.
debug
:
print
(
">> Entering rule {} in {} at position {} => {}"
.
format
(
self
.
name
,
parser
.
in_rule
,
parser
.
position
,
parser
.
context
()))
parser
.
_in_parse_intro
=
True
# Skip whitespaces and parse comments if we are not
# in the lexical rule
if
not
parser
.
_in_lex_rule
:
parser
.
_skip_ws
()
if
parser
.
comments_model
and
not
parser
.
_in_parse_comment
:
parser
.
_in_parse_comment
=
True
try
:
while
True
:
parser
.
comments
.
append
(
parser
.
comments_model
.
parse
(
parser
))
parser
.
_skip_ws
()
except
NoMatch
:
# NoMatch in comment matching is perfectly
# legal and no action should be taken.
pass
finally
:
parser
.
_in_parse_comment
=
False
parser
.
_in_parse_intro
=
False
def
parse
(
self
,
parser
):
self
.
_parse_intro
(
parser
)
if
not
parser
.
_in_parse_intro
:
self
.
_parse_intro
(
parser
)
try
:
match
=
self
.
_parse
(
parser
)
...
...
@@ -832,8 +830,13 @@ class NonTerminal(ParseTreeNode, list):
This is used internally.
"""
def
__init__
(
self
,
rule
,
position
,
nodes
,
error
=
False
,
_filtered
=
False
):
def
__init__
(
self
,
rule
,
nodes
,
error
=
False
,
_filtered
=
False
):
# Inherit position from the first child node
position
=
nodes
[
0
]
.
position
super
(
NonTerminal
,
self
)
.
__init__
(
rule
,
position
,
error
)
self
.
extend
(
flatten
([
nodes
]))
self
.
_filtered
=
_filtered
...
...
@@ -893,10 +896,7 @@ class NonTerminal(ParseTreeNode, list):
nodes
.
append
(
n
)
rule
=
n
.
rule
# For expression NonTerminals instances position does not have
# any sense.
result
=
NonTerminal
(
rule
=
rule
,
position
=
None
,
nodes
=
nodes
,
_filtered
=
True
)
result
=
NonTerminal
(
rule
=
rule
,
nodes
=
nodes
,
_filtered
=
True
)
self
.
_expr_cache
[
rule_name
]
=
result
return
result
...
...
@@ -1340,14 +1340,6 @@ class Parser(object):
self
.
input
[
self
.
position
]
in
self
.
ws
:
self
.
position
+=
1
def
_skip_comments
(
self
):
# We do not want to recurse into parsing comments
if
self
.
comments_model
and
not
self
.
in_skip_comments
:
self
.
in_skip_comments
=
True
comments
=
self
.
comments_model
.
parse
(
self
)
self
.
in_skip_comments
=
False
return
comments
def
_nm_raise
(
self
,
*
args
):
"""
Register new NoMatch object if the input is consumed
...
...
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