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
7eb2e080
Commit
7eb2e080
authored
Jan 24, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed logging module from examples.
parent
7eef4197
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
21 deletions
+11
-21
json.py
examples/json.py
+1
-3
peg_peg.py
examples/peg_peg.py
+1
-3
robot.py
examples/robot.py
+7
-9
robot_peg.py
examples/robot_peg.py
+1
-3
simple.py
examples/simple.py
+1
-3
No files found.
examples/json.py
View file @
7eb2e080
...
...
@@ -83,10 +83,8 @@ if __name__ == "__main__":
}
"""
try
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# Creating parser from parser model.
parser
=
ParserPython
(
jsonFile
)
parser
=
ParserPython
(
jsonFile
,
debug
=
True
)
# Exporting parser model to dot file in order to visualise it.
PMDOTExport
()
.
exportFile
(
parser
.
parser_model
,
...
...
examples/peg_peg.py
View file @
7eb2e080
...
...
@@ -13,7 +13,6 @@
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio.peg
import
ParserPEG
import
logging
# Semantic actions
from
arpeggio.peg
import
SemGrammar
,
SemRule
,
SemOrderedChoice
,
SemSequence
,
\
...
...
@@ -67,11 +66,10 @@ peg_grammar = r"""
try
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# ParserPEG will use ParserPython to parse peg_grammar definition and
# create parser_model for parsing PEG based grammars
parser
=
ParserPEG
(
peg_grammar
,
'grammar'
)
parser
=
ParserPEG
(
peg_grammar
,
'grammar'
,
debug
=
True
)
# Exporting parser model to dot file in order to visualise.
PMDOTExport
()
.
exportFile
(
parser
.
parser_model
,
...
...
examples/robot.py
View file @
7eb2e080
...
...
@@ -22,7 +22,6 @@
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
RegExMatch
as
_
import
logging
# Grammar rules
def
program
():
return
Kwd
(
'begin'
),
ZeroOrMore
(
command
),
Kwd
(
'end'
),
EndOfFile
...
...
@@ -36,33 +35,33 @@ def right(): return 'right'
# Semantic actions
class
Up
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
logging
.
debug
(
"Going up"
)
print
"Going up"
return
(
0
,
1
)
class
Down
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
logging
.
debug
(
"Going down"
)
print
"Going down"
return
(
0
,
-
1
)
class
Left
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
logging
.
debug
(
"Going left"
)
print
"Going left"
return
(
-
1
,
0
)
class
Right
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
logging
.
debug
(
"Going right"
)
print
"Going right"
return
(
1
,
0
)
class
Command
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
logging
.
debug
(
"Command"
)
print
"Command"
return
nodes
[
0
]
class
Program
(
SemanticAction
):
def
first_pass
(
self
,
parser
,
node
,
nodes
):
logging
.
debug
(
"Evaluating position"
)
print
"Evaluating position"
return
reduce
(
lambda
x
,
y
:
(
x
[
0
]
+
y
[
0
],
x
[
1
]
+
y
[
1
]),
nodes
[
1
:
-
2
])
# Connecting rules with semantic actions
...
...
@@ -75,7 +74,6 @@ right.sem = Right()
if
__name__
==
"__main__"
:
try
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# Program code
input
=
'''
...
...
@@ -92,7 +90,7 @@ if __name__ == "__main__":
# First we will make a parser - an instance of the robot parser model.
# Parser model is given in the form of python constructs therefore we
# are using ParserPython class.
parser
=
ParserPython
(
program
)
parser
=
ParserPython
(
program
,
debug
=
True
)
# Then we export it to a dot file in order to visualize it. This is
# particularly handy for debugging purposes.
...
...
examples/robot_peg.py
View file @
7eb2e080
...
...
@@ -22,7 +22,6 @@
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
RegExMatch
as
_
import
logging
from
arpeggio.peg
import
ParserPEG
# Grammar rules
...
...
@@ -49,7 +48,6 @@ semantic_actions = {
if
__name__
==
"__main__"
:
try
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# Program code
input
=
'''
...
...
@@ -66,7 +64,7 @@ if __name__ == "__main__":
# First we will make a parser - an instance of the robot parser model.
# Parser model is given in the form of PEG specification therefore we
# are using ParserPEG class.
parser
=
ParserPEG
(
robot_grammar
,
'program'
)
parser
=
ParserPEG
(
robot_grammar
,
'program'
,
debug
=
True
)
# Then we export it to a dot file in order to visualize it. This is
# particularly handy for debugging purposes.
...
...
examples/simple.py
View file @
7eb2e080
...
...
@@ -12,7 +12,6 @@
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
RegExMatch
as
_
import
logging
def
comment
():
return
[
_
(
"//.*"
),
_
(
"/
\
*.*
\
*/"
)]
def
literal
():
return
_
(
r'\d*\.\d*|\d+|".*?"'
)
...
...
@@ -31,11 +30,10 @@ def function(): return Kwd("function"), symbol, parameterlist, block
def
simpleLanguage
():
return
function
try
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# Parser instantiation. simpleLanguage is root definition and comment is
# grammar rule for comments.
parser
=
ParserPython
(
simpleLanguage
,
comment
)
parser
=
ParserPython
(
simpleLanguage
,
comment
,
debug
=
True
)
# We save parser model to dot file in order to visualise it.
# We can make a jpg out of it using dot (part of graphviz) like this
...
...
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