From 37e8a65f04d662a392436ef04066a96c4c6f3c6e Mon Sep 17 00:00:00 2001 From: Kim Grasman Date: Mon, 29 Jul 2013 10:28:56 +0200 Subject: [PATCH] Parser support for SIZE constraints on SET OF and SEQUENCE OF. --- asn1ate/parser.py | 13 ++++++++----- asn1ate/sema.py | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/asn1ate/parser.py b/asn1ate/parser.py index 6df2c3f..4eb3f12 100644 --- a/asn1ate/parser.py +++ b/asn1ate/parser.py @@ -115,12 +115,12 @@ def _build_asn1_grammar(): EXTENSIBILITY_IMPLIED = Keyword('EXTENSIBILITY IMPLIED') COMPONENTS_OF = Keyword('COMPONENTS OF') ELLIPSIS = Keyword('...') + SIZE = Keyword('SIZE') + OF = Keyword('OF') # Built-in types SEQUENCE = Keyword('SEQUENCE') SET = Keyword('SET') - SEQUENCE_OF = Keyword('SEQUENCE OF') - SET_OF = Keyword('SET OF') CHOICE = Keyword('CHOICE') ENUMERATED = Keyword('ENUMERATED') BIT_STRING = Keyword('BIT STRING') @@ -203,7 +203,10 @@ def _build_asn1_grammar(): value_range_min = (signed_number | valuereference | MIN) value_range_max = (signed_number | valuereference | MAX) value_range_constraint = value_range_min + Suppress('..') + value_range_max - constraint = Suppress('(') + value_range_constraint + Suppress(')') # todo: consider exception spec from 45.6 + size_constraint = SIZE + Suppress('(') + value_range_constraint + Suppress(')') + constraint = Suppress('(') + value_range_constraint + Suppress(')') + optional_paren_l = Optional(Suppress('(')) + optional_paren_r = Optional(Suppress(')')) # TODO: consider exception syntax from 24.1 extension_marker = Unique(ELLIPSIS) @@ -221,8 +224,8 @@ def _build_asn1_grammar(): set_type = SET + braced_list(component_type | extension_marker) sequence_type = SEQUENCE + braced_list(component_type | extension_marker) - sequenceof_type = SEQUENCE_OF + (type_ | named_type) - setof_type = SET_OF + (type_ | named_type) + sequenceof_type = SEQUENCE + Optional(optional_paren_l + size_constraint + optional_paren_r) + OF + (type_ | named_type) + setof_type = SET + Optional(optional_paren_l + size_constraint + optional_paren_r) + OF + (type_ | named_type) choice_type = CHOICE + braced_list(named_type | extension_marker) enumerated_type = ENUMERATED + braced_list(enumeration) bitstring_type = BIT_STRING + braced_list(named_number) diff --git a/asn1ate/sema.py b/asn1ate/sema.py index 853f4ee..4f44f4e 100644 --- a/asn1ate/sema.py +++ b/asn1ate/sema.py @@ -248,7 +248,8 @@ class SetType(ConstructedType): class SequenceOfType(object): def __init__(self, elements): - type_name, type_token = elements + # TODO: handle optional size constraint + type_name, of_keyword, type_token = elements self.type_name = type_name self.type_decl = _create_sema_node(type_token) @@ -263,7 +264,8 @@ class SequenceOfType(object): class SetOfType(object): def __init__(self, elements): - type_name, type_token = elements + # TODO: handle optional size constraint + type_name, of_keyword, type_token = elements self.type_name = type_name self.type_decl = _create_sema_node(type_token) -- 1.7.10.4