kimgr / asn1ate

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

Parsing Error: pyparsing.ParseException: Expected "DEFINITIONS" #58

Open twix1312 opened 6 years ago

twix1312 commented 6 years ago

I'm trying to convert an LTE specification's ASN.1 syntax into python code and ran the file (see attached zip) in pyasn1gen.py.

I received the following error:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 649, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 627, in main
    parse_tree = parser.parse_asn1(asn1def)
  File "/usr/lib/python2.7/site-packages/asn1ate/parser.py", line 40, in parse_asn1
    parse_result = grammar.parseString(asn1_definition)
  File "/usr/lib/python2.7/site-packages/pyparsing.py", line 1632, in parseString
    raise exc
pyparsing.ParseException: Expected "DEFINITIONS" (at char 195), (line:8, col:13)

The attached file was taken from here. I had to filter out the ASN.1 definitions and remove unwanted text.

I might have made a mistake doing that. Could you please help? gtp.zip

kimgr commented 6 years ago

It might be a while until I get to this, but this: pyparsing.ParseException: Expected "DEFINITIONS" (at char 195), (line:8, col:13) is a good place to start. You can run your ASN.1 through http://asn1-playground.oss.com/ first, to make sure it's valid.

asn1ate does not support all of ASN.1 so there may be something that's missing, and the line/column from the error message might give a clue as to what it is.

twix1312 commented 6 years ago

Hi,

Thanks for suggesting that link. There were some ASN errors that I've fixed. Now the compilation of the ASN.1 file works fine at that link.

However, pyasn1.gen.py gives a new error: Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 649, in sys.exit(main()) File "/usr/lib/python2.7/site-packages/asn1ate/pyasn1gen.py", line 627, in main parse_tree = parser.parse_asn1(asn1def) File "/usr/lib/python2.7/site-packages/asn1ate/parser.py", line 40, in parse_asn1 parse_result = grammar.parseString(asn1_definition) File "/usr/lib/python2.7/site-packages/pyparsing.py", line 1632, in parseString raise exc pyparsing.ParseException: Expected "END" (at char 6111), (line:195, col:37)

Attaching the updated ASN.1 file.

Any help would be appreciated.

Thanks a bunch!

On Thu, Nov 16, 2017 at 3:51 PM, Kim Gräsman notifications@github.com wrote:

It might be a while until I get to this, but this: pyparsing.ParseException: Expected "DEFINITIONS" (at char 195), (line:8, col:13) is a good place to start. You can run your ASN.1 through http://asn1-playground.oss.com/ first, to make sure it's valid.

asn1ate does not support all of ASN.1 so there may be something that's missing, and the line/column from the error message might give a clue as to what it is.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kimgr/asn1ate/issues/58#issuecomment-344879179, or mute the thread https://github.com/notifications/unsubscribe-auth/AejhoIbpuU19q4WXwpIVotIvby6ELfEyks5s3AyMgaJpZM4QgNXl .

gtp.zip

kimgr commented 6 years ago

So is line 195, col 37 at the end of the file? Can you upload the ASN.1 as text so I can see it?

twix1312 commented 6 years ago

I've attached the ASN.1 as a textfile (its 6600 lines long!)

If you just want that specific portion: FROM S1AP-Constants;

-- **************************************************************
--
-- Interface Elementary Procedure Class
--
-- **************************************************************

S1AP-ELEMENTARY-PROCEDURE ::= CLASS {
    &InitiatingMessage              ,
    &SuccessfulOutcome                          OPTIONAL,
    &UnsuccessfulOutcome                        OPTIONAL,
    &procedureCode              ProcedureCode   UNIQUE,
    &criticality                Criticality     DEFAULT ignore
}

its the "{" brace after "S1AP-ELEMENTARY-PROCEDURE ::= CLASS". gtp.txt

kimgr commented 6 years ago

Yeah, that explains it. asn1ate doesn't support CLASSes, and I don't really know where to start on that, so I think it's safe to assume that it won't do so unless you can spare time to work on it yourself.