From 53d1b4a6f48a53c4c4ec4ac7031362b691c0366d Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 31 Oct 2019 21:10:28 -0700 Subject: Blacken the project (#141) --- examples/simpleArith.py | 53 +++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'examples/simpleArith.py') diff --git a/examples/simpleArith.py b/examples/simpleArith.py index af05373..af3f904 100644 --- a/examples/simpleArith.py +++ b/examples/simpleArith.py @@ -9,15 +9,15 @@ from pyparsing import * -integer = Word(nums).setParseAction(lambda t:int(t[0])) -variable = Word(alphas,exact=1) +integer = Word(nums).setParseAction(lambda t: int(t[0])) +variable = Word(alphas, exact=1) operand = integer | variable -expop = Literal('^') -signop = oneOf('+ -') -multop = oneOf('* /') -plusop = oneOf('+ -') -factop = Literal('!') +expop = Literal("^") +signop = oneOf("+ -") +multop = oneOf("* /") +plusop = oneOf("+ -") +factop = Literal("!") # To use the infixNotation helper: # 1. Define the "atom" operand term of the grammar. @@ -43,24 +43,29 @@ factop = Literal('!') # this expression to parse input strings, or incorporate it # into a larger, more complex grammar. # -expr = infixNotation( operand, - [("!", 1, opAssoc.LEFT), - ("^", 2, opAssoc.RIGHT), - (signop, 1, opAssoc.RIGHT), - (multop, 2, opAssoc.LEFT), - (plusop, 2, opAssoc.LEFT),] - ) +expr = infixNotation( + operand, + [ + ("!", 1, opAssoc.LEFT), + ("^", 2, opAssoc.RIGHT), + (signop, 1, opAssoc.RIGHT), + (multop, 2, opAssoc.LEFT), + (plusop, 2, opAssoc.LEFT), + ], +) -test = ["9 + 2 + 3", - "9 + 2 * 3", - "(9 + 2) * 3", - "(9 + -2) * 3", - "(9 + -2) * 3^2^2", - "(9! + -2) * 3^2^2", - "M*X + B", - "M*(X + B)", - "1+2*-3^4*5+-+-6",] +test = [ + "9 + 2 + 3", + "9 + 2 * 3", + "(9 + 2) * 3", + "(9 + -2) * 3", + "(9 + -2) * 3^2^2", + "(9! + -2) * 3^2^2", + "M*X + B", + "M*(X + B)", + "1+2*-3^4*5+-+-6", +] for t in test: print(t) print(expr.parseString(t)) - print('') + print("") -- cgit v1.2.1