Commit c3d8a5be authored by Igor Dejanovic's avatar Igor Dejanovic

Removed logging module from examples.

parent 08653e36
...@@ -13,7 +13,6 @@ import sys ...@@ -13,7 +13,6 @@ import sys
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 import RegExMatch as _
import logging
def bibfile(): return ZeroOrMore([bibentry, comment]), EndOfFile def bibfile(): return ZeroOrMore([bibentry, comment]), EndOfFile
...@@ -29,7 +28,8 @@ def comment(): return _(r'[^@]+') ...@@ -29,7 +28,8 @@ def comment(): return _(r'[^@]+')
class BibFileSem(SemanticAction): class BibFileSem(SemanticAction):
'''Just returns list of child nodes (bibentries).''' '''Just returns list of child nodes (bibentries).'''
def first_pass(self, parser, node, nodes): def first_pass(self, parser, node, nodes):
logging.debug("Processing Bibfile") if parser.debug:
print "Processing Bibfile"
return nodes[:-1] return nodes[:-1]
...@@ -37,7 +37,8 @@ class BibEntrySem(SemanticAction): ...@@ -37,7 +37,8 @@ class BibEntrySem(SemanticAction):
'''Constructs a map where key is bibentry field name. '''Constructs a map where key is bibentry field name.
Key is returned under 'bibkey' key. Type is returned under 'bibtype'.''' Key is returned under 'bibkey' key. Type is returned under 'bibtype'.'''
def first_pass(self, parser, node, nodes): 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 = { bib_entry_map = {
'bibtype': nodes[0].value, 'bibtype': nodes[0].value,
'bibkey': nodes[2].value 'bibkey': nodes[2].value
...@@ -51,7 +52,8 @@ class BibEntrySem(SemanticAction): ...@@ -51,7 +52,8 @@ class BibEntrySem(SemanticAction):
class FieldSem(SemanticAction): class FieldSem(SemanticAction):
'''Constructs a tuple (fieldname, fieldvalue).''' '''Constructs a tuple (fieldname, fieldvalue).'''
def first_pass(self, parser, node, nodes): 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]) field = (nodes[0].value, nodes[3])
return field return field
...@@ -75,13 +77,10 @@ field.sem = FieldSem() ...@@ -75,13 +77,10 @@ field.sem = FieldSem()
fieldvalue.sem = FieldValueSem() fieldvalue.sem = FieldValueSem()
if __name__ == "__main__": if __name__ == "__main__":
try:
logging.basicConfig(level=logging.DEBUG)
# First we will make a parser - an instance of the bib parser model. # 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 # Parser model is given in the form of python constructs therefore we
# are using ParserPython class. # 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 # Then we export it to a dot file in order to visualise it. This is
# particulary handy for debugging purposes. # particulary handy for debugging purposes.
...@@ -109,5 +108,3 @@ if __name__ == "__main__": ...@@ -109,5 +108,3 @@ if __name__ == "__main__":
else: else:
print "Usage: python bibtex.py file_to_parse" 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 @@ ...@@ -16,7 +16,6 @@
from arpeggio import * from arpeggio import *
from arpeggio.peg import ParserPEG from arpeggio.peg import ParserPEG
from arpeggio.export import PMDOTExport, PTDOTExport from arpeggio.export import PMDOTExport, PTDOTExport
import logging
# Semantic actions # Semantic actions
from calc import ToFloat, Factor, Term, Expr, Calc from calc import ToFloat, Factor, Term, Expr, Calc
...@@ -41,12 +40,11 @@ sem_actions = { ...@@ -41,12 +40,11 @@ sem_actions = {
} }
try: try:
logging.basicConfig(level=logging.DEBUG)
# First we will make a parser - an instance of the calc parser model. # 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 # Parser model is given in the form of PEG notation therefore we
# are using ParserPEG class. Root rule name (parsing expression) is "calc". # 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. # Then we export it to a dot file.
......
...@@ -36,7 +36,6 @@ value ...@@ -36,7 +36,6 @@ value
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 import RegExMatch as _
import logging
def TRUE(): return "true" def TRUE(): return "true"
def FALSE(): return "false" 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