python.stg 3.09 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
group python;

//delimiters "$", "$"

RootXml(arrsFiles) ::= <<
#!/usr/bin/env python
# ASN.1 Data model
asn1Files = []
asn1Modules = []
exportedTypes = {}
exportedVariables = {}
importedModules = {}
types = {}
$arrsFiles;separator="\n"$
>>

FileXml(sFileName, arrsModules) ::= <<
asn1Files.append("$sFileName$")
$arrsModules;separator="\n"$
>>

ModuleXml(sName, arrsImportedModules, arrsExpTypes, arrsExpVars, arrsTases) ::=<<
asn1Modules.append("$sName$")
exportedTypes["$sName$"] = [$arrsExpTypes:{x|"$x$"};separator=", "$]
exportedVariables["$sName$"] = [$arrsExpVars:{x|"$x$"};separator=", "$]
importedModules["$sName$"] = [$arrsImportedModules:{x|$x$};separator=", "$]
$arrsTases;separator="\n"$
>>

ImportedMod(sName, arrsTypes, arrsVars) ::= <<
{"$sName$":{"ImportedTypes": [$arrsTypes:{t|"$t$"};separator=","$], "ImportedVariables": [$arrsVars:{t|"$t$"};separator=","$]}}
>>

TasXml(sName, nLine, nPos, sType) ::= <<
types["$sName$"] = type("$sName$", (object,), {
    "Line": $nLine$, "CharPositionInLine": $nPos$, "type": type("$sName$_type", (object,), {
        $sType$
    })
})

>>

TypeGeneric(nLine, nPos, sSubType) ::= <<
"Line": $nLine$, "CharPositionInLine": $nPos$, $sSubType$
>>


MinMaxType(sName, sMin, sMax) ::= <<
"kind": "$sName$", "Min": "$sMin$", "Max": "$sMax$"
>>

MinMaxType2(sName, sMin, sMax) ::= <<
"kind": "$sName$", "Min": "$sMin$", "Max": "$sMax$"
>>

BooleanType () ::= <<"kind": "BooleanType">>

NullType () ::= <<"kind": "NullType">>


EnumItem (sName, nVal, nLine, nPos, sCID) ::= <<
"$sName$": type("$sCID$", (object,), {
    "IntValue": $nVal$, "Line": $nLine$, "CharPositionInLine": $nPos$, "EnumID": "$sCID$"
})
>>

EnumType(arrsItems) ::= <<
"kind": "EnumeratedType", "Extensible": "False", "ValuesAutoCalculated": "False", "EnumValues": {
    $arrsItems;separator=",\n"$
}
>>


ChoiceChild(sName, nLine, nPos, sChildContent, sNamePresent ) ::= <<
"$sName$": type("$sNamePresent$", (object,), {
    "Line": $nLine$, "CharPositionInLine": $nPos$, "EnumID": "$sNamePresent$", "type": type("$sNamePresent$_type", (object,), {
        $sChildContent$
    })
})
>>

ChoiceType(arrsChildren) ::= <<
"kind": "ChoiceType", "Children": {
    $arrsChildren;separator=",\n"$
}
>>


SequenceChild(sName, bOptional, sDefVal, nLine, nPos, sChildContent ) ::= <<
"$sName$": type("$sName$", (object,), {
    "Optional": "$bOptional$"$if(sDefVal)$, "DefaultValue": "$sDefVal$"$endif$, "Line": $nLine$, "CharPositionInLine": $nPos$, "type": type("$sName$_type", (object,), {
        $sChildContent$
    })
})
>>

SequenceType(arrsChildren) ::= <<
"kind": "SequenceType", "Children": {
    $arrsChildren;separator=",\n"$
}
>>


SequenceOfType(sMin, sMax, sChild) ::= <<
"kind": "SequenceOfType", "Min": "$sMin$", "Max": "$sMax$", "type": type("SeqOf_type", (object,), {
    $sChild$
})
>>

RefTypeMinMax(sMin, sMax, sName, sModName) ::= <<
"kind": "ReferenceType", "ReferencedTypeName": "$sName$", "Min": "$sMin$", "Max": "$sMax$"$if(sModName)$, "ReferencedModName": "$sModName$"$endif$
>>

RefType(sName, sModName) ::= <<
"kind": "ReferenceType", "ReferencedTypeName": "$sName$"$if(sModName)$, "ReferencedModName": "$sModName$"$endif$
>>