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

Removed logging module from examples.

parent 7eef4197
...@@ -83,10 +83,8 @@ if __name__ == "__main__": ...@@ -83,10 +83,8 @@ if __name__ == "__main__":
} }
""" """
try: try:
logging.basicConfig(level=logging.DEBUG)
# Creating parser from parser model. # Creating parser from parser model.
parser = ParserPython(jsonFile) parser = ParserPython(jsonFile, debug=True)
# Exporting parser model to dot file in order to visualise it. # Exporting parser model to dot file in order to visualise it.
PMDOTExport().exportFile(parser.parser_model, PMDOTExport().exportFile(parser.parser_model,
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
from arpeggio import * from arpeggio import *
from arpeggio.export import PMDOTExport, PTDOTExport from arpeggio.export import PMDOTExport, PTDOTExport
from arpeggio.peg import ParserPEG from arpeggio.peg import ParserPEG
import logging
# Semantic actions # Semantic actions
from arpeggio.peg import SemGrammar, SemRule, SemOrderedChoice, SemSequence,\ from arpeggio.peg import SemGrammar, SemRule, SemOrderedChoice, SemSequence,\
...@@ -67,11 +66,10 @@ peg_grammar = r""" ...@@ -67,11 +66,10 @@ peg_grammar = r"""
try: try:
logging.basicConfig(level=logging.DEBUG)
# ParserPEG will use ParserPython to parse peg_grammar definition and # ParserPEG will use ParserPython to parse peg_grammar definition and
# create parser_model for parsing PEG based grammars # 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. # Exporting parser model to dot file in order to visualise.
PMDOTExport().exportFile(parser.parser_model, PMDOTExport().exportFile(parser.parser_model,
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
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
# Grammar rules # Grammar rules
def program(): return Kwd('begin'), ZeroOrMore(command), Kwd('end'), EndOfFile def program(): return Kwd('begin'), ZeroOrMore(command), Kwd('end'), EndOfFile
...@@ -36,33 +35,33 @@ def right(): return 'right' ...@@ -36,33 +35,33 @@ def right(): return 'right'
# Semantic actions # Semantic actions
class Up(SemanticAction): class Up(SemanticAction):
def first_pass(self, parser, node, nodes): def first_pass(self, parser, node, nodes):
logging.debug("Going up") print "Going up"
return (0, 1) return (0, 1)
class Down(SemanticAction): class Down(SemanticAction):
def first_pass(self, parser, node, nodes): def first_pass(self, parser, node, nodes):
logging.debug("Going down") print "Going down"
return (0, -1) return (0, -1)
class Left(SemanticAction): class Left(SemanticAction):
def first_pass(self, parser, node, nodes): def first_pass(self, parser, node, nodes):
logging.debug("Going left") print "Going left"
return (-1, 0) return (-1, 0)
class Right(SemanticAction): class Right(SemanticAction):
def first_pass(self, parser, node, nodes): def first_pass(self, parser, node, nodes):
logging.debug("Going right") print "Going right"
return (1, 0) return (1, 0)
class Command(SemanticAction): class Command(SemanticAction):
def first_pass(self, parser, node, nodes): def first_pass(self, parser, node, nodes):
logging.debug("Command") print "Command"
return nodes[0] return nodes[0]
class Program(SemanticAction): class Program(SemanticAction):
def first_pass(self, parser, node, nodes): 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]) return reduce(lambda x, y: (x[0]+y[0], x[1]+y[1]), nodes[1:-2])
# Connecting rules with semantic actions # Connecting rules with semantic actions
...@@ -75,7 +74,6 @@ right.sem = Right() ...@@ -75,7 +74,6 @@ right.sem = Right()
if __name__ == "__main__": if __name__ == "__main__":
try: try:
logging.basicConfig(level=logging.DEBUG)
# Program code # Program code
input = ''' input = '''
...@@ -92,7 +90,7 @@ if __name__ == "__main__": ...@@ -92,7 +90,7 @@ if __name__ == "__main__":
# First we will make a parser - an instance of the robot parser model. # 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 # Parser model is given in the form of python constructs therefore we
# are using ParserPython class. # 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 # Then we export it to a dot file in order to visualize it. This is
# particularly handy for debugging purposes. # particularly handy for debugging purposes.
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
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
from arpeggio.peg import ParserPEG from arpeggio.peg import ParserPEG
# Grammar rules # Grammar rules
...@@ -49,7 +48,6 @@ semantic_actions = { ...@@ -49,7 +48,6 @@ semantic_actions = {
if __name__ == "__main__": if __name__ == "__main__":
try: try:
logging.basicConfig(level=logging.DEBUG)
# Program code # Program code
input = ''' input = '''
...@@ -66,7 +64,7 @@ if __name__ == "__main__": ...@@ -66,7 +64,7 @@ if __name__ == "__main__":
# First we will make a parser - an instance of the robot parser model. # 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 # Parser model is given in the form of PEG specification therefore we
# are using ParserPEG class. # 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 # Then we export it to a dot file in order to visualize it. This is
# particularly handy for debugging purposes. # particularly handy for debugging purposes.
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
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 comment(): return [_("//.*"), _("/\*.*\*/")] def comment(): return [_("//.*"), _("/\*.*\*/")]
def literal(): return _(r'\d*\.\d*|\d+|".*?"') def literal(): return _(r'\d*\.\d*|\d+|".*?"')
...@@ -31,11 +30,10 @@ def function(): return Kwd("function"), symbol, parameterlist, block ...@@ -31,11 +30,10 @@ def function(): return Kwd("function"), symbol, parameterlist, block
def simpleLanguage(): return function def simpleLanguage(): return function
try: try:
logging.basicConfig(level=logging.DEBUG)
# Parser instantiation. simpleLanguage is root definition and comment is # Parser instantiation. simpleLanguage is root definition and comment is
# grammar rule for comments. # 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 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 # 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