Applied pep8 and pyflakes recommendations.

parent 9bb7dede
......@@ -16,6 +16,7 @@ sys.path.insert(1, EXTERNAL_MODS)
from pybison import BisonParser
class Parser(BisonParser):
"""
Implements the calculator parser. Grammar rules are defined in the method
......@@ -197,9 +198,13 @@ class Parser(BisonParser):
#define YYSTYPE void *
#include "tokens.h"
extern void *py_parser;
extern void (*py_input)(PyObject *parser, char *buf, int *result, int max_size);
#define returntoken(tok) yylval = PyString_FromString(strdup(yytext)); return (tok);
#define YY_INPUT(buf,result,max_size) { (*py_input)(py_parser, buf, &result, max_size); }
extern void (*py_input)(PyObject *parser, char *buf, int *result,
int max_size);
#define returntoken(tok) \
yylval = PyString_FromString(strdup(yytext)); return (tok);
#define YY_INPUT(buf,result,max_size) { \
(*py_input)(py_parser, buf, &result, max_size); \
}
%}
%%
......@@ -217,7 +222,8 @@ class Parser(BisonParser):
[ \t\v\f] {}
[\n] {yylineno++; returntoken(NEWLINE); }
. { printf("unknown char %c ignored, yytext=0x%lx\n", yytext[0], yytext); /* ignore bad chars */}
. { printf("unknown char %c ignored, yytext=0x%lx\n",
yytext[0], yytext); /* ignore bad chars */}
%%
......
......@@ -3,16 +3,16 @@ import logging.config
import sys
try:
import config
import config as cfg
except ImportError:
config = object()
cfg = object()
import default_config as default
try:
logging.basicConfig(level=logging.DEBUG,
format=getattr(config, 'LOG_FORMAT', default.LOG_FORMAT),
filename=getattr(config, 'LOG_FILE', default.LOG_FILE),
format=getattr(cfg, 'LOG_FORMAT', default.LOG_FORMAT),
filename=getattr(cfg, 'LOG_FILE', default.LOG_FILE),
filemode='a')
except IOError as e: # pragma: no cover
print >>sys.stderr, 'warning: IOError raised: "%s"' % str(e)
......
......@@ -19,7 +19,7 @@ sys.path.insert(1, EXTERNAL_MODS)
from pybison import BisonParser, BisonSyntaxError
from graph_drawing.graph import generate_graph
from node import TYPE_OPERATOR, OP_ADD, OP_MUL, OP_SUB, OP_NEG
from node import TYPE_OPERATOR, OP_ADD, OP_MUL, OP_SUB
# Check for n-ary operator in child nodes
......@@ -28,13 +28,6 @@ def combine(op, op_type, *nodes):
res = [op]
for n in nodes:
try:
assert n.type != TYPE_OPERATOR or n.op != OP_NEG or len(n.nodes) == 1
assert n.type != TYPE_OPERATOR or n.op != OP_SUB or len(n.nodes) > 1
except AssertionError:
print n, type(n), n.type, OP_NEG, OP_SUB, n.nodes, len(n.nodes)
raise
# Merge the children for all nodes which have the same operator.
if n.type == TYPE_OPERATOR and n.op == op_type:
res += n.nodes
......@@ -367,14 +360,20 @@ class Parser(BisonParser):
def get_args():
parser = argparse.ArgumentParser(prog='parser', description=__doc__)
parser.add_argument('--debug', '-d', action='store_true', default=False,
parser.add_argument('--debug', '-d', action='store_true',
default=False,
help='Enable debug mode in bison and flex.')
parser.add_argument('--verbose', '-v', action='store_true', default=False,
parser.add_argument('--verbose', '-v', action='store_true',
default=False,
help='Enable verbose output messages (printed to stdout).')
parser.add_argument('--keepfiles', '-k', action='store_true', default=False,
parser.add_argument('--keepfiles', '-k', action='store_true',
default=False,
help='Keep temporary generated bison and lex files.')
parser.add_argument('--batch', '-b', action='store_true', default=False,
help='Disable interactive mode and execute expressions in batch mode.')
help='Disable interactive mode and execute expressions in batch' \
' mode.')
return parser.parse_args()
......
......@@ -5,6 +5,7 @@ from rules import rules
# (node, funcptr, (args...))
def get_node_possibilities(node):
"""
Get all possible rewrite steps for this node.
......@@ -18,6 +19,7 @@ def get_node_possibilities(node):
return possibilities
def get_possibilities(node):
"""
Get all possible rewrite steps for this node and its children.
......@@ -29,6 +31,7 @@ def get_possibilities(node):
return possibilities
if __name__ == '__main__':
node = main()
print 'node:', node
......
......@@ -2,7 +2,7 @@ import unittest
from src.parser import Parser
from src.node import ExpressionNode as N, ExpressionLeaf as L
from tests.parser import ParserWrapper, run_expressions
from tests.parser import run_expressions
class TestB1Ch8(unittest.TestCase):
......
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