summaryrefslogtreecommitdiff
path: root/examples/sexpParser.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sexpParser.py')
-rw-r--r--examples/sexpParser.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/examples/sexpParser.py b/examples/sexpParser.py
index 963d153..86fb089 100644
--- a/examples/sexpParser.py
+++ b/examples/sexpParser.py
@@ -5,8 +5,8 @@
#
# Updates:
# November, 2011 - fixed errors in precedence of alternatives in simpleString;
-# fixed exception raised in verifyLen to properly signal the input string
-# and exception location so that markInputline works correctly; fixed
+# fixed exception raised in verifyLen to properly signal the input string
+# and exception location so that markInputline works correctly; fixed
# definition of decimal to accept a single '0' and optional leading '-'
# sign; updated tests to improve parser coverage
#
@@ -17,7 +17,7 @@ BNF reference: http://theory.lcs.mit.edu/~rivest/sexp.txt
<sexp> :: <string> | <list>
<string> :: <display>? <simple-string> ;
-<simple-string> :: <raw> | <token> | <base-64> | <hexadecimal> |
+<simple-string> :: <raw> | <token> | <base-64> | <hexadecimal> |
<quoted-string> ;
<display> :: "[" <simple-string> "]" ;
<raw> :: <decimal> ":" <bytes> ;
@@ -27,7 +27,7 @@ BNF reference: http://theory.lcs.mit.edu/~rivest/sexp.txt
<token> :: <tokenchar>+ ;
<base-64> :: <decimal>? "|" ( <base-64-char> | <whitespace> )* "|" ;
<hexadecimal> :: "#" ( <hex-digit> | <white-space> )* "#" ;
-<quoted-string> :: <decimal>? <quoted-string-body>
+<quoted-string> :: <decimal>? <quoted-string-body>
<quoted-string-body> :: "\"" <bytes> "\""
<list> :: "(" ( <sexp> | <whitespace> )* ")" ;
<whitespace> :: <whitespace-char>* ;
@@ -65,11 +65,11 @@ hexadecimal = ("#" + OneOrMore(Word(hexnums)) + "#")\
bytes = Word(printables)
raw = Group(decimal("len") + Suppress(":") + bytes).setParseAction(verifyLen)
token = Word(alphanums + "-./_:*+=")
-base64_ = Group(Optional(decimal|hexadecimal,default=None)("len") + VBAR
+base64_ = Group(Optional(decimal|hexadecimal,default=None)("len") + VBAR
+ OneOrMore(Word( alphanums +"+/=" )).setParseAction(lambda t: b64decode("".join(t)))
+ VBAR).setParseAction(verifyLen)
-
-qString = Group(Optional(decimal,default=None)("len") +
+
+qString = Group(Optional(decimal,default=None)("len") +
dblQuotedString.setParseAction(removeQuotes)).setParseAction(verifyLen)
simpleString = base64_ | raw | decimal | token | hexadecimal | qString
@@ -86,7 +86,7 @@ string_ = Optional(display) + simpleString
sexp = Forward()
sexpList = Group(LPAR + ZeroOrMore(sexp) + RPAR)
sexp << ( string_ | sexpList )
-
+
######### Test data ###########
test00 = """(snicker "abc" (#03# |YWJj|))"""
test01 = """(certificate
@@ -142,14 +142,14 @@ test07 = """(defun factorial (x)
test51 = """(2:XX "abc" (#30# |YWJj|))"""
test51error = """(3:XX "abc" (#30# |YWJj|))"""
-test52 = """
- (and
- (or (> uid 1000)
- (!= gid 20)
- )
- (> quota 5.0e+03)
- )
- """
+test52 = """
+ (and
+ (or (> uid 1000)
+ (!= gid 20)
+ )
+ (> quota 5.0e+03)
+ )
+ """
# Run tests
t = None