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
35c767fc
Commit
35c767fc
authored
11 years ago
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing formatting in peg.py
parent
d21f6388
master
cleanpeg
feature/add_jenkins_file
gm/master
release/v0.7.x
release/v0.8.x
visitor
v0.9
v0.8.1
v0.8
v0.7.1
v0.7
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
8 deletions
+19
-8
peg.py
arpeggio/peg.py
+19
-8
No files found.
arpeggio/peg.py
View file @
35c767fc
...
...
@@ -49,21 +49,23 @@ class PEGSemanticAction(SemanticAction):
def
second_pass
(
self
,
parser
,
node
):
if
isinstance
(
node
,
Terminal
):
return
for
i
,
n
in
enumerate
(
node
.
nodes
):
for
i
,
n
in
enumerate
(
node
.
nodes
):
if
isinstance
(
n
,
Terminal
):
if
n
.
value
in
parser
.
peg_rules
:
node
.
nodes
[
i
]
=
parser
.
peg_rules
[
n
.
value
]
else
:
raise
SemanticError
(
"Rule
\"
%
s
\"
does not exists."
%
n
)
class
SemGrammar
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
return
parser
.
peg_rules
[
parser
.
root_rule_name
]
class
SemRule
(
PEGSemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
rule_name
=
children
[
0
]
.
value
if
len
(
children
)
>
4
:
if
len
(
children
)
>
4
:
retval
=
Sequence
(
nodes
=
children
[
2
:
-
1
])
else
:
retval
=
children
[
2
]
...
...
@@ -77,26 +79,29 @@ class SemRule(PEGSemanticAction):
parser
.
peg_rules
[
rule_name
]
=
retval
return
retval
class
SemSequence
(
PEGSemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
if
len
(
children
)
>
1
:
if
len
(
children
)
>
1
:
return
Sequence
(
nodes
=
children
)
else
:
return
children
[
0
]
class
SemOrderedChoice
(
PEGSemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
if
len
(
children
)
>
1
:
if
len
(
children
)
>
1
:
retval
=
OrderedChoice
(
nodes
=
children
[::
2
])
else
:
retval
=
children
[
0
]
return
retval
class
SemPrefix
(
PEGSemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
if
parser
.
debug
:
print
(
"Prefix: {} "
.
format
(
str
(
children
)))
if
len
(
children
)
==
2
:
if
len
(
children
)
==
2
:
if
children
[
0
]
==
NOT
():
retval
=
Not
()
else
:
...
...
@@ -110,6 +115,7 @@ class SemPrefix(PEGSemanticAction):
return
retval
class
SemSufix
(
PEGSemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
if
parser
.
debug
:
...
...
@@ -132,27 +138,31 @@ class SemSufix(PEGSemanticAction):
return
retval
class
SemExpression
(
PEGSemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
if
parser
.
debug
:
print
(
"Expression : {}"
.
format
(
str
(
children
)))
if
len
(
children
)
==
1
:
if
len
(
children
)
==
1
:
return
children
[
0
]
else
:
return
children
[
1
]
class
SemIdentifier
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
if
parser
.
debug
:
print
(
"Identifier {}."
.
format
(
node
.
value
))
return
node
class
SemRegEx
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
if
parser
.
debug
:
print
(
"RegEx {}."
.
format
(
children
[
1
]
.
value
))
return
RegExMatch
(
children
[
1
]
.
value
)
class
SemLiteral
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
if
parser
.
debug
:
...
...
@@ -162,6 +172,7 @@ class SemLiteral(SemanticAction):
match_str
=
match_str
.
replace
(
"
\\\\
"
,
"
\\
"
)
return
StrMatch
(
match_str
)
class
SemTerminal
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
children
):
return
StrMatch
(
node
.
value
)
...
...
@@ -182,7 +193,8 @@ for sem in [LEFT_ARROW, SLASH, STAR, QUESTION, PLUS, AND, NOT, OPEN, CLOSE]:
class
ParserPEG
(
Parser
):
def
__init__
(
self
,
language_def
,
root_rule_name
,
comment_rule_name
=
None
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
language_def
,
root_rule_name
,
comment_rule_name
=
None
,
*
args
,
**
kwargs
):
super
(
ParserPEG
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
root_rule_name
=
root_rule_name
...
...
@@ -202,4 +214,3 @@ class ParserPEG(Parser):
parser
.
root_rule_name
=
self
.
root_rule_name
parser
.
parse
(
language_def
)
return
parser
.
getASG
()
This diff is collapsed.
Click to expand it.
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