Commit 7eb2e080 authored by Igor Dejanovic's avatar Igor Dejanovic

Removed logging module from examples.

parent 7eef4197
......@@ -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,
......
......@@ -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,
......
......@@ -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.
......
......@@ -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.
......
......@@ -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
......
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