Skip to content

Commit

Permalink
Merge pull request #1 from KOomaXX/fix-add_parser_support_for_WITH_SU…
Browse files Browse the repository at this point in the history
…CCESSORS_WITH_DESCENDANTS-1

added support for 'WITH SUCCESSORS' and 'WITH DESCENDANTS' in parser …
  • Loading branch information
KOomaXX committed Mar 9, 2023
2 parents 349e9a7 + 94b5c7d commit bbe0f4d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion asn1tools/parser.py
Expand Up @@ -894,6 +894,8 @@ def create_grammar():
NULL = Keyword('NULL').setName('NULL')
WITH_COMPONENT = Keyword('WITH COMPONENT').setName('WITH COMPONENT')
WITH_COMPONENTS = Keyword('WITH COMPONENTS').setName('WITH COMPONENTS')
WITH_SUCCESSORS = Keyword('WITH SUCCESSORS').setName('WITH SUCCESSORS')
WITH_DESCENDANTS = Keyword('WITH DESCENDANTS').setName('WITH DESCENDANTS')
COMPONENTS_OF = Keyword('COMPONENTS OF').setName('COMPONENTS OF')
PRESENT = Keyword('PRESENT').setName('PRESENT')
ABSENT = Keyword('ABSENT').setName('ABSENT')
Expand Down Expand Up @@ -1676,7 +1678,9 @@ def create_grammar():
symbol_list = Group(delimitedList(symbol))
symbols_from_module = (symbol_list
+ FROM
+ global_module_reference)
+ global_module_reference
+ Suppress(Optional(WITH_SUCCESSORS
| WITH_DESCENDANTS)))
symbols_imported = ZeroOrMore(Group(symbols_from_module))
imports = Optional(Suppress(IMPORTS)
- symbols_imported
Expand Down
23 changes: 22 additions & 1 deletion tests/test_parse.py
Expand Up @@ -177,7 +177,7 @@ def test_parse_imports_global_module_reference(self):
'IMPORTS '
'a FROM B '
'c, d FROM E global-module-reference '
'f, g FROM H {iso(1)}; '
'f, g FROM H {iso(1)} ;'
'END')

expected = {
Expand Down Expand Up @@ -243,6 +243,27 @@ def test_parse_empty_imports(self):

self.assertEqual(actual, expected)

def test_parse_with_successors_descendants(self):
actual = asn1tools.parse_string('A DEFINITIONS ::= BEGIN '
'IMPORTS '
'a FROM B WITH SUCCESSORS '
'c, d FROM E {iso(1)} WITH DESCENDANTS ;'
'END')
expected = {
'A': {
'extensibility-implied': False,
'imports': {
'B': ['a'],
'E': ['c', 'd']
},
'object-classes': {},
'object-sets': {},
'types': {},
'values': {}
}
}
self.assertEqual(actual, expected)

def test_parse_keyword_in_type_name(self):
actual = asn1tools.parse_string('A DEFINITIONS ::= BEGIN '
'ENDa ::= INTEGER '
Expand Down

0 comments on commit bbe0f4d

Please sign in to comment.