kimgr / asn1ate

A Python library for translating ASN.1 into other forms.
Other
69 stars 41 forks source link

Fail to parse INTEGER single value with syntax "|" #40

Closed FredLien closed 5 years ago

FredLien commented 8 years ago

Hi,

I have recently used asn1ate to translate ASN.1 file to python code. The case of following cannot correctly generate code. I paste the patch code to solve this. FYI

ASN.1

Network-Device ::= SEQUENCE {
    port-num               INTEGER (0 .. 255),
    port-lane              INTEGER ( 0 | 1 | 2 | 4 ),
    port-speed             INTEGER ( 0 | 1000 | 10000 | 250000 ),
    ...
}
## patch code:

diff --git a/asn1ate/parser.py b/asn1ate/parser.py
index b8e3623..e9970a9 100644
--- a/asn1ate/parser.py
+++ b/asn1ate/parser.py
@@ -236,8 +236,9 @@ def _build_asn1_grammar():
     # todo: consider the full subtype and general constraint syntax described in 45.*
     lower_bound = (constraint_real_value | signed_number | referenced_value | MIN)
     upper_bound = (constraint_real_value | signed_number | referenced_value | MAX)
-    single_value_constraint = Suppress('(') + value + Suppress(')')
## \+    single_value_constraint = Suppress('(') + Optional(Group(delimitedList(value, delim='|'))) + Suppress(')')

Regards, FredLien

FredLien commented 8 years ago

Sorry, I find it's duplicate with "Single value constraint handled as a list #14." Please ignore above information. Thanks.

mungayree commented 7 years ago

I think below are some statements of ASN.1 the current version do not handle - So a user need to replicate the IMPORT by copy and paste. IMPORTS abc-xyz FROM Top-Component and

Network-Device ::= SEQUENCE {
    port-num               INTEGER (0 .. 255 | 10000 ), <------------- this case
    port-lane              INTEGER ( 0 | 1 | 2 | 4 ),
    port-speed             INTEGER ( 0 | 1000 | 10000 | 250000 ),
    ...
}

at times there spec which do this, but the patch does not seem to work on it.

kimgr commented 5 years ago

This is now fixed on master.