Parser support for extension marker (...).
authorKim Grasman <kim.grasman@gmail.com>
Sun, 28 Jul 2013 20:44:58 +0000 (22:44 +0200)
committerKim Grasman <kim.grasman@gmail.com>
Sun, 28 Jul 2013 20:44:58 +0000 (22:44 +0200)
Still no sema or codegen support.

asn1ate/parser.py
testdata/extension_marker.asn [new file with mode: 0644]

index 8fe2fea..ad0ef09 100644 (file)
@@ -114,6 +114,7 @@ def _build_asn1_grammar():
     AUTOMATIC_TAGS = Keyword('AUTOMATIC TAGS')
     EXTENSIBILITY_IMPLIED = Keyword('EXTENSIBILITY IMPLIED')
     COMPONENTS_OF = Keyword('COMPONENTS OF')
+    ELLIPSIS = Keyword('...')
 
     # Built-in types
     SEQUENCE = Keyword('SEQUENCE')
@@ -214,10 +215,10 @@ def _build_asn1_grammar():
     enumeration = named_number | identifier
 
     # todo: consider extension and exception syntax from 24.1
-    sequence_type = SEQUENCE + braced_list(component_type)
+    sequence_type = SEQUENCE + braced_list(component_type | ELLIPSIS)
     sequenceof_type = SEQUENCE_OF + (type_ | named_type)
     setof_type = SET_OF + (type_ | named_type)
-    choice_type = CHOICE + braced_list(named_type)
+    choice_type = CHOICE + braced_list(named_type | ELLIPSIS)
     enumerated_type = ENUMERATED + braced_list(enumeration)
     bitstring_type = BIT_STRING + braced_list(named_number)
     plain_integer_type = INTEGER
diff --git a/testdata/extension_marker.asn b/testdata/extension_marker.asn
new file mode 100644 (file)
index 0000000..9046310
--- /dev/null
@@ -0,0 +1,28 @@
+TEST DEFINITIONS ::=
+BEGIN
+
+ChoiceType ::= CHOICE
+{
+  required1 INTEGER,
+  required2 UTF8String,
+  ...
+}
+
+SequenceType ::= SEQUENCE
+{
+  required1 INTEGER,
+  required2 UTF8String,
+  ...
+}
+
+-- I'm not sure if this is valid syntax, but I expect not.
+-- The extension marker is likely only acceptable as the last
+-- choice/sequence component.
+PotentiallyInvalid ::= SEQUENCE
+{
+  required1 INTEGER,
+  ...,
+  required2 UTF8String
+}
+
+END