eric6/Utilities/ClassBrowsers/protoclbr.py

Wed, 30 Dec 2020 11:00:05 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:05 +0100
changeset 7923
91e843545d9a
parent 7836
2f0d208b8137
child 8217
385f60c94548
permissions
-rw-r--r--

Updated copyright for 2021.

5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
3 # Copyright (c) 2017 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Parse a ProtoBuf protocol file and retrieve messages, enums, services and
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 rpc methods.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 It is based on the Python class browser found in this package.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import re
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 import Utilities
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import Utilities.ClassBrowsers as ClassBrowsers
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from . import ClbrBaseClasses
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 SUPPORTED_TYPES = [ClassBrowsers.PROTO_SOURCE]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 _getnext = re.compile(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 r"""
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 (?P<String>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 " [^"\\\n]* (?: \\. [^"\\\n]*)* "
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 | (?P<Comment>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 ^ [ \t]* // .*? $
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 |
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 ^ [ \t]* /\* .*? \*/
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 | (?P<Message>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 (?P<MessageIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 message [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 (?P<MessageName> [a-zA-Z_] [a-zA-Z0-9_]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 | (?P<Enum>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 (?P<EnumIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 enum [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 (?P<EnumName> [a-zA-Z_] [a-zA-Z0-9_]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 | (?P<Service>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 (?P<ServiceIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 service [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 (?P<ServiceName> [a-zA-Z_] [a-zA-Z0-9_]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 | (?P<Method>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 (?P<MethodIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 rpc [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 (?P<MethodName> [a-zA-Z_] [a-zA-Z0-9_]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 [ \t]*
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 \(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 (?P<MethodSignature> [^)]+? )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 \)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 returns
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 [ \t]*
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 \(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 (?P<MethodReturn> [^)]+? )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 \)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 [ \t]*
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 | (?P<Begin>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 [ \t]* {
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 | (?P<End>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 [ \t]* } [ \t]* ;?
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 )""",
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 re.VERBOSE | re.DOTALL | re.MULTILINE).search
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 # function to replace comments
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 _commentsub = re.compile(r"""//[^\n]*\n|//[^\n]*$""").sub
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 # function to normalize whitespace
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 _normalize = re.compile(r"""[ \t]{2,}""").sub
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 _modules = {} # cache of modules we've seen
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 Mixin class implementing the notion of visibility.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 def __init__(self):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.setPublic()
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 class Message(ClbrBaseClasses.Module, VisibilityMixin):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 Class to represent a ProtoBuf Message.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 def __init__(self, module, name, file, lineno):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 @param module name of the module containing this message
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @param name name of this message
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @param file filename containing this message
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 @param lineno linenumber of the message definition
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 ClbrBaseClasses.Module.__init__(self, module, name, file, lineno)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 VisibilityMixin.__init__(self)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 class Enum(ClbrBaseClasses.Enum, VisibilityMixin):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 Class to represent a ProtoBuf Enum.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 def __init__(self, module, name, file, lineno):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 @param module name of the module containing this enum
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 @param name name of this enum
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @param file filename containing this enum
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 @param lineno linenumber of the message enum
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 ClbrBaseClasses.Enum.__init__(self, module, name, file, lineno)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 VisibilityMixin.__init__(self)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 class Service(ClbrBaseClasses.Class, VisibilityMixin):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 Class to represent a ProtoBuf Service.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 def __init__(self, module, name, file, lineno):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 @param module name of the module containing this service
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 @param name name of this service
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @param file filename containing this service
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 @param lineno linenumber of the service definition
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 ClbrBaseClasses.Class.__init__(self, module, name, None, file,
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 lineno)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 VisibilityMixin.__init__(self)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 class ServiceMethod(ClbrBaseClasses.Function, VisibilityMixin):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 Class to represent a ProtoBuf Service Method.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 def __init__(self, name, file, lineno, signature, returns):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 @param name name of this service method
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 @param file filename containing this service method
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 @param lineno linenumber of the service method definition
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @param signature parameter list of the service method
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 @param returns return type of the service method
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 ClbrBaseClasses.Function.__init__(self, None, name, file, lineno,
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 signature,
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 annotation="-> {0}".format(returns))
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 VisibilityMixin.__init__(self)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 def readmodule_ex(module, path=None):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 Read a ProtoBuf protocol file and return a dictionary of messages, enums,
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 services and rpc methods.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 @param module name of the ProtoBuf protocol file
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 @param path path the file should be searched in
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 @type list of str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 @return the resulting dictionary
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 @rtype dict
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 global _modules
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 if module in _modules:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 # we've seen this file before...
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 return _modules[module]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 # search the path for the file
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 f = None
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 fullpath = [] if path is None else path[:]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 if f:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 f.close()
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 if type not in SUPPORTED_TYPES:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 # not ProtoBuf protocol source, can't do anything with this module
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
218 _modules[module] = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
219 return {}
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 try:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 src = Utilities.readEncodedFile(file)[0]
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
223 except (UnicodeError, OSError):
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 # can't do anything with this module
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
225 _modules[module] = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
226 return {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
227
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
228 _modules[module] = scan(src, file, module)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
229 return _modules[module]
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
230
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
231
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
232 def scan(src, file, module):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
233 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
234 Public method to scan the given source text.
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
235
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
236 @param src source text to be scanned
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
237 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
238 @param file file name associated with the source text
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
239 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
240 @param module module name associated with the source text
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
241 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
242 @return dictionary containing the extracted data
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
243 @rtype dict
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
244 """
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
245 def calculateEndline(lineno, lines):
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
246 """
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
247 Function to calculate the end line.
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
248
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
249 @param lineno line number to start at (one based)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
250 @type int
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
251 @param lines list of source lines
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
252 @type list of str
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
253 @return end line (one based)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
254 @rtype int
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
255 """
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
256 # convert lineno to be zero based
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
257 lineno -= 1
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
258 # 1. search for opening brace '{'
7706
0c6d32ec64f1 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7699
diff changeset
259 while lineno < len(lines) and "{" not in lines[lineno]:
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
260 lineno += 1
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
261 depth = lines[lineno].count("{") - lines[lineno].count("}")
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
262 # 2. search for ending line, i.e. matching closing brace '}'
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
263 while depth > 0 and lineno < len(lines) - 1:
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
264 lineno += 1
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
265 depth += lines[lineno].count("{") - lines[lineno].count("}")
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
266 if depth == 0:
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
267 # found a matching brace
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
268 return lineno + 1
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
269 else:
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
270 # nothing found
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
271 return -1
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
272
7676
0f67b4562d98 ClassBrowsers: added code to treat source texts like Python (universal newline).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
273 # convert eol markers the Python style
0f67b4562d98 ClassBrowsers: added code to treat source texts like Python (universal newline).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
274 src = src.replace("\r\n", "\n").replace("\r", "\n")
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
275 srcLines = src.splitlines()
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
277 dictionary = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
278
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
279 classstack = [] # stack of (class, indent) pairs
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
280 indent = 0
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
281
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 lineno, last_lineno_pos = 1, 0
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 i = 0
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 while True:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 m = _getnext(src, i)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 if not m:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 break
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 start, i = m.span()
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 if m.start("Method") >= 0:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 # found a method definition or function
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 meth_name = m.group("MethodName")
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 meth_sig = m.group("MethodSignature")
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 meth_sig = meth_sig and meth_sig.replace('\\\n', '') or ''
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 meth_sig = _commentsub('', meth_sig)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 meth_sig = _normalize(' ', meth_sig)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 meth_return = m.group("MethodReturn")
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 meth_return = meth_return and meth_return.replace('\\\n', '') or ''
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 meth_return = _commentsub('', meth_return)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 meth_return = _normalize(' ', meth_return)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 lineno = lineno + src.count('\n', last_lineno_pos, start)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 # close all interfaces/modules indented at least as much
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
305 while classstack and classstack[-1][1] >= thisindent:
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 if classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 # it's an interface/module method
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 cur_class = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 if isinstance(cur_class, Service):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 # it's a method
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 f = ServiceMethod(meth_name, file, lineno, meth_sig,
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 meth_return)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 cur_class._addmethod(meth_name, f)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 # else it's a nested def
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 f = None
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 # the file is incorrect, ignore the entry
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 continue
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
321 if f:
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
322 endline = calculateEndline(lineno, srcLines)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
323 f.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 classstack.append((f, thisindent)) # Marker for nested fns
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 elif m.start("String") >= 0:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 pass
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 elif m.start("Comment") >= 0:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 pass
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 elif m.start("Message") >= 0:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 # we found a message definition
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 indent += 1
7695
032a0586a349 protoclbr: fixed an issue caused by an unitialized variable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
336 lineno = lineno + src.count('\n', last_lineno_pos, start)
032a0586a349 protoclbr: fixed an issue caused by an unitialized variable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
337 last_lineno_pos = start
032a0586a349 protoclbr: fixed an issue caused by an unitialized variable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
338 message_name = m.group("MessageName")
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 # close all messages/services indented at least as much
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
340 while classstack and classstack[-1][1] >= thisindent:
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 # remember this message
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 cur_class = Message(module, message_name, file, lineno)
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
344 endline = calculateEndline(lineno, srcLines)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
345 cur_class.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 dictionary[message_name] = cur_class
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 msg = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 msg._addclass(message_name, cur_class)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 classstack.append((cur_class, thisindent))
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 elif m.start("Enum") >= 0:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 # we found a message definition
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 # close all messages/services indented at least as much
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
358 while classstack and classstack[-1][1] >= thisindent:
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 lineno = lineno + src.count('\n', last_lineno_pos, start)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 enum_name = m.group("EnumName")
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 # remember this Enum
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 cur_class = Enum(module, enum_name, file, lineno)
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
365 endline = calculateEndline(lineno, srcLines)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
366 cur_class.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 dictionary[enum_name] = cur_class
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 enum = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 enum._addclass(enum_name, cur_class)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 classstack.append((cur_class, thisindent))
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 elif m.start("Service") >= 0:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 # we found a message definition
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 # close all messages/services indented at least as much
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
379 while classstack and classstack[-1][1] >= thisindent:
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 lineno = lineno + src.count('\n', last_lineno_pos, start)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 service_name = m.group("ServiceName")
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 # remember this Service
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 cur_class = Service(module, service_name, file, lineno)
7699
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
386 endline = calculateEndline(lineno, srcLines)
d338c533f5f0 Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7695
diff changeset
387 cur_class.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 dictionary[service_name] = cur_class
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 service = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 service._addclass(service_name, cur_class)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 classstack.append((cur_class, thisindent))
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 elif m.start("Begin") >= 0:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 # a begin of a block we are not interested in
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 elif m.start("End") >= 0:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 # an end of a block
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 indent -= 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 return dictionary

eric ide

mercurial