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
297eea71
Commit
297eea71
authored
Dec 17, 2013
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing PEP8 violations in peg_peg.
parent
40c1b0a9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
19 deletions
+20
-19
peg_peg.py
examples/peg_peg.py
+20
-19
No files found.
examples/peg_peg.py
View file @
297eea71
...
@@ -12,28 +12,29 @@
...
@@ -12,28 +12,29 @@
##############################################################################
##############################################################################
from
arpeggio
import
*
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
RegExMatch
as
_
from
arpeggio.peg
import
ParserPEG
from
arpeggio.peg
import
ParserPEG
import
logging
import
logging
# Semantic actions
# Semantic actions
from
arpeggio.peg
import
SemGrammar
,
SemRule
,
SemOrderedChoice
,
SemSequence
,
SemPrefix
,
\
from
arpeggio.peg
import
SemGrammar
,
SemRule
,
SemOrderedChoice
,
SemSequence
,
\
SemSufix
,
SemExpression
,
SemRegEx
,
SemIdentifier
,
SemLiteral
,
SemTerminal
SemPrefix
,
SemSufix
,
SemExpression
,
SemRegEx
,
SemIdentifier
,
SemLiteral
,
\
SemTerminal
sem_actions
=
{
sem_actions
=
{
"grammar"
:
SemGrammar
(),
"grammar"
:
SemGrammar
(),
"rule"
:
SemRule
(),
"rule"
:
SemRule
(),
"ordered_choice"
:
SemOrderedChoice
(),
"ordered_choice"
:
SemOrderedChoice
(),
"sequence"
:
SemSequence
(),
"sequence"
:
SemSequence
(),
"prefix"
:
SemPrefix
(),
"prefix"
:
SemPrefix
(),
"sufix"
:
SemSufix
(),
"sufix"
:
SemSufix
(),
"expression"
:
SemExpression
(),
"expression"
:
SemExpression
(),
"regex"
:
SemRegEx
(),
"regex"
:
SemRegEx
(),
"identifier"
:
SemIdentifier
(),
"identifier"
:
SemIdentifier
(),
"literal"
:
SemLiteral
()
"literal"
:
SemLiteral
()
}
}
for
sem
in
[
"LEFT_ARROW"
,
"SLASH"
,
"STAR"
,
"QUESTION"
,
"PLUS"
,
"AND"
,
"NOT"
,
"OPEN"
,
"CLOSE"
]:
for
sem
in
[
"LEFT_ARROW"
,
"SLASH"
,
"STAR"
,
"QUESTION"
,
"PLUS"
,
"AND"
,
"NOT"
,
"OPEN"
,
"CLOSE"
]:
sem_actions
[
sem
]
=
SemTerminal
()
sem_actions
[
sem
]
=
SemTerminal
()
...
@@ -76,9 +77,9 @@ try:
...
@@ -76,9 +77,9 @@ try:
PMDOTExport
()
.
exportFile
(
parser
.
parser_model
,
PMDOTExport
()
.
exportFile
(
parser
.
parser_model
,
"peg_peg_parser_model.dot"
)
"peg_peg_parser_model.dot"
)
# Now we will use created parser to parse the same peg_grammar used for
parser
# Now we will use created parser to parse the same peg_grammar used for
#
initialization. We can parse peg_grammar because it is specified using
#
parser initialization. We can parse peg_grammar because it is specified
# PEG itself.
#
using
PEG itself.
parser
.
parse
(
peg_grammar
)
parser
.
parse
(
peg_grammar
)
PTDOTExport
()
.
exportFile
(
parser
.
parse_tree
,
PTDOTExport
()
.
exportFile
(
parser
.
parse_tree
,
...
@@ -98,6 +99,6 @@ try:
...
@@ -98,6 +99,6 @@ try:
parser
.
parser_model
=
asg
parser
.
parser_model
=
asg
parser
.
parse
(
peg_grammar
)
parser
.
parse
(
peg_grammar
)
except
NoMatch
,
e
:
except
NoMatch
,
e
:
print
"Expected
%
s at position
%
s."
%
(
e
.
value
,
str
(
e
.
parser
.
pos_to_linecol
(
e
.
position
)))
print
"Expected
%
s at position
%
s."
%
\
(
e
.
value
,
str
(
e
.
parser
.
pos_to_linecol
(
e
.
position
)))
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