Skip to content

Commit

Permalink
Merge pull request #211 from zoranbosnjak/master
Browse files Browse the repository at this point in the history
asterix-specs conversion fix
  • Loading branch information
dsalantic committed Dec 4, 2023
2 parents 2f6624b + 863cd37 commit a6def69
Show file tree
Hide file tree
Showing 39 changed files with 15,778 additions and 96 deletions.
31 changes: 29 additions & 2 deletions asterix-specs-converter/asterixjson2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import json
import hashlib
from copy import copy
from itertools import chain, repeat

def getNumber(value):
Expand Down Expand Up @@ -102,7 +103,7 @@ def replaceOutput(s):
u'–': '-',
u'“': '',
u'”': '',
u'°': ' deg',
u'°': 'deg',
})

def tell(s):
Expand Down Expand Up @@ -304,6 +305,27 @@ def case2(val):

renderRule(content, case1, case2)

def get_bit_size(item):
"""Return bit size of a (spare) item."""
if item['spare']:
return item['length']
else:
return item['variation']['size']

def ungroup(item):
"""Convert group of items of known size to element"""
n = sum([get_bit_size(i) for i in item['variation']['items']])
result = copy(item)
result['variation'] = {
'rule': {
'content': {'type': 'Raw'},
'type': 'ContextFree',
},
'size': n,
'type': 'Element',
}
return result

class Variation(object):

@staticmethod
Expand All @@ -324,7 +346,12 @@ def create(parent, item):
if vt == 'Extended':
n1 = variation['first']
n2 = variation['extents']
items = variation['items']
items = []
for i in variation['items']:
if i.get('variation') is not None:
if i['variation']['type'] == 'Group':
i = ungroup(i)
items.append(i)
return Variable(parent, item, n1, n2, items)

if vt == 'Repetitive':
Expand Down
2 changes: 1 addition & 1 deletion asterix-specs-converter/specs/asterix_cat001_1_2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Do not edit this file!
This file is auto-generated from json specs file.
sha1sum of concatenated json input(s): 9ca74855641a0468d6c35a57a5bdd06c2dec4cb0
sha1sum of concatenated json input(s): 42d255f438a9c4fce818839ae6b4927d380e4200
See asterix-specs-converter/README.md for details.
-->
Expand Down
2 changes: 1 addition & 1 deletion asterix-specs-converter/specs/asterix_cat001_1_3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Do not edit this file!
This file is auto-generated from json specs file.
sha1sum of concatenated json input(s): 80c9cef3b90478b73c20f88a2ccd34540d0a6351
sha1sum of concatenated json input(s): 817a9cc056850f867a774fa1d794e09133877d55
See asterix-specs-converter/README.md for details.
-->
Expand Down

0 comments on commit a6def69

Please sign in to comment.