From 0b19bb71ba5a4afa84e673a8239935426fa0db23 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Tue, 9 Aug 2016 21:50:19 +0000 Subject: Remove incorrect tag directory git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/tags/pyparsing_2.1.6@405 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b --- trunk/src/examples/parsePythonValue.py | 70 ---------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 trunk/src/examples/parsePythonValue.py (limited to 'trunk/src/examples/parsePythonValue.py') diff --git a/trunk/src/examples/parsePythonValue.py b/trunk/src/examples/parsePythonValue.py deleted file mode 100644 index 53c61fc..0000000 --- a/trunk/src/examples/parsePythonValue.py +++ /dev/null @@ -1,70 +0,0 @@ -# parsePythonValue.py -# -# Copyright, 2006, by Paul McGuire -# -from __future__ import print_function -from pyparsing import * - - -cvtBool = lambda t:t[0]=='True' -cvtInt = lambda toks: int(toks[0]) -cvtReal = lambda toks: float(toks[0]) -cvtTuple = lambda toks : tuple(toks.asList()) -cvtDict = lambda toks: dict(toks.asList()) -cvtList = lambda toks: [toks.asList()] - -# define punctuation as suppressed literals -lparen,rparen,lbrack,rbrack,lbrace,rbrace,colon = \ - map(Suppress,"()[]{}:") - -integer = Regex(r"[+-]?\d+")\ - .setName("integer")\ - .setParseAction( cvtInt ) -real = Regex(r"[+-]?\d+\.\d*([Ee][+-]?\d+)?")\ - .setName("real")\ - .setParseAction( cvtReal ) -tupleStr = Forward() -listStr = Forward() -dictStr = Forward() - -unicodeString.setParseAction(lambda t:t[0][2:-1].decode('unicode-escape')) -quotedString.setParseAction(lambda t:t[0][1:-1].decode('string-escape')) -boolLiteral = oneOf("True False").setParseAction(cvtBool) -noneLiteral = Literal("None").setParseAction(replaceWith(None)) - -listItem = real|integer|quotedString|unicodeString|boolLiteral|noneLiteral| \ - Group(listStr) | tupleStr | dictStr - -tupleStr << ( Suppress("(") + Optional(delimitedList(listItem)) + - Optional(Suppress(",")) + Suppress(")") ) -tupleStr.setParseAction( cvtTuple ) - -listStr << (lbrack + Optional(delimitedList(listItem) + - Optional(Suppress(","))) + rbrack) -listStr.setParseAction(cvtList, lambda t: t[0]) - -dictEntry = Group( listItem + colon + listItem ) -dictStr << (lbrace + Optional(delimitedList(dictEntry) + \ - Optional(Suppress(","))) + rbrace) -dictStr.setParseAction( cvtDict ) - -tests = """['a', 100, ('A', [101,102]), 3.14, [ +2.718, 'xyzzy', -1.414] ] - [{0: [2], 1: []}, {0: [], 1: [], 2: []}, {0: [1, 2]}] - { 'A':1, 'B':2, 'C': {'a': 1.2, 'b': 3.4} } - 3.14159 - 42 - 6.02E23 - 6.02e+023 - 1.0e-7 - 'a quoted string'""".split("\n") - -for test in tests: - print("Test:", test.strip()) - result = listItem.parseString(test)[0] - print("Result:", result) - try: - for dd in result: - if isinstance(dd,dict): print(list(dd.items())) - except TypeError as te: - pass - print() -- cgit v1.2.1