summaryrefslogtreecommitdiff
path: root/src/examples/macroExpander.py
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2015-12-31 00:55:47 +0000
committerPaul McGuire <ptmcg@austin.rr.com>2015-12-31 00:55:47 +0000
commit401ba4a945b88f12e26495a82d4059d4adbaec92 (patch)
tree9570287813d7358750ddd1ffe50ba60c0a999972 /src/examples/macroExpander.py
parentc8e8c6592d625d24bc7c0ca34bcc527ec380c2d5 (diff)
downloadpyparsing-git-401ba4a945b88f12e26495a82d4059d4adbaec92.tar.gz
Added new example parseTabularData.py
Updated several examples to more current Python and pyparsing practices (and better Py2/Py3 cross-compatibility)
Diffstat (limited to 'src/examples/macroExpander.py')
-rw-r--r--src/examples/macroExpander.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/examples/macroExpander.py b/src/examples/macroExpander.py
index 89562a4..327976c 100644
--- a/src/examples/macroExpander.py
+++ b/src/examples/macroExpander.py
@@ -16,11 +16,12 @@ from pyparsing import *
# define the structure of a macro definition (the empty term is used
# to advance to the next non-whitespace character)
-macroDef = "#def" + Word(alphas+"_",alphanums+"_").setResultsName("macro") + \
- empty + restOfLine.setResultsName("value")
+identifier = Word(alphas+"_",alphanums+"_")
+macroDef = "#def" + identifier("macro") + empty + restOfLine("value")
# define a placeholder for defined macros - initially nothing
macroExpr = Forward()
+macroExpr << NoMatch()
# global dictionary for macro definitions
macros = {}
@@ -29,7 +30,7 @@ macros = {}
def processMacroDefn(s,l,t):
macroVal = macroExpander.transformString(t.value)
macros[t.macro] = macroVal
- macroExpr << MatchFirst( list(map(Keyword,list(macros.keys()))) )
+ macroExpr << MatchFirst(map(Keyword, macros.keys()))
return "#def " + t.macro + " " + macroVal
# parse action to replace macro references with their respective definition