idl-parser 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- idl_parser/__init__.py +7 -0
- idl_parser/const.py +50 -0
- idl_parser/enum.py +114 -0
- idl_parser/exception.py +37 -0
- idl_parser/interface.py +226 -0
- idl_parser/module.py +314 -0
- idl_parser/node.py +123 -0
- idl_parser/parser.py +356 -0
- idl_parser/struct.py +155 -0
- idl_parser/token_buffer.py +25 -0
- idl_parser/type.py +283 -0
- idl_parser/typedef.py +84 -0
- idl_parser/union.py +188 -0
- idl_parser-0.1.0.dist-info/METADATA +110 -0
- idl_parser-0.1.0.dist-info/RECORD +17 -0
- idl_parser-0.1.0.dist-info/WHEEL +5 -0
- idl_parser-0.1.0.dist-info/top_level.txt +1 -0
idl_parser/__init__.py
ADDED
idl_parser/const.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import os, sys, traceback
|
|
2
|
+
|
|
3
|
+
from . import node
|
|
4
|
+
sep = '::'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class IDLConst(node.IDLNode):
|
|
8
|
+
|
|
9
|
+
def __init__(self, name, typename, value, parent, filepath=None):
|
|
10
|
+
super(IDLConst, self).__init__('IDLConst', name, parent)
|
|
11
|
+
self._typename = typename
|
|
12
|
+
self._verbose = True
|
|
13
|
+
self._value = value
|
|
14
|
+
self._filepath= filepath
|
|
15
|
+
|
|
16
|
+
def to_simple_dic(self, quiet=False, full_path=False, recursive=False, member_only=False):
|
|
17
|
+
name = self.full_path if full_path else self.name
|
|
18
|
+
if quiet:
|
|
19
|
+
return 'const %s %s = %s' % (self.typename, name, self.value)
|
|
20
|
+
dic = { 'const %s' % name : { 'type' : self.typename,
|
|
21
|
+
'value' : self.value } }
|
|
22
|
+
return dic
|
|
23
|
+
|
|
24
|
+
def to_dic(self):
|
|
25
|
+
dic = { 'name' : self.name,
|
|
26
|
+
'filepath' : self.filepath,
|
|
27
|
+
'classname' : self.classname,
|
|
28
|
+
'typename' : self.typename,
|
|
29
|
+
'value' : self.value }
|
|
30
|
+
return dic
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def typename(self):
|
|
34
|
+
return self._typename
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def type(self):
|
|
38
|
+
return self.root_node.find_types(self.typename)[0]
|
|
39
|
+
@property
|
|
40
|
+
def value(self):
|
|
41
|
+
return self._value
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def value_string(self):
|
|
45
|
+
return self._value
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def full_path(self):
|
|
49
|
+
return self.parent.full_path + sep + self.name
|
|
50
|
+
|
idl_parser/enum.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import os, sys, traceback
|
|
2
|
+
|
|
3
|
+
from . import node
|
|
4
|
+
sep = '::'
|
|
5
|
+
|
|
6
|
+
class IDLEnumValue(node.IDLNode):
|
|
7
|
+
def __init__(self, value, parent):
|
|
8
|
+
super(IDLEnumValue, self).__init__('IDLEnumValue', '', parent)
|
|
9
|
+
self._verbose = True
|
|
10
|
+
self._value = value
|
|
11
|
+
|
|
12
|
+
def parse_blocks(self, blocks, filepath=None):
|
|
13
|
+
self._filepath = filepath
|
|
14
|
+
if len(blocks) == 1:
|
|
15
|
+
self._name = blocks[0]
|
|
16
|
+
else:
|
|
17
|
+
sys.stdout.write('Unkown Enum format %s\n' % blocks)
|
|
18
|
+
#name, type = self._name_and_type(blocks)
|
|
19
|
+
#self._name = name
|
|
20
|
+
#self._type = type
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def full_path(self):
|
|
24
|
+
return self.full_path + '.' + self.name
|
|
25
|
+
|
|
26
|
+
def to_simple_dic(self):
|
|
27
|
+
dic = {self.name : self.value }
|
|
28
|
+
return dic
|
|
29
|
+
|
|
30
|
+
def to_dic(self):
|
|
31
|
+
dic = { 'name' : self.name,
|
|
32
|
+
'filepath' : self.filepath,
|
|
33
|
+
'classname' : self.classname,
|
|
34
|
+
'value' : self.value }
|
|
35
|
+
return dic
|
|
36
|
+
@property
|
|
37
|
+
def value(self):
|
|
38
|
+
return self._value
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class IDLEnum(node.IDLNode):
|
|
44
|
+
|
|
45
|
+
def __init__(self, name, parent):
|
|
46
|
+
super(IDLEnum, self).__init__('IDLEnum', name, parent)
|
|
47
|
+
self._verbose = True
|
|
48
|
+
self._values = []
|
|
49
|
+
|
|
50
|
+
def to_simple_dic(self, quiet=False, full_path=False, recursive=False, member_only=False):
|
|
51
|
+
name = self.full_path if full_path else self.name
|
|
52
|
+
if quiet:
|
|
53
|
+
return 'enum %s' % name
|
|
54
|
+
dic = { 'enum %s' % name : [v.to_simple_dic() for v in self.values] }
|
|
55
|
+
return dic
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def to_dic(self):
|
|
59
|
+
dic = { 'name' : self.name,
|
|
60
|
+
'classname' : self.classname,
|
|
61
|
+
'values' : [v.to_dic() for v in self.values] }
|
|
62
|
+
return dic
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def full_path(self):
|
|
66
|
+
return self.parent.full_path + sep + self.name
|
|
67
|
+
|
|
68
|
+
def parse_tokens(self, token_buf, filepath=None):
|
|
69
|
+
self._filepath = filepath
|
|
70
|
+
self._counter = 0
|
|
71
|
+
ln, fn, kakko = token_buf.pop()
|
|
72
|
+
if not kakko == '{':
|
|
73
|
+
if self._verbose: sys.stdout.write('# Error. No kakko "{".\n')
|
|
74
|
+
raise InvalidIDLSyntaxError()
|
|
75
|
+
|
|
76
|
+
block_tokens = []
|
|
77
|
+
while True:
|
|
78
|
+
ln, fn, token = token_buf.pop()
|
|
79
|
+
if token == None:
|
|
80
|
+
if self._verbose: sys.stdout.write('# Error. No kokka "}".\n')
|
|
81
|
+
raise InvalidIDLSyntaxError()
|
|
82
|
+
|
|
83
|
+
elif token == '}':
|
|
84
|
+
ln, fn, token = token_buf.pop()
|
|
85
|
+
if not token == ';':
|
|
86
|
+
if self._verbose: sys.stdout.write('# Error. No semi-colon after "}".\n')
|
|
87
|
+
raise InvalidIDLSyntaxError()
|
|
88
|
+
|
|
89
|
+
if len(block_tokens) > 0:
|
|
90
|
+
self._parse_block(block_tokens)
|
|
91
|
+
break
|
|
92
|
+
|
|
93
|
+
if token == ',':
|
|
94
|
+
self._parse_block(block_tokens)
|
|
95
|
+
block_tokens = []
|
|
96
|
+
continue
|
|
97
|
+
block_tokens.append(token)
|
|
98
|
+
|
|
99
|
+
def _parse_block(self, blocks):
|
|
100
|
+
v = IDLEnumValue(self._counter, self)
|
|
101
|
+
self._counter = self._counter+ 1
|
|
102
|
+
v.parse_blocks(blocks, self.filepath)
|
|
103
|
+
self._values.append(v)
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def values(self):
|
|
107
|
+
return self._values
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def value_by_name(self, name):
|
|
111
|
+
for m in self.values:
|
|
112
|
+
if m.name == name:
|
|
113
|
+
return m
|
|
114
|
+
return None
|
idl_parser/exception.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class IDLParserException(Exception):
|
|
5
|
+
|
|
6
|
+
def __init__(self, line_number=None, file_name=None, message='IDLParserException occurred.'):
|
|
7
|
+
self._className = 'IDLParserException'
|
|
8
|
+
self._line_number = line_number
|
|
9
|
+
self._file_name = file_name
|
|
10
|
+
self._message = message
|
|
11
|
+
|
|
12
|
+
@property
|
|
13
|
+
def message(self):
|
|
14
|
+
return 'File "' + self.file_name + '", line %s, ' % self.line_number + '(' + self._className + '):"' + self._message
|
|
15
|
+
|
|
16
|
+
@property
|
|
17
|
+
def line_number(self):
|
|
18
|
+
return self._line_number
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def file_name(self):
|
|
22
|
+
return self._file_name
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class InvalidIDLSyntaxError(IDLParserException):
|
|
27
|
+
|
|
28
|
+
def __init__(self, line_number=None, file_name=None, message='IDLParserException occurred.'):
|
|
29
|
+
super(InvalidIDLSyntaxError, self).__init__(line_number, file_name, message)
|
|
30
|
+
self._className = 'InvalidIDLSyntaxError'
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
class InvalidDataTypeException(IDLParserException):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
class IDLCanNotFindException(IDLParserException):
|
|
37
|
+
pass
|
idl_parser/interface.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from . import node
|
|
3
|
+
|
|
4
|
+
from . import type as idl_type
|
|
5
|
+
|
|
6
|
+
sep = '::'
|
|
7
|
+
|
|
8
|
+
class IDLArgument(node.IDLNode):
|
|
9
|
+
def __init__(self, parent):
|
|
10
|
+
super(IDLArgument, self).__init__('IDLArgument', '', parent)
|
|
11
|
+
self._verbose = True
|
|
12
|
+
self._dir = 'in'
|
|
13
|
+
self._type = None
|
|
14
|
+
|
|
15
|
+
def parse_blocks(self, blocks, filepath=None):
|
|
16
|
+
self._filepath= filepath
|
|
17
|
+
directions = ['in', 'out', 'inout']
|
|
18
|
+
self._dir = 'in'
|
|
19
|
+
if blocks[0] in directions:
|
|
20
|
+
self._dir = blocks[0]
|
|
21
|
+
blocks.pop(0)
|
|
22
|
+
pass
|
|
23
|
+
argument_name, argument_type = self._name_and_type(blocks)
|
|
24
|
+
self._name = argument_name
|
|
25
|
+
self._type = idl_type.IDLType(argument_type, self)
|
|
26
|
+
|
|
27
|
+
def to_simple_dic(self):
|
|
28
|
+
dic = '%s %s %s' % (self.direction, self.type, self.name)
|
|
29
|
+
return dic
|
|
30
|
+
|
|
31
|
+
def to_dic(self):
|
|
32
|
+
dic = { 'name' : self.name,
|
|
33
|
+
'classname' : self.classname,
|
|
34
|
+
'type' : str(self.type),
|
|
35
|
+
'direction' : self.direction,
|
|
36
|
+
'filepath' : self.filepath }
|
|
37
|
+
return dic
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def direction(self):
|
|
41
|
+
return self._dir
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def type(self):
|
|
45
|
+
return self._type
|
|
46
|
+
|
|
47
|
+
def post_process(self):
|
|
48
|
+
self._type._name = self.refine_typename(self.type)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class IDLMethod(node.IDLNode):
|
|
53
|
+
def __init__(self, parent):
|
|
54
|
+
super(IDLMethod, self).__init__('IDLValue', '', parent)
|
|
55
|
+
self._verbose = True
|
|
56
|
+
self._returns = None
|
|
57
|
+
self._arguments = []
|
|
58
|
+
|
|
59
|
+
def parse_blocks(self, blocks, filepath=None):
|
|
60
|
+
self._filepath=filepath
|
|
61
|
+
|
|
62
|
+
if blocks[0] == 'oneway':
|
|
63
|
+
self._oneway = True
|
|
64
|
+
blocks.pop(0)
|
|
65
|
+
else:
|
|
66
|
+
self._oneway = False
|
|
67
|
+
|
|
68
|
+
self._returns = idl_type.IDLType(blocks[0], self)
|
|
69
|
+
self._name = blocks[1]
|
|
70
|
+
self._arguments = []
|
|
71
|
+
|
|
72
|
+
if not blocks[2] == '(':
|
|
73
|
+
print(' -- Invalid Interface Token (%s)' % blocks[1])
|
|
74
|
+
print( blocks)
|
|
75
|
+
|
|
76
|
+
index = 3
|
|
77
|
+
argument_blocks = []
|
|
78
|
+
while True:
|
|
79
|
+
if index == len(blocks):
|
|
80
|
+
break
|
|
81
|
+
token = blocks[index]
|
|
82
|
+
if token == ',' or token == ')':
|
|
83
|
+
if len(argument_blocks) == 0:
|
|
84
|
+
break
|
|
85
|
+
|
|
86
|
+
a = IDLArgument(self)
|
|
87
|
+
self._arguments.append(a)
|
|
88
|
+
a.parse_blocks(argument_blocks, self.filepath)
|
|
89
|
+
|
|
90
|
+
argument_blocks = []
|
|
91
|
+
else:
|
|
92
|
+
argument_blocks.append(token)
|
|
93
|
+
index = index + 1
|
|
94
|
+
|
|
95
|
+
def to_simple_dic(self):
|
|
96
|
+
return {self.name : {
|
|
97
|
+
'returns' : str(self.returns),
|
|
98
|
+
'params' : [a.to_simple_dic() for a in self.arguments]}}
|
|
99
|
+
|
|
100
|
+
def to_dic(self):
|
|
101
|
+
dic = { 'name' : self.name,
|
|
102
|
+
'filepath' : self.filepath,
|
|
103
|
+
'classname' : self.classname,
|
|
104
|
+
'returns' : str(self._returns),
|
|
105
|
+
'arguments' : [a.to_dic() for a in self.arguments]}
|
|
106
|
+
return dic
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def returns(self):
|
|
110
|
+
return self._returns
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def arguments(self):
|
|
114
|
+
return self._arguments
|
|
115
|
+
|
|
116
|
+
def argument_by_name(self, name):
|
|
117
|
+
for a in self.arguments:
|
|
118
|
+
if a.name == name:
|
|
119
|
+
return a
|
|
120
|
+
|
|
121
|
+
return None
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def forEachArgument(self, func):
|
|
125
|
+
for a in self.arguments:
|
|
126
|
+
func(a)
|
|
127
|
+
|
|
128
|
+
def post_process(self):
|
|
129
|
+
#self._returns = self.refine_typename(self.returns)
|
|
130
|
+
#self.forEachArgument(lambda a : a.post_process())
|
|
131
|
+
pass
|
|
132
|
+
|
|
133
|
+
class IDLInterface(node.IDLNode):
|
|
134
|
+
|
|
135
|
+
def __init__(self, name, parent):
|
|
136
|
+
super(IDLInterface, self).__init__('IDLInterface', name, parent)
|
|
137
|
+
self._verbose = True
|
|
138
|
+
self._methods = []
|
|
139
|
+
self._inheritances = []
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def inheritances(self):
|
|
143
|
+
return [self.root_node.find_types(inheritance)[0] for inheritance in self._inheritances]
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def full_path(self):
|
|
147
|
+
return self.parent.full_path + sep + self.name
|
|
148
|
+
|
|
149
|
+
def to_simple_dic(self, quiet=False, full_path=False, recursive=False, member_only=False):
|
|
150
|
+
if quiet:
|
|
151
|
+
return 'interface %s' % self.name
|
|
152
|
+
dic = { 'interface ' + self.name : [m.to_simple_dic() for m in self.methods] }
|
|
153
|
+
return dic
|
|
154
|
+
|
|
155
|
+
def to_dic(self):
|
|
156
|
+
dic = { 'name' : self.name,
|
|
157
|
+
'filepath' : self.filepath,
|
|
158
|
+
'classname' : self.classname,
|
|
159
|
+
'methods' : [m.to_dic() for m in self.methods] }
|
|
160
|
+
return dic
|
|
161
|
+
|
|
162
|
+
def parse_tokens(self, token_buf, filepath=None):
|
|
163
|
+
self._filepath=filepath
|
|
164
|
+
ln, fn, token = token_buf.pop()
|
|
165
|
+
if token == ':': # Detect Inheritance
|
|
166
|
+
ln, fn, name = token_buf.pop()
|
|
167
|
+
interfaces = self.root_node.find_types(name)
|
|
168
|
+
if len(interfaces) == 0:
|
|
169
|
+
if self._verbose: sys.stdout.write('# Error. Can not find "%s" interface which is generalization of "%s"\n' % (name, self.name))
|
|
170
|
+
raise exception.InvalidDataTypeException
|
|
171
|
+
elif len(interfaces) > 1:
|
|
172
|
+
if self._verbose: sys.stdout.write('# Error. Multiple "%s" interfaces (one is generalization of "%s"). \n' % (name, self.name))
|
|
173
|
+
raise exception.InvalidDataTypeException
|
|
174
|
+
self._inheritances.append(interfaces[0].full_path)
|
|
175
|
+
ln, fn, token = token_buf.pop()
|
|
176
|
+
|
|
177
|
+
kakko = token
|
|
178
|
+
if not kakko == '{':
|
|
179
|
+
if self._verbose: sys.stdout.write('# Error. No kakko "{".\n')
|
|
180
|
+
raise exception.InvalidIDLSyntaxError()
|
|
181
|
+
|
|
182
|
+
block_tokens = []
|
|
183
|
+
while True:
|
|
184
|
+
|
|
185
|
+
ln, fn, token = token_buf.pop()
|
|
186
|
+
if token == None:
|
|
187
|
+
if self._verbose: sys.stdout.write('# Error. No kokka "}".\n')
|
|
188
|
+
raise InvalidIDLSyntaxError()
|
|
189
|
+
|
|
190
|
+
elif token == '}':
|
|
191
|
+
ln, fn, token = token_buf.pop()
|
|
192
|
+
if not token == ';':
|
|
193
|
+
if self._verbose: sys.stdout.write('# Error. No semi-colon after "}".\n')
|
|
194
|
+
raise InvalidIDLSyntaxError()
|
|
195
|
+
break
|
|
196
|
+
|
|
197
|
+
if token == ';':
|
|
198
|
+
self._parse_block(block_tokens)
|
|
199
|
+
block_tokens = []
|
|
200
|
+
continue
|
|
201
|
+
block_tokens.append(token)
|
|
202
|
+
self._post_process()
|
|
203
|
+
|
|
204
|
+
def _post_process(self):
|
|
205
|
+
self.forEachMethod(lambda m : m.post_process())
|
|
206
|
+
|
|
207
|
+
def _parse_block(self, blocks):
|
|
208
|
+
v = IDLMethod(self)
|
|
209
|
+
v.parse_blocks(blocks, self.filepath)
|
|
210
|
+
self._methods.append(v)
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def methods(self):
|
|
214
|
+
return self._methods
|
|
215
|
+
|
|
216
|
+
def method_by_name(self, name):
|
|
217
|
+
for m in self.methods:
|
|
218
|
+
if name == m.name:
|
|
219
|
+
return m
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
def forEachMethod(self, func):
|
|
223
|
+
for m in self.methods:
|
|
224
|
+
func(m)
|
|
225
|
+
|
|
226
|
+
|