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
c3d8a5be
Commit
c3d8a5be
authored
Feb 02, 2014
by
Igor Dejanovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed logging module from examples.
parent
08653e36
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
14 deletions
+8
-14
bibtex.py
examples/bibtex.py
+7
-10
calc_peg.py
examples/calc_peg.py
+1
-3
json.py
examples/json.py
+0
-1
No files found.
examples/bibtex.py
View file @
c3d8a5be
...
...
@@ -13,7 +13,6 @@ import sys
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
RegExMatch
as
_
import
logging
def
bibfile
():
return
ZeroOrMore
([
bibentry
,
comment
]),
EndOfFile
...
...
@@ -29,7 +28,8 @@ def comment(): return _(r'[^@]+')
class
BibFileSem
(
SemanticAction
):
'''Just returns list of child nodes (bibentries).'''
def
first_pass
(
self
,
parser
,
node
,
nodes
):
logging
.
debug
(
"Processing Bibfile"
)
if
parser
.
debug
:
print
"Processing Bibfile"
return
nodes
[:
-
1
]
...
...
@@ -37,7 +37,8 @@ class BibEntrySem(SemanticAction):
'''Constructs a map where key is bibentry field name.
Key is returned under 'bibkey' key. Type is returned under 'bibtype'.'''
def
first_pass
(
self
,
parser
,
node
,
nodes
):
logging
.
debug
(
" Processing bibentry
%
s"
%
nodes
[
2
])
if
parser
.
debug
:
print
" Processing bibentry
%
s"
%
nodes
[
2
]
bib_entry_map
=
{
'bibtype'
:
nodes
[
0
]
.
value
,
'bibkey'
:
nodes
[
2
]
.
value
...
...
@@ -51,7 +52,8 @@ class BibEntrySem(SemanticAction):
class
FieldSem
(
SemanticAction
):
'''Constructs a tuple (fieldname, fieldvalue).'''
def
first_pass
(
self
,
parser
,
node
,
nodes
):
logging
.
debug
(
" Processing field
%
s"
%
nodes
[
0
])
if
parser
.
debug
:
print
" Processing field
%
s"
%
nodes
[
0
]
field
=
(
nodes
[
0
]
.
value
,
nodes
[
3
])
return
field
...
...
@@ -75,13 +77,10 @@ field.sem = FieldSem()
fieldvalue
.
sem
=
FieldValueSem
()
if
__name__
==
"__main__"
:
try
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# First we will make a parser - an instance of the bib parser model.
# Parser model is given in the form of python constructs therefore we
# are using ParserPython class.
parser
=
ParserPython
(
bibfile
,
reduce_tree
=
True
)
parser
=
ParserPython
(
bibfile
,
reduce_tree
=
True
,
debug
=
True
)
# Then we export it to a dot file in order to visualise it. This is
# particulary handy for debugging purposes.
...
...
@@ -109,5 +108,3 @@ if __name__ == "__main__":
else
:
print
"Usage: python bibtex.py file_to_parse"
except
NoMatch
,
e
:
print
"Expected
%
s at position
%
s."
%
(
e
.
value
,
str
(
e
.
parser
.
pos_to_linecol
(
e
.
position
)))
examples/calc_peg.py
View file @
c3d8a5be
...
...
@@ -16,7 +16,6 @@
from
arpeggio
import
*
from
arpeggio.peg
import
ParserPEG
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
import
logging
# Semantic actions
from
calc
import
ToFloat
,
Factor
,
Term
,
Expr
,
Calc
...
...
@@ -41,12 +40,11 @@ sem_actions = {
}
try
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
# First we will make a parser - an instance of the calc parser model.
# Parser model is given in the form of PEG notation therefore we
# are using ParserPEG class. Root rule name (parsing expression) is "calc".
parser
=
ParserPEG
(
calc_grammar
,
"calc"
)
parser
=
ParserPEG
(
calc_grammar
,
"calc"
,
debug
=
True
)
# Then we export it to a dot file.
...
...
examples/json.py
View file @
c3d8a5be
...
...
@@ -36,7 +36,6 @@ value
from
arpeggio
import
*
from
arpeggio.export
import
PMDOTExport
,
PTDOTExport
from
arpeggio
import
RegExMatch
as
_
import
logging
def
TRUE
():
return
"true"
def
FALSE
():
return
"false"
...
...
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