Commit c3d8a5be authored by Igor Dejanovic's avatar Igor Dejanovic

Removed logging module from examples.

parent 08653e36
......@@ -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)))
......@@ -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.
......
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment