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
43dd61e4
Commit
43dd61e4
authored
Jul 04, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reference resolving unification
parent
dd71eb5e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
16 deletions
+11
-16
__init__.py
arpeggio/__init__.py
+8
-4
peg.py
arpeggio/peg.py
+3
-12
No files found.
arpeggio/__init__.py
View file @
43dd61e4
...
...
@@ -964,6 +964,14 @@ class Parser(object):
raise
self
.
nm
class
CrossRef
(
object
):
'''
Used for rule reference resolving.
'''
def
__init__
(
self
,
rule_name
):
self
.
rule_name
=
rule_name
class
ParserPython
(
Parser
):
def
__init__
(
self
,
language_def
,
comment_def
=
None
,
*
args
,
**
kwargs
):
super
(
ParserPython
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
...
@@ -994,10 +1002,6 @@ class ParserPython(Parser):
__for_resolving
=
[]
# Expressions that needs crossref resolvnih
self
.
__cross_refs
=
0
class
CrossRef
(
object
):
def
__init__
(
self
,
rule_name
):
self
.
rule_name
=
rule_name
def
inner_from_python
(
expression
):
retval
=
None
if
callable
(
expression
):
# Is this expression a parser rule?
...
...
arpeggio/peg.py
View file @
43dd61e4
...
...
@@ -47,15 +47,6 @@ def expression(): return [regex,(rule_identifier, Not(LEFT_ARROW)),
# ------------------------------------------------------------------
# PEG Semantic Actions
class
RuleReference
(
object
):
'''
Used for rule reference resolving in the second
pass of the semantic analysis.
'''
def
__init__
(
self
,
rule_name
):
self
.
rule_name
=
rule_name
class
PEGSemanticAction
(
SemanticAction
):
def
_resolve
(
self
,
parser
,
rule_name
):
if
rule_name
in
parser
.
peg_rules
:
...
...
@@ -67,11 +58,11 @@ class PEGSemanticAction(SemanticAction):
.
format
(
rule_name
))
def
second_pass
(
self
,
parser
,
node
):
if
isinstance
(
node
,
RuleReference
):
if
isinstance
(
node
,
CrossRef
):
return
self
.
_resolve
(
parser
,
node
.
rule_name
)
elif
isinstance
(
node
,
ParsingExpression
):
for
i
,
n
in
node
.
nodes
.
items
(
):
if
isinstance
(
n
,
RuleReference
):
for
i
,
n
in
enumerate
(
node
.
nodes
):
if
isinstance
(
n
,
CrossRef
):
node
[
i
]
=
self
.
_resolve
(
parser
,
n
.
rule_name
)
return
node
else
:
...
...
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