summaryrefslogtreecommitdiff
path: root/examples/protobuf_parser.py
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2020-06-27 08:26:16 -0500
committerptmcg <ptmcg@austin.rr.com>2020-06-27 08:26:16 -0500
commit20dfaac6b80ad42851d82f9d2be376e098f0a5ba (patch)
tree2cf9ef8ceee535a069a05399575ef763b2a6e066 /examples/protobuf_parser.py
parentb3edef08a38b45c3a5fe74968e3589996761660c (diff)
downloadpyparsing-git-20dfaac6b80ad42851d82f9d2be376e098f0a5ba.tar.gz
Add make_diagram.py to examples to demonstrate creating railroad diags for selected examples
Diffstat (limited to 'examples/protobuf_parser.py')
-rw-r--r--examples/protobuf_parser.py90
1 files changed, 46 insertions, 44 deletions
diff --git a/examples/protobuf_parser.py b/examples/protobuf_parser.py
index afc8296..92f5a28 100644
--- a/examples/protobuf_parser.py
+++ b/examples/protobuf_parser.py
@@ -20,6 +20,7 @@ from pyparsing import (
restOfLine,
quotedString,
Dict,
+ Keyword,
)
ident = Word(alphas + "_", alphanums + "_").setName("identifier")
@@ -123,47 +124,48 @@ parser = Optional(packageDirective) + ZeroOrMore(topLevelStatement)
parser.ignore(comment)
-
-test1 = """message Person {
- required int32 id = 1;
- required string name = 2;
- optional string email = 3;
-}"""
-
-test2 = """package tutorial;
-
-message Person {
- required string name = 1;
- required int32 id = 2;
- optional string email = 3;
-
- enum PhoneType {
- MOBILE = 0;
- HOME = 1;
- WORK = 2;
- }
-
- message PhoneNumber {
- required string number = 1;
- optional PhoneType type = 2 [default = HOME];
- }
-
- repeated PhoneNumber phone = 4;
-}
-
-message AddressBook {
- repeated Person person = 1;
-}"""
-
-test3 = """syntax = "proto3";
-
-import "test.proto";
-
-message SearchRequest {
- string query = 1;
- int32 page_number = 2;
- int32 result_per_page = 3;
-}
-"""
-
-parser.runTests([test1, test2, test3])
+if __name__ == "__main__":
+
+ test1 = """message Person {
+ required int32 id = 1;
+ required string name = 2;
+ optional string email = 3;
+ }"""
+
+ test2 = """package tutorial;
+
+ message Person {
+ required string name = 1;
+ required int32 id = 2;
+ optional string email = 3;
+
+ enum PhoneType {
+ MOBILE = 0;
+ HOME = 1;
+ WORK = 2;
+ }
+
+ message PhoneNumber {
+ required string number = 1;
+ optional PhoneType type = 2 [default = HOME];
+ }
+
+ repeated PhoneNumber phone = 4;
+ }
+
+ message AddressBook {
+ repeated Person person = 1;
+ }"""
+
+ test3 = """syntax = "proto3";
+
+ import "test.proto";
+
+ message SearchRequest {
+ string query = 1;
+ int32 page_number = 2;
+ int32 result_per_page = 3;
+ }
+ """
+
+ parser.runTests([test1, test2, test3])