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
e30f7617
Commit
e30f7617
authored
Jul 27, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing peg_peg example
Reworked peg_peg example to align with the previous changes.
parent
94958f52
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
16 deletions
+11
-16
peg_peg.py
examples/peg_peg.py
+11
-16
No files found.
examples/peg_peg.py
View file @
e30f7617
...
...
@@ -16,8 +16,7 @@ from arpeggio.peg import ParserPEG
# Semantic actions
from
arpeggio.peg
import
SemGrammar
,
SemRule
,
SemOrderedChoice
,
SemSequence
,
\
SemPrefix
,
SemSufix
,
SemExpression
,
SemRegEx
,
SemIdentifier
,
SemLiteral
,
\
SemTerminal
SemPrefix
,
SemSufix
,
SemExpression
,
SemRegEx
,
SemStrMatch
,
SemRuleCrossRef
sem_actions
=
{
"grammar"
:
SemGrammar
(),
...
...
@@ -28,29 +27,26 @@ sem_actions = {
"sufix"
:
SemSufix
(),
"expression"
:
SemExpression
(),
"regex"
:
SemRegEx
(),
"
identifier"
:
SemIdentifier
(),
"
literal"
:
SemLiteral
()
"
str_match"
:
SemStrMatch
(),
"
rule_crossref"
:
SemRuleCrossRef
()
}
for
sem
in
[
"LEFT_ARROW"
,
"SLASH"
,
"STAR"
,
"QUESTION"
,
"PLUS"
,
"AND"
,
"NOT"
,
"OPEN"
,
"CLOSE"
]:
sem_actions
[
sem
]
=
SemTerminal
()
# PEG defined using PEG itself.
peg_grammar
=
r"""
grammar <- rule+ E
ndOfFile
;
rule <-
identifier
LEFT_ARROW ordered_choice ';';
grammar <- rule+ E
OF
;
rule <-
rule_name
LEFT_ARROW ordered_choice ';';
ordered_choice <- sequence (SLASH sequence)*;
sequence <- prefix+;
prefix <- (AND/NOT)? sufix;
sufix <- expression (QUESTION/STAR/PLUS)?;
expression <- regex /
(identifier !LEFT_ARROW)
/ (
"(" ordered_choice ")") / literal
;
expression <- regex /
rule_crossref
/ (
OPEN ordered_choice CLOSE) / str_match
;
identifier <- r'[a-zA-Z_]([a-zA-Z_]|[0-9])*';
rule_name <- r'[a-zA-Z_]([a-zA-Z_]|[0-9])*';
rule_crossref <- rule_name;
regex <- 'r\'' r'(\\\'|[^\'])*' '\'';
literal
<- r'\'(\\\'|[^\'])*\'|"[^"]*"';
str_match
<- r'\'(\\\'|[^\'])*\'|"[^"]*"';
LEFT_ARROW <- '<-';
SLASH <- '/';
AND <- '&';
...
...
@@ -78,7 +74,7 @@ PMDOTExporter().exportFile(parser.parser_model,
# using PEG itself.
parser
.
parse
(
peg_grammar
)
# Again we export parse tree in dot file for vi
z
ualization.
# Again we export parse tree in dot file for vi
s
ualization.
PTDOTExporter
()
.
exportFile
(
parser
.
parse_tree
,
"peg_peg_parse_tree.dot"
)
...
...
@@ -95,4 +91,3 @@ PMDOTExporter().exportFile(asg,
# parse PEG grammars
parser
.
parser_model
=
asg
parser
.
parse
(
peg_grammar
)
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