idl-parser 0.3.2__tar.gz → 0.4.0__tar.gz

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.
Files changed (138) hide show
  1. {idl_parser-0.3.2/idl_parser.egg-info → idl_parser-0.4.0}/PKG-INFO +1 -1
  2. {idl_parser-0.3.2 → idl_parser-0.4.0}/docs/api/index.rst +2 -0
  3. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/bitset.py +4 -8
  4. idl_parser-0.4.0/idl_parser/definitions.py +416 -0
  5. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/exception.py +9 -9
  6. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/interface.py +228 -5
  7. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/module.py +100 -332
  8. idl_parser-0.4.0/idl_parser/native.py +42 -0
  9. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/node.py +20 -10
  10. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/parser.py +6 -3
  11. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/struct.py +52 -1
  12. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/type.py +14 -3
  13. {idl_parser-0.3.2 → idl_parser-0.4.0/idl_parser.egg-info}/PKG-INFO +1 -1
  14. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser.egg-info/SOURCES.txt +7 -0
  15. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser.egg-info/scm_file_list.json +7 -0
  16. idl_parser-0.4.0/idl_parser.egg-info/scm_version.json +8 -0
  17. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/README.md +3 -3
  18. idl_parser-0.4.0/tests/interface/interface_body_test.py +188 -0
  19. idl_parser-0.4.0/tests/interface/local_abstract_test.py +109 -0
  20. idl_parser-0.4.0/tests/primitive_const/native_test.py +134 -0
  21. idl_parser-0.4.0/tests/scope/pathname_test.py +39 -0
  22. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/unknown_word_test.py +52 -63
  23. idl_parser-0.4.0/tests/struct_enum_union/exception_test.py +178 -0
  24. idl_parser-0.3.2/idl_parser.egg-info/scm_version.json +0 -8
  25. {idl_parser-0.3.2 → idl_parser-0.4.0}/.github/workflows/release.yml +0 -0
  26. {idl_parser-0.3.2 → idl_parser-0.4.0}/.github/workflows/test.yml +0 -0
  27. {idl_parser-0.3.2 → idl_parser-0.4.0}/.gitignore +0 -0
  28. {idl_parser-0.3.2 → idl_parser-0.4.0}/.readthedocs.yaml +0 -0
  29. {idl_parser-0.3.2 → idl_parser-0.4.0}/.vscode/extensions.json +0 -0
  30. {idl_parser-0.3.2 → idl_parser-0.4.0}/.vscode/launch.json +0 -0
  31. {idl_parser-0.3.2 → idl_parser-0.4.0}/.vscode/settings.json +0 -0
  32. {idl_parser-0.3.2 → idl_parser-0.4.0}/LICENSE +0 -0
  33. {idl_parser-0.3.2 → idl_parser-0.4.0}/README.md +0 -0
  34. {idl_parser-0.3.2 → idl_parser-0.4.0}/README.rst +0 -0
  35. {idl_parser-0.3.2 → idl_parser-0.4.0}/docs/conf.py +0 -0
  36. {idl_parser-0.3.2 → idl_parser-0.4.0}/docs/index.rst +0 -0
  37. {idl_parser-0.3.2 → idl_parser-0.4.0}/docs/requirements.txt +0 -0
  38. {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/_path.py +0 -0
  39. {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/annotation_example.py +0 -0
  40. {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/argument_direction_example.py +0 -0
  41. {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/enum_example.py +0 -0
  42. {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/example.py +0 -0
  43. {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/scoped_name_example.py +0 -0
  44. {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/struct_example.py +0 -0
  45. {idl_parser-0.3.2 → idl_parser-0.4.0}/examples/union_example.py +0 -0
  46. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/__init__.py +0 -0
  47. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/bitmask.py +0 -0
  48. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/const.py +0 -0
  49. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/enum.py +0 -0
  50. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/pragma.py +0 -0
  51. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/token_buffer.py +0 -0
  52. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/typedef.py +0 -0
  53. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser/union.py +0 -0
  54. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser.egg-info/dependency_links.txt +0 -0
  55. {idl_parser-0.3.2 → idl_parser-0.4.0}/idl_parser.egg-info/top_level.txt +0 -0
  56. {idl_parser-0.3.2 → idl_parser-0.4.0}/pyproject.toml +0 -0
  57. {idl_parser-0.3.2 → idl_parser-0.4.0}/setup.cfg +0 -0
  58. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/__init__.py +0 -0
  59. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/annotation/__init__.py +0 -0
  60. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/annotation/annotation_test.py +0 -0
  61. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/annotation/bit_bound_scope_test.py +0 -0
  62. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/annotation/string_argument_test.py +0 -0
  63. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/bitmask_bitset/__init__.py +0 -0
  64. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/bitmask_bitset/bitmask_bitset_test.py +0 -0
  65. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/examples/__init__.py +0 -0
  66. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/examples/examples_test.py +0 -0
  67. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/forward_declaration/__init__.py +0 -0
  68. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/forward_declaration/element_type_forward_test.py +0 -0
  69. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/forward_declaration/interface_forward_test.py +0 -0
  70. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/forward_declaration/struct_union_forward_test.py +0 -0
  71. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/basic_module_test.idl +0 -0
  72. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/circular/circular_a.idl +0 -0
  73. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/circular/circular_b.idl +0 -0
  74. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/circular/diamond.idl +0 -0
  75. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/forward_declaration.idl +0 -0
  76. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/generalization.idl +0 -0
  77. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/generalization_extended.idl +0 -0
  78. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/included_idl.idl +0 -0
  79. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/including_idl.idl +0 -0
  80. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/invalid_idl.idl +0 -0
  81. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue12_subpath/relative_include.idl +0 -0
  82. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue12_subpath/sensor_msgs/msg/Imu.idl +0 -0
  83. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue12_subpath/std/msg/Header.idl +0 -0
  84. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue18_idl42_int_types.idl +0 -0
  85. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue28_pragma_keylist.idl +0 -0
  86. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue9_const_pragma.idl +0 -0
  87. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue9_tabs_bounded_string.idl +0 -0
  88. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/issue9_whitespace_variants.idl +0 -0
  89. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/idls/multi_module_test.idl +0 -0
  90. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/include/__init__.py +0 -0
  91. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/include/circular_include_test.py +0 -0
  92. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/include/include_dirs_test.py +0 -0
  93. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/include/subpath_include_test.py +0 -0
  94. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/__init__.py +0 -0
  95. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/argument_direction_test.py +0 -0
  96. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/basic_module_test.py +0 -0
  97. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/inheritance_test.py +0 -0
  98. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/interface/raises_context_test.py +0 -0
  99. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/__init__.py +0 -0
  100. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/basic_module_test.py +0 -0
  101. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/bracket_spacing_test.py +0 -0
  102. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/error_line_number_test.py +0 -0
  103. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/exception_message_test.py +0 -0
  104. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/opensplice_idl_test.py +0 -0
  105. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/string_literal_comment_test.py +0 -0
  106. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/lexing/token_split_test.py +0 -0
  107. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/__init__.py +0 -0
  108. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/constructor_python_test.py +0 -0
  109. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/simple_dic_enum_test.py +0 -0
  110. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/simple_dic_inherits_test.py +0 -0
  111. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/simple_dic_member_only_test.py +0 -0
  112. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/output/simple_dic_member_type_test.py +0 -0
  113. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/pragma_key/__init__.py +0 -0
  114. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/pragma_key/key_annotation_test.py +0 -0
  115. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/pragma_key/keylist_validation_test.py +0 -0
  116. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/pragma_key/pragma_test.py +0 -0
  117. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/primitive_const/__init__.py +0 -0
  118. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/primitive_const/basic_module_test.py +0 -0
  119. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/primitive_const/const_test.py +0 -0
  120. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/primitive_const/int_types_test.py +0 -0
  121. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/__init__.py +0 -0
  122. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/basename_test.py +0 -0
  123. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/basic_module_test.py +0 -0
  124. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/leading_scope_test.py +0 -0
  125. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/multi_module_test.py +0 -0
  126. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/same_name_resolution_test.py +0 -0
  127. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/scope/unsupported_block_scope_test.py +0 -0
  128. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/__init__.py +0 -0
  129. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/basic_module_test.py +0 -0
  130. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/element_type_test.py +0 -0
  131. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/nested_bounded_sequence_test.py +0 -0
  132. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/sequence_array/syntax_error_test.py +0 -0
  133. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/__init__.py +0 -0
  134. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/basic_module_test.py +0 -0
  135. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/syntax_error_test.py +0 -0
  136. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/union_char_label_test.py +0 -0
  137. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/struct_enum_union/union_default_label_test.py +0 -0
  138. {idl_parser-0.3.2 → idl_parser-0.4.0}/tests/support.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: idl_parser
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Summary: Very simple OMG IDL (Interface Definition Language) parser. This parses IDL files and outputs intermediate class objects.
5
5
  Author-email: ysuga <ysuga@ysuga.net>
6
6
  License-Expression: GPL-3.0-or-later
@@ -15,6 +15,8 @@ API Reference
15
15
  idl_parser.union
16
16
  idl_parser.typedef
17
17
  idl_parser.const
18
+ idl_parser.native
19
+ idl_parser.definitions
18
20
  idl_parser.pragma
19
21
  idl_parser.type
20
22
  idl_parser.node
@@ -245,13 +245,11 @@ class IDLBitset(node.IDLNode):
245
245
  return candidates
246
246
 
247
247
  def _find_base(self, name, ln, fn):
248
+ from .module import definition_scopes
248
249
  bitsets = {}
249
- def collect(m):
250
+ for m in definition_scopes(self.root_node, self):
250
251
  for b in m.bitsets:
251
252
  bitsets[b.full_path.lstrip(':')] = b
252
- for sub in m.modules:
253
- collect(sub)
254
- collect(self.root_node)
255
253
  for c in self._scopes(name):
256
254
  if c in bitsets:
257
255
  return bitsets[c]
@@ -259,13 +257,11 @@ class IDLBitset(node.IDLNode):
259
257
  ln, fn, 'Can not find "%s" bitset which is the base of "%s"' % (name, self.name))
260
258
 
261
259
  def _find_const(self, name):
260
+ from .module import definition_scopes
262
261
  consts = {}
263
- def collect(m):
262
+ for m in definition_scopes(self.root_node, self):
264
263
  for c in m.consts:
265
264
  consts[(m.full_path.lstrip(':') + sep + c.name).lstrip(':')] = c
266
- for sub in m.modules:
267
- collect(sub)
268
- collect(self.root_node)
269
265
  for c in self._scopes(name):
270
266
  if c in consts:
271
267
  return consts[c]
@@ -0,0 +1,416 @@
1
+ """Type and constant definitions shared by modules and interfaces.
2
+
3
+ A ``module`` and an ``interface`` can both hold ``struct``, ``union``,
4
+ ``enum``, ``typedef``, ``const``, ``exception``, ``native``, ``bitmask`` and
5
+ ``bitset`` definitions (issue #101). :class:`IDLDefinitionScope` keeps them
6
+ and parses them for both.
7
+ """
8
+ import sys
9
+
10
+ from . import node
11
+ from . import struct, typedef, enum, const, union, bitmask, bitset, native
12
+ from .exception import InvalidIDLSyntaxError
13
+
14
+ # Keywords that start a definition handled by IDLDefinitionScope.parse_definition().
15
+ definition_keywords = ('typedef', 'struct', 'exception', 'enum', 'bitmask',
16
+ 'bitset', 'union', 'native', 'const')
17
+
18
+
19
+ class IDLDefinitionScope(object):
20
+ """Mixin for a scope that holds type and constant definitions.
21
+
22
+ Used by :class:`~idl_parser.module.IDLModule` and
23
+ :class:`~idl_parser.interface.IDLInterface`.
24
+ """
25
+
26
+ def _init_definitions(self):
27
+ self._typedefs = []
28
+ self._structs = []
29
+ self._forward_structs = []
30
+ self._exceptions = []
31
+ self._enums = []
32
+ self._bitmasks = []
33
+ self._bitsets = []
34
+ self._unions = []
35
+ self._forward_unions = []
36
+ self._consts = []
37
+ self._natives = []
38
+
39
+ def parse_definition(self, token, token_buf, filepath=None, annotations=()):
40
+ """Parse a definition whose keyword ``token`` is already consumed.
41
+
42
+ :param token: The keyword (one of :data:`definition_keywords`).
43
+ :param token_buf: :class:`~idl_parser.token_buffer.TokenBuffer` to read from.
44
+ :param filepath: File name recorded in the parsed nodes.
45
+ :param annotations: Annotations written before the keyword.
46
+ :return: False if ``token`` does not start a definition (nothing is read).
47
+ :raises ~idl_parser.exception.InvalidIDLSyntaxError: The definition is
48
+ not valid IDL.
49
+ """
50
+ pending_annotations = list(annotations)
51
+ if token == 'typedef':
52
+ blocks = []
53
+ while True:
54
+ ln, fn, t = token_buf.pop()
55
+ if t == None:
56
+ raise InvalidIDLSyntaxError()
57
+ elif t == ';':
58
+ break
59
+ else:
60
+ blocks.append(t)
61
+ t = typedef.IDLTypedef(self)
62
+ anns, blocks = node.parse_annotations(blocks)
63
+ t._add_annotations(pending_annotations + anns)
64
+ t.parse_blocks(blocks, filepath=filepath)
65
+ t_ = self.typedef_by_name(t.name)
66
+ if t_:
67
+ if self._verbose: sys.stdout.write('# Error. Same Typedef Defined (%s)\n' % t.name)
68
+ else:
69
+ self._typedefs.append(t)
70
+
71
+ elif token == 'struct':
72
+ ln, fn, name_ = token_buf.pop()
73
+ s_ = self.struct_by_name(name_)
74
+ s = struct.IDLStruct(name_, self)
75
+ s._add_annotations(pending_annotations)
76
+ s.parse_tokens(token_buf, filepath=filepath)
77
+ if s.is_forward:
78
+ # Forward declaration ("struct A;"): remember the name only.
79
+ # The definition, if any, is added to structs when it appears.
80
+ if name_ not in self._forward_structs:
81
+ self._forward_structs.append(name_)
82
+ elif s_:
83
+ if self._verbose: sys.stdout.write('# Error. Same Struct Defined (%s)\n' % name_)
84
+ # raise InvalidIDLSyntaxError
85
+ else:
86
+ self._structs.append(s)
87
+
88
+ elif token == 'exception':
89
+ ln, fn, name_ = token_buf.pop()
90
+ s = struct.IDLException(name_, self)
91
+ s._add_annotations(pending_annotations)
92
+ s.parse_tokens(token_buf, filepath=filepath)
93
+ if self.exception_by_name(name_):
94
+ if self._verbose: sys.stdout.write('# Error. Same Exception Defined (%s)\n' % name_)
95
+ else:
96
+ self._exceptions.append(s)
97
+
98
+ elif token == 'enum':
99
+ ln, fn, name_ = token_buf.pop()
100
+ s = enum.IDLEnum(name_, self)
101
+ s._add_annotations(pending_annotations)
102
+ s.parse_tokens(token_buf, filepath)
103
+ s_ = self.enum_by_name(name_)
104
+ if s_:
105
+ if self._verbose: sys.stdout.write('# Error. Same Enum Defined (%s)\n' % name_)
106
+ # raise InvalidIDLSyntaxError
107
+ else:
108
+ self._enums.append(s)
109
+
110
+ elif token == 'bitmask':
111
+ ln, fn, name_ = token_buf.pop()
112
+ s = bitmask.IDLBitmask(name_, self, pending_annotations)
113
+ s.parse_tokens(token_buf, filepath)
114
+ if self.bitmask_by_name(name_):
115
+ if self._verbose: sys.stdout.write('# Error. Same Bitmask Defined (%s)\n' % name_)
116
+ else:
117
+ self._bitmasks.append(s)
118
+
119
+ elif token == 'bitset':
120
+ ln, fn, name_ = token_buf.pop()
121
+ s = bitset.IDLBitset(name_, self)
122
+ s._add_annotations(pending_annotations)
123
+ s.parse_tokens(token_buf, filepath)
124
+ if self.bitset_by_name(name_):
125
+ if self._verbose: sys.stdout.write('# Error. Same Bitset Defined (%s)\n' % name_)
126
+ else:
127
+ self._bitsets.append(s)
128
+
129
+ elif token == 'union':
130
+ ln, fn, name_ = token_buf.pop()
131
+ s = union.IDLUnion(name_, self)
132
+ s._add_annotations(pending_annotations)
133
+ s.parse_tokens(token_buf, filepath)
134
+ if s.is_forward:
135
+ # Forward declaration ("union A;"): remember the name only.
136
+ if name_ not in self._forward_unions:
137
+ self._forward_unions.append(name_)
138
+ elif self.union_by_name(name_):
139
+ if self._verbose: sys.stdout.write('# Error. Same Union Defined (%s)\n' % name_)
140
+ # raise InvalidIDLSyntaxError
141
+ else:
142
+ self._unions.append(s)
143
+
144
+ elif token == 'native':
145
+ # "native N;": a type with a name only (issue #93).
146
+ ln, fn, name_ = token_buf.pop()
147
+ if name_ is None or name_ in (';', '{', '}'):
148
+ raise InvalidIDLSyntaxError(ln, fn, 'No name after "native"')
149
+ ln2, fn2, t = token_buf.pop()
150
+ if t != ';':
151
+ raise InvalidIDLSyntaxError(ln, fn, 'No ";" after "native %s"' % name_)
152
+ n = native.IDLNative(name_, self, filepath=filepath)
153
+ n._add_annotations(pending_annotations)
154
+ if self.native_by_name(name_):
155
+ if self._verbose: sys.stdout.write('# Error. Same Native Defined (%s)\n' % name_)
156
+ else:
157
+ self._natives.append(n)
158
+
159
+ elif token == 'const':
160
+ values = []
161
+ while True:
162
+ ln, fn, t = token_buf.pop()
163
+ if t is None:
164
+ if self._verbose: sys.stdout.write('# Error. No ";" after const.\n')
165
+ raise InvalidIDLSyntaxError(message='No ";" after const definition')
166
+ if t == ';':
167
+ break
168
+ values.append(t)
169
+
170
+ # Split at '=': "<type> <name> = <value>" (issue #52).
171
+ # The value is every token after '=', so that an
172
+ # expression such as "1 + 2" is kept whole.
173
+ if '=' not in values:
174
+ raise InvalidIDLSyntaxError(ln, fn, 'No "=" in const definition "%s"' % ' '.join(values))
175
+ eq = values.index('=')
176
+ if eq < 2:
177
+ raise InvalidIDLSyntaxError(ln, fn, 'No type or name in const definition "%s"' % ' '.join(values))
178
+ if eq == len(values) - 1:
179
+ raise InvalidIDLSyntaxError(ln, fn, 'No value in const definition "%s"' % ' '.join(values))
180
+ value_ = ' '.join(values[eq+1:])
181
+ name_ = values[eq-1]
182
+ typename = ' '.join(values[:eq-1])
183
+ s = const.IDLConst(name_, typename, value_, self, filepath=filepath)
184
+ s._add_annotations(pending_annotations)
185
+ s_ = self.const_by_name(name_)
186
+ if s_:
187
+ if self._verbose: sys.stdout.write('# Error. Same Const Defined (%s)\n' % name_)
188
+ else:
189
+ self._consts.append(s)
190
+
191
+ else:
192
+ return False
193
+ return True
194
+
195
+ @property
196
+ def has_definitions(self):
197
+ """True if any type or constant is defined in this scope."""
198
+ return any((self._typedefs, self._structs, self._exceptions, self._enums,
199
+ self._bitmasks, self._bitsets, self._unions, self._consts,
200
+ self._natives))
201
+
202
+ @property
203
+ def structs(self):
204
+ """Structs defined directly in this scope (list of :class:`~idl_parser.struct.IDLStruct`)."""
205
+ return self._structs
206
+
207
+ def struct_by_name(self, name):
208
+ """The struct named ``name`` (not scoped) in this scope, or None."""
209
+ for s in self.structs:
210
+ if s.name == name:
211
+ return s
212
+ return None
213
+
214
+ @property
215
+ def forward_structs(self):
216
+ """Names of structs forward-declared ("struct A;") in this scope,
217
+ in declaration order, whether or not they are defined later."""
218
+ return list(self._forward_structs)
219
+
220
+ @property
221
+ def undefined_forward_structs(self):
222
+ """Forward-declared struct names that have no definition in this scope."""
223
+ return [n for n in self._forward_structs if self.struct_by_name(n) is None]
224
+
225
+ def for_each_struct(self, func, filter=None):
226
+ """Call ``func`` with each struct and return the results as a list.
227
+
228
+ :param filter: If given, only the structs for which ``filter(struct)`` is
229
+ true are passed to ``func``.
230
+ """
231
+ retval = []
232
+ for m in self.structs:
233
+ if filter:
234
+ if filter(m):
235
+ retval.append(func(m))
236
+ pass
237
+ else:
238
+ retval.append(func(m))
239
+ return retval
240
+
241
+ @property
242
+ def exceptions(self):
243
+ """Exceptions defined directly in this scope (list of :class:`~idl_parser.struct.IDLException`)."""
244
+ return self._exceptions
245
+
246
+ def exception_by_name(self, name):
247
+ """The exception named ``name`` (not scoped) in this scope, or None."""
248
+ for x in self.exceptions:
249
+ if x.name == name:
250
+ return x
251
+ return None
252
+
253
+ def for_each_exception(self, func):
254
+ """Call ``func`` with each exception and return the results as a list."""
255
+ return [func(x) for x in self.exceptions]
256
+
257
+ @property
258
+ def enums(self):
259
+ """Enums defined directly in this scope (list of :class:`~idl_parser.enum.IDLEnum`)."""
260
+ return self._enums
261
+
262
+ def enum_by_name(self, name):
263
+ """The enum named ``name`` (not scoped) in this scope, or None."""
264
+ for e in self.enums:
265
+ if e.name == name:
266
+ return e
267
+ return None
268
+
269
+ def for_each_enum(self, func):
270
+ """Call ``func`` with each enum and return the results as a list."""
271
+ retval = []
272
+ for m in self.enums:
273
+ retval.append(func(m))
274
+ return retval
275
+
276
+ @property
277
+ def bitmasks(self):
278
+ """Bitmasks defined directly in this scope (list of :class:`~idl_parser.bitmask.IDLBitmask`)."""
279
+ return self._bitmasks
280
+
281
+ def bitmask_by_name(self, name):
282
+ """The bitmask named ``name`` (not scoped) in this scope, or None."""
283
+ for b in self.bitmasks:
284
+ if b.name == name:
285
+ return b
286
+ return None
287
+
288
+ def for_each_bitmask(self, func):
289
+ """Call ``func`` with each bitmask and return the results as a list."""
290
+ return [func(b) for b in self.bitmasks]
291
+
292
+ @property
293
+ def bitsets(self):
294
+ """Bitsets defined directly in this scope (list of :class:`~idl_parser.bitset.IDLBitset`)."""
295
+ return self._bitsets
296
+
297
+ def bitset_by_name(self, name):
298
+ """The bitset named ``name`` (not scoped) in this scope, or None."""
299
+ for b in self.bitsets:
300
+ if b.name == name:
301
+ return b
302
+ return None
303
+
304
+ def for_each_bitset(self, func):
305
+ """Call ``func`` with each bitset and return the results as a list."""
306
+ return [func(b) for b in self.bitsets]
307
+
308
+ @property
309
+ def unions(self):
310
+ """Unions defined directly in this scope (list of :class:`~idl_parser.union.IDLUnion`)."""
311
+ return self._unions
312
+
313
+ def union_by_name(self, name):
314
+ """The union named ``name`` (not scoped) in this scope, or None."""
315
+ for u in self.unions:
316
+ if u.name == name:
317
+ return u
318
+ return None
319
+
320
+ @property
321
+ def forward_unions(self):
322
+ """Names of unions forward-declared ("union A;") in this scope,
323
+ in declaration order, whether or not they are defined later."""
324
+ return list(self._forward_unions)
325
+
326
+ @property
327
+ def undefined_forward_unions(self):
328
+ """Forward-declared union names that have no definition in this scope."""
329
+ return [n for n in self._forward_unions if self.union_by_name(n) is None]
330
+
331
+ def for_each_union(self, func):
332
+ """Call ``func`` with each union and return the results as a list."""
333
+ retval = []
334
+ for m in self.unions:
335
+ retval.append(func(m))
336
+ return retval
337
+
338
+ @property
339
+ def consts(self):
340
+ """Constants defined directly in this scope (list of :class:`~idl_parser.const.IDLConst`)."""
341
+ return self._consts
342
+
343
+ def const_by_name(self, name):
344
+ """The constant named ``name`` (not scoped) in this scope, or None."""
345
+ for c in self.consts:
346
+ if c.name == name:
347
+ return c
348
+ return None
349
+
350
+ def for_each_const(self, func):
351
+ """Call ``func`` with each constant and return the results as a list."""
352
+ retval = []
353
+ for m in self.consts:
354
+ retval.append(func(m))
355
+ return retval
356
+
357
+ @property
358
+ def natives(self):
359
+ """Native types declared directly in this scope (list of :class:`~idl_parser.native.IDLNative`)."""
360
+ return self._natives
361
+
362
+ def native_by_name(self, name):
363
+ """The native type named ``name`` (not scoped) in this scope, or None."""
364
+ for n in self.natives:
365
+ if n.name == name:
366
+ return n
367
+ return None
368
+
369
+ def for_each_native(self, func):
370
+ """Call ``func`` with each native type and return the results as a list."""
371
+ return [func(n) for n in self.natives]
372
+
373
+ @property
374
+ def typedefs(self):
375
+ """Typedefs defined directly in this scope (list of :class:`~idl_parser.typedef.IDLTypedef`)."""
376
+ return self._typedefs
377
+
378
+ def typedef_by_name(self, name):
379
+ """The typedef named ``name`` (not scoped) in this scope, or None."""
380
+ for t in self.typedefs:
381
+ if t.name == name:
382
+ return t
383
+ return None
384
+
385
+ def for_each_typedef(self, func):
386
+ """Call ``func`` with each typedef.
387
+
388
+ Unlike the other ``for_each_*`` methods, it returns None.
389
+ """
390
+ retval = []
391
+ for m in self.typedefs:
392
+ retval.append(func(m))
393
+
394
+ def _definitions_simple_dic(self, quiet=False):
395
+ """``to_simple_dic()`` of the definitions in this scope, grouped by kind."""
396
+ return ([s.to_simple_dic(quiet) for s in self.structs] +
397
+ [x.to_simple_dic(quiet) for x in self.exceptions] +
398
+ [e.to_simple_dic(quiet) for e in self.enums] +
399
+ [b.to_simple_dic(quiet) for b in self.bitmasks] +
400
+ [b.to_simple_dic(quiet) for b in self.bitsets] +
401
+ [u.to_simple_dic(quiet) for u in self.unions] +
402
+ [t.to_simple_dic(quiet) for t in self.typedefs] +
403
+ [n.to_simple_dic(quiet) for n in self.natives] +
404
+ [c.to_simple_dic(quiet) for c in self.consts])
405
+
406
+ def _definitions_dic(self):
407
+ """``to_dic()`` of the definitions in this scope, keyed by kind."""
408
+ return { 'typedefs' : [t.to_dic() for t in self.typedefs],
409
+ 'natives' : [n.to_dic() for n in self.natives],
410
+ 'structs' : [s.to_dic() for s in self.structs],
411
+ 'exceptions' : [x.to_dic() for x in self.exceptions],
412
+ 'enums' : [e.to_dic() for e in self.enums],
413
+ 'bitmasks' : [b.to_dic() for b in self.bitmasks],
414
+ 'bitsets' : [b.to_dic() for b in self.bitsets],
415
+ 'unions' : [u.to_dic() for u in self.unions],
416
+ 'consts' : [c.to_dic() for c in self.consts] }
@@ -54,7 +54,8 @@ class InvalidDataTypeException(IDLParserException):
54
54
  pass
55
55
 
56
56
  class IDLCanNotFindException(IDLParserException):
57
- """An ``#include`` file or a base interface / bitset can not be found."""
57
+ """An ``#include`` file, a base interface / bitset or an exception in
58
+ ``raises (...)`` can not be found."""
58
59
  pass
59
60
 
60
61
 
@@ -63,18 +64,17 @@ class IDLParserWarning(UserWarning):
63
64
  pass
64
65
 
65
66
  class UnknownIDLSyntaxWarning(IDLParserWarning):
66
- """A word that starts no known definition was found in a module or the
67
- global scope (a misspelled keyword such as ``strcut``), and the definition
68
- it starts was skipped (issue #76).
67
+ """No longer issued: an unknown word in a module or the global scope (a
68
+ misspelled keyword such as ``strcut``) is an :class:`InvalidIDLSyntaxError`
69
+ since 0.4.0 (issue #94).
69
70
 
70
- This will become an :class:`InvalidIDLSyntaxError` in a future release.
71
- To get the error now, turn the warning into an exception::
72
-
73
- warnings.simplefilter('error', UnknownIDLSyntaxWarning)
71
+ It was issued from 0.3.2 (issue #76), and is kept so that code referring
72
+ to it (``warnings.simplefilter('error', UnknownIDLSyntaxWarning)``) still
73
+ works.
74
74
  """
75
75
  pass
76
76
 
77
77
  class UnsupportedIDLSyntaxWarning(IDLParserWarning):
78
78
  """A valid IDL definition that idl_parser does not support yet
79
- (``exception``, ``valuetype``, ``component``, ...) was skipped (issue #76)."""
79
+ (``valuetype``, ``component``, ...) was skipped (issue #76)."""
80
80
  pass