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/macroExpander.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'examples/macroExpander.py') diff --git a/examples/macroExpander.py b/examples/macroExpander.py index c6b7034..3b06250 100644 --- a/examples/macroExpander.py +++ b/examples/macroExpander.py @@ -16,7 +16,7 @@ from pyparsing import * # define the structure of a macro definition (the empty term is used # to advance to the next non-whitespace character) -identifier = Word(alphas+"_",alphanums+"_") +identifier = Word(alphas + "_", alphanums + "_") macroDef = "#def" + identifier("macro") + empty + restOfLine("value") # define a placeholder for defined macros - initially nothing @@ -27,16 +27,18 @@ macroExpr << NoMatch() macros = {} # parse action for macro definitions -def processMacroDefn(s,l,t): +def processMacroDefn(s, l, t): macroVal = macroExpander.transformString(t.value) macros[t.macro] = macroVal macroExpr << MatchFirst(map(Keyword, macros.keys())) return "#def " + t.macro + " " + macroVal + # parse action to replace macro references with their respective definition -def processMacroRef(s,l,t): +def processMacroRef(s, l, t): return macros[t[0]] + # attach parse actions to expressions macroExpr.setParseAction(processMacroRef) macroDef.setParseAction(processMacroDefn) @@ -45,7 +47,6 @@ macroDef.setParseAction(processMacroDefn) macroExpander = macroExpr | macroDef - # test macro substitution using transformString testString = """ #def A 100 -- cgit v1.2.1