Null sema and codegen support for extension marker (...)
authorKim Grasman <kim.grasman@gmail.com>
Sun, 28 Jul 2013 20:55:44 +0000 (22:55 +0200)
committerKim Grasman <kim.grasman@gmail.com>
Sun, 28 Jul 2013 20:55:44 +0000 (22:55 +0200)
asn1ate/parser.py
asn1ate/pyasn1gen.py
asn1ate/sema.py

index ad0ef09..ae1bf24 100644 (file)
@@ -203,6 +203,9 @@ def _build_asn1_grammar():
     value_range_constraint = value_range_min + Suppress('..') + value_range_max
     constraint = Suppress('(') + value_range_constraint + Suppress(')')  # todo: consider exception spec from 45.6
 
+    # TODO: consider exception syntax from 24.1
+    extension_marker = Unique(ELLIPSIS)
+
     component_type_optional = named_type + Suppress(OPTIONAL)
     component_type_default = named_type + Suppress(DEFAULT) + value
     component_type_components_of = Suppress(COMPONENTS_OF) + type_
@@ -214,11 +217,10 @@ def _build_asn1_grammar():
     named_number = identifier + named_number_value
     enumeration = named_number | identifier
 
-    # todo: consider extension and exception syntax from 24.1
-    sequence_type = SEQUENCE + braced_list(component_type | ELLIPSIS)
+    sequence_type = SEQUENCE + braced_list(component_type | extension_marker)
     sequenceof_type = SEQUENCE_OF + (type_ | named_type)
     setof_type = SET_OF + (type_ | named_type)
-    choice_type = CHOICE + braced_list(named_type | ELLIPSIS)
+    choice_type = CHOICE + braced_list(named_type | extension_marker)
     enumerated_type = ENUMERATED + braced_list(enumeration)
     bitstring_type = BIT_STRING + braced_list(named_number)
     plain_integer_type = INTEGER
@@ -292,6 +294,7 @@ def _build_asn1_grammar():
     module_reference.setParseAction(annotate('ModuleReference'))
     module_body.setParseAction(annotate('ModuleBody'))
     module_definition.setParseAction(annotate('ModuleDefinition'))
+    extension_marker.setParseAction(annotate('ExtensionMarker'))
 
     return module_definition
 
index e5ed4cd..11d3dce 100644 (file)
@@ -152,7 +152,8 @@ class Pyasn1Backend(object):
 
         component_exprs = []
         for c in components:
-            component_exprs.append(self.generate_expr(c))
+            if not isinstance(c, ExtensionMarker):
+                component_exprs.append(self.generate_expr(c))
 
         fragment.write_enumeration(component_exprs)
 
@@ -269,6 +270,9 @@ class Pyasn1Backend(object):
         value_type = _translate_type(type_decl.type_name)
         return '%s = %s(%s)' % (assigned_value, value_type, value)
 
+    def ignore(self, t):
+        return ''
+
 
 def generate_pyasn1(sema_module, out_stream):
     return Pyasn1Backend(sema_module, out_stream).generate_code()
index 2b8fb9f..ff733cb 100644 (file)
@@ -520,6 +520,19 @@ class NamedValue(object):
     __repr__ = __str__
 
 
+class ExtensionMarker(object):
+    def __init__(self, elements):
+        pass
+
+    def references(self):
+        # TODO: This appears to never be called. Investigate.
+        return []
+
+    def __str__(self):
+        return '...'
+
+    __repr__ = __str__
+
 def _maybe_create_sema_node(token):
     if isinstance(token, parser.AnnotatedToken):
         return _create_sema_node(token)
@@ -566,6 +579,8 @@ def _create_sema_node(token):
         return SequenceOfType(token.elements)
     elif token.ty == 'SetOfType':
         return SetOfType(token.elements)
+    elif token.ty == 'ExtensionMarker':
+        return ExtensionMarker(token.elements)
 
     raise Exception('Unknown token type: %s' % token.ty)