eric6/Utilities/ClassBrowsers/protoclbr.py

Fri, 11 Sep 2020 17:28:59 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 11 Sep 2020 17:28:59 +0200
changeset 7699
d338c533f5f0
parent 7695
032a0586a349
child 7706
0c6d32ec64f1
permissions
-rw-r--r--

Class browsers: improved endline detection for the Python, IDL and ProtoBuf source code browsers and the Python module parser.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7259
diff changeset
3 # Copyright (c) 2017 - 2020 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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import re
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import Utilities
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 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
18 from . import ClbrBaseClasses
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 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
21
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 _getnext = re.compile(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 r"""
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 (?P<String>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 " [^"\\\n]* (?: \\. [^"\\\n]*)* "
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 | (?P<Comment>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 ^ [ \t]* // .*? $
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 |
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 ^ [ \t]* /\* .*? \*/
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 | (?P<Message>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 (?P<MessageIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 message [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 (?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
39 [ \t]* {
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 | (?P<Enum>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 (?P<EnumIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 enum [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 (?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
47 [ \t]* {
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 | (?P<Service>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 (?P<ServiceIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 service [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 (?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
55 [ \t]* {
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 | (?P<Method>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 ^
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 (?P<MethodIndent> [ \t]* )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 rpc [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 (?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
63 [ \t]*
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 \(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 (?P<MethodSignature> [^)]+? )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 \)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 [ \t]+
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 returns
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 [ \t]*
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 \(
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 (?P<MethodReturn> [^)]+? )
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 \)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 [ \t]*
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 | (?P<Begin>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 [ \t]* {
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 | (?P<End>
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 [ \t]* } [ \t]* ;?
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 )""",
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 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
84
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 # function to replace comments
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 _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
87 # function to normalize whitespace
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 _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
89
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 _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
91
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 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
96 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 def __init__(self):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.setPublic()
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 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
105 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 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
107 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 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
109 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 @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
113 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @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
115 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @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
117 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @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
119 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 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
122 VisibilityMixin.__init__(self)
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 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
126 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 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
128 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 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
130 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 @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
134 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @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
136 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 @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
138 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 @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
140 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 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
143 VisibilityMixin.__init__(self)
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 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
147 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 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
149 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 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
151 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 @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
155 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 @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
157 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 @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
159 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 @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
161 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 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
164 lineno)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 VisibilityMixin.__init__(self)
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 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
169 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 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
171 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 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
173 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 Constructor
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 @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
177 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 @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
179 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 @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
181 @type int
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 @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
183 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 @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
185 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 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
188 signature,
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 annotation="-> {0}".format(returns))
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 VisibilityMixin.__init__(self)
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
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 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
194 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 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
196 services and rpc methods.
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 @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
199 @type str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 @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
201 @type list of str
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 @return the resulting dictionary
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 @rtype dict
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 """
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 global _modules
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 if module in _modules:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 # 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
209 return _modules[module]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 # 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
212 f = None
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 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
214 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
215 if f:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 f.close()
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 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
218 # 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
219 _modules[module] = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
220 return {}
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 try:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 src = Utilities.readEncodedFile(file)[0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 except (UnicodeError, IOError):
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 # 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
226 _modules[module] = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
227 return {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
228
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
229 _modules[module] = scan(src, file, module)
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
230 return _modules[module]
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
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
233 def scan(src, file, module):
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
234 """
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
235 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
236
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
237 @param src source text to be scanned
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
238 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
239 @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
240 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
241 @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
242 @type str
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
243 @return dictionary containing the extracted data
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
244 @rtype dict
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
245 """
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
246 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
247 """
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 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
249
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 @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
251 @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
252 @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
253 @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
254 @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
255 @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
256 """
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 # 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
258 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
259 # 1. search for opening 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
260 while lineno < len(lines) and not "{" in lines[lineno]:
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 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
262 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
263 # 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
264 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
265 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
266 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
267 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
268 # 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
269 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
270 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
271 # 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
272 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
273
7676
0f67b4562d98 ClassBrowsers: added code to treat source texts like Python (universal newline).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7628
diff changeset
274 # 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
275 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
276 srcLines = src.splitlines()
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277
7690
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
278 dictionary = {}
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
279
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
280 classstack = [] # stack of (class, indent) pairs
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
281 indent = 0
a59680062837 Continued implementing the editor outline widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7685
diff changeset
282
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 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
284 i = 0
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 while True:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 m = _getnext(src, i)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 if not m:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 break
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 start, i = m.span()
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 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
292 # 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
293 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303 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
304 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 # 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
306 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
307 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 if classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 # 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
310 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
311 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
312 # it's a method
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 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
314 meth_return)
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 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
316 # 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
317 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 f = None
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 # 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
321 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
322 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
323 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
324 f.setEndLine(endline)
5977
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 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
326
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 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
328 pass
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 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
331 pass
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 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
334 # 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
335 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 indent += 1
7695
032a0586a349 protoclbr: fixed an issue caused by an unitialized variable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
337 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
338 last_lineno_pos = start
032a0586a349 protoclbr: fixed an issue caused by an unitialized variable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7690
diff changeset
339 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
340 # 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
341 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
342 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 # remember this message
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 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
345 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
346 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
347 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 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
349 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 msg = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 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
352 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
353
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 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
355 # 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
356 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 # 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
359 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
360 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 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
362 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 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
364 # remember this Enum
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 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
366 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
367 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
368 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 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
370 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 enum = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 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
373 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
374
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 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
376 # 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
377 thisindent = indent
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 # 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
380 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
381 del classstack[-1]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 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
383 last_lineno_pos = start
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 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
385 # remember this Service
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 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
387 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
388 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
389 if not classstack:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 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
391 else:
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 service = classstack[-1][0]
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 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
394 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
395
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 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
397 # 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
398 indent += 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 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
401 # 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
402 indent -= 1
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403
8a0ec75b0f73 Finished adding support for Google protobuf protocol and gRPC files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 return dictionary

eric ide

mercurial