summaryrefslogtreecommitdiff
path: root/src/examples/matchPreviousDemo.py
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2012-10-02 04:55:56 +0000
committerPaul McGuire <ptmcg@austin.rr.com>2012-10-02 04:55:56 +0000
commita7f9dda0668bfce4fba51df1bf2976b4a93a8bd5 (patch)
tree57ea8bcf2e66532a36c833a7bc57cff9d5d0e4dd /src/examples/matchPreviousDemo.py
parentf5d2b716ffb57b65660a7ee0bbf04332dfb29620 (diff)
downloadpyparsing-git-a7f9dda0668bfce4fba51df1bf2976b4a93a8bd5.tar.gz
Add example files to SVN
Diffstat (limited to 'src/examples/matchPreviousDemo.py')
-rw-r--r--src/examples/matchPreviousDemo.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/examples/matchPreviousDemo.py b/src/examples/matchPreviousDemo.py
new file mode 100644
index 0000000..91d7eb1
--- /dev/null
+++ b/src/examples/matchPreviousDemo.py
@@ -0,0 +1,33 @@
+#
+# matchPreviousDemo.py
+#
+
+from pyparsing import *
+
+src = """
+class a
+...
+end a;
+
+class b
+...
+end b;
+
+class c
+...
+end d;"""
+
+
+identifier = Word(alphas)
+
+classIdent = identifier("classname") # note that this also makes a copy of identifier
+classHead = "class" + classIdent
+classBody = "..."
+classEnd = "end" + matchPreviousLiteral(classIdent) + ';'
+classDefn = classHead + classBody + classEnd
+
+# use this form to catch syntax error
+# classDefn = classHead + classBody - classEnd
+
+for tokens in classDefn.searchString(src):
+ print tokens.classname \ No newline at end of file