summaryrefslogtreecommitdiff
path: root/src/examples/protobuf_parser.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/protobuf_parser.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/protobuf_parser.py')
-rw-r--r--src/examples/protobuf_parser.py9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/examples/protobuf_parser.py b/src/examples/protobuf_parser.py
index 8940e14..04ce0d8 100644
--- a/src/examples/protobuf_parser.py
+++ b/src/examples/protobuf_parser.py
@@ -7,7 +7,7 @@
from pyparsing import (Word, alphas, alphanums, Regex, Suppress, Forward,
Group, oneOf, ZeroOrMore, Optional, delimitedList, Keyword,
- restOfLine, quotedString)
+ restOfLine, quotedString, Dict)
ident = Word(alphas+"_",alphanums+"_").setName("identifier")
integer = Regex(r"[+-]?\d+")
@@ -31,7 +31,7 @@ fieldDefn = (( REQUIRED_ | OPTIONAL_ | REPEATED_ )("fieldQualifier") -
typespec("typespec") + ident("ident") + EQ + integer("fieldint") + ZeroOrMore(fieldDirective) + SEMI)
# enumDefn ::= 'enum' ident '{' { ident '=' integer ';' }* '}'
-enumDefn = ENUM_ - ident + LBRACE + ZeroOrMore( Group(ident + EQ + integer + SEMI) ) + RBRACE
+enumDefn = ENUM_("typespec") - ident('name') + LBRACE + Dict( ZeroOrMore( Group(ident + EQ + integer + SEMI) ))('values') + RBRACE
# extensionsDefn ::= 'extensions' integer 'to' integer ';'
extensionsDefn = EXTENSIONS_ - integer + TO_ + integer + SEMI
@@ -97,7 +97,4 @@ message AddressBook {
repeated Person person = 1;
}"""
-from pprint import pprint
-#~ print parser.parseString(test2, parseAll=True).dump()
-pprint( parser.parseString(test2, parseAll=True).asList())
-
+parser.runTests([test1, test2])