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
bb4a4bc8
Commit
bb4a4bc8
authored
Oct 12, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
peg_peg example reworked to use PEGVisitor
parent
93a7e010
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
20 deletions
+5
-20
peg_peg.py
examples/peg_peg.py
+5
-20
No files found.
examples/peg_peg.py
View file @
bb4a4bc8
...
...
@@ -15,24 +15,7 @@ from __future__ import unicode_literals
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExporter
from
arpeggio.peg
import
ParserPEG
# Semantic actions
from
arpeggio.peg
import
SemGrammar
,
sem_rule
,
sem_sequence
,
sem_ordered_choice
,
\
sem_sufix
,
sem_prefix
,
sem_strmatch
,
sem_regex
,
sem_rule_crossref
sem_actions
=
{
"peggrammar"
:
SemGrammar
(),
"rule"
:
sem_rule
,
"ordered_choice"
:
sem_ordered_choice
,
"sequence"
:
sem_sequence
,
"prefix"
:
sem_prefix
,
"sufix"
:
sem_sufix
,
"expression"
:
SemanticActionSingleChild
(),
"regex"
:
sem_regex
,
"str_match"
:
sem_strmatch
,
"rule_crossref"
:
sem_rule_crossref
}
from
arpeggio.peg
import
ParserPEG
,
PEGVisitor
# PEG defined using PEG itself.
...
...
@@ -76,11 +59,13 @@ def main(debug=False):
# Now we will use created parser to parse the same peg_grammar used for
# parser initialization. We can parse peg_grammar because it is specified
# using PEG itself.
parser
.
parse
(
peg_grammar
)
parse
_tree
=
parse
r
.
parse
(
peg_grammar
)
# ASG should be the same as parser.parser_model because semantic
# actions will create PEG parser (tree of ParsingExpressions).
asg
=
parser
.
getASG
(
sem_actions
)
asg
=
visit_parse_tree
(
parse_tree
,
PEGVisitor
(
root_rule_name
=
'peggrammar'
,
ignore_case
=
False
,
debug
=
debug
))
if
debug
:
# This graph should be the same as peg_peg_parser_model.dot because
...
...
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