Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
3abe9331 | 2 | * Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | ******************************************************************************/ | |
8 | /* RAW encoding/decoding specification parser & compiler */ | |
9 | ||
10 | %{ | |
11 | #include <stdlib.h> | |
12 | #include <stdio.h> | |
13 | #include <string.h> | |
14 | #include "../../common/memory.h" | |
15 | #include "../Int.hh" | |
16 | #include "../Real.hh" | |
17 | #include "../Value.hh" | |
18 | #include "AST_ttcn3.hh" | |
19 | #include "rawASTspec.h" | |
20 | #include "RawAST.hh" | |
21 | #include "../XerAttributes.hh" | |
22 | #include "BerAST.hh" | |
23 | #include "JsonAST.hh" | |
24 | ||
25 | extern void rawAST_error(const char *str); | |
26 | extern int rawAST_lex(); | |
27 | ||
28 | extern RawAST* rawstruct; | |
29 | extern Common::Module *mymod; | |
30 | extern int length_multiplier; | |
31 | extern TextAST *textstruct; | |
32 | extern bool raw_f; | |
33 | extern bool text_f; | |
34 | extern bool xer_f; | |
35 | extern bool ber_f; | |
36 | extern bool json_f; | |
37 | extern XerAttributes* xerstruct; | |
38 | extern BerAST* berstruct; | |
39 | extern JsonAST* jsonstruct; | |
40 | ||
41 | extern string *parse_charstring_value(const char *str, | |
42 | const Common::Location& loc); | |
43 | ||
44 | #define YYERROR_VERBOSE | |
45 | ||
46 | #ifndef NDEBUG | |
47 | union YYSTYPE; | |
48 | static void yyprint(FILE *file, int type, const YYSTYPE& value); | |
49 | #define YYPRINT(f,t,v) yyprint(f,t,v) | |
50 | #endif | |
51 | ||
52 | %} | |
53 | ||
54 | %union { | |
55 | bool boolval; | |
56 | int enumval; | |
57 | char* str; | |
58 | const char *cstr; | |
59 | Common::Int intval; | |
60 | Common::Real floatval; | |
61 | Common::Value::verdict_t verdictval; | |
62 | Common::Identifier *identifier; | |
63 | rawAST_field_list *fieldlist; | |
64 | rawAST_tag_list taglist; | |
65 | rawAST_tag_field_value keyid; | |
66 | rawAST_single_tag singletag; | |
67 | rawAST_toplevel toplevel; | |
68 | rawAST_values values; | |
69 | struct { | |
70 | char *token; | |
71 | bool case_sensitive; | |
72 | } decodetoken; | |
73 | NamespaceSpecification nsspec; | |
74 | NamespaceRestriction nsrestr; | |
75 | } | |
76 | ||
77 | %token <intval> XNumber | |
78 | %token <floatval> XFloatValue | |
79 | %token <identifier> XIdentifier | |
80 | %token <str> XBstring | |
81 | %token <str> XHstring | |
82 | %token <str> XOstring | |
83 | %token <str> XCstring | |
84 | %token <str> Xstring | |
85 | %token <boolval> XBooleanConst | |
86 | %token <verdictval> XVerdictConst | |
87 | %token XNullKeyword | |
88 | %token XNULLKeyword | |
89 | %token XOmitKeyword | |
90 | ||
91 | %token <str> Xtoken | |
92 | %token XBeginKeyword | |
93 | %token XEndKeyword | |
94 | %token XSeparatorKeyword | |
95 | %token XCodingKeyword | |
96 | %token XLengthToken | |
97 | %token XLowerToken | |
98 | %token XUpperToken | |
99 | %token XJustToken | |
100 | %token XLeftToken | |
101 | %token XRightToken | |
102 | %token XCenterToken | |
103 | %token XLeadingToken | |
104 | %token XTrueToken | |
105 | %token XSensitivToken | |
106 | %token XInSensitivToken | |
107 | %token XConvertToken | |
108 | %token XFalseToken | |
109 | %token XRepeatToken | |
110 | ||
111 | %token XPaddingKeyword | |
112 | %token XPaddAllKeyword | |
113 | %token XPrePaddingKeyword | |
114 | %token XPaddingPatternKeyword | |
115 | %token XOtherwise | |
116 | %token <enumval> XYes | |
117 | %token <enumval> XNo | |
118 | %token <enumval> XReverse | |
119 | %token XFieldOrderKeyword | |
120 | %token <enumval> XMsb | |
121 | %token <enumval> XLsb | |
122 | %token XExtensionBitKeyword | |
123 | %token XExtensionBitGroupKeyword | |
124 | %token XLengthToKeyword | |
125 | %token XPointerToKeyword | |
126 | %token XUnitKeyword | |
127 | %token XPtrUnitKeyword | |
128 | %token XPtrOffsetKeyword | |
129 | %token <enumval> XBits | |
130 | %token <enumval> XOctets | |
131 | %token XLengthIndexKeyword | |
132 | %token XTagKeyword | |
133 | %token XCrossTagKeyword | |
134 | %token XPresenceKeyword | |
135 | %token XFieldLengthKeyword | |
136 | %token XAlignKeyword | |
137 | %token <enumval> XLeft | |
138 | %token <enumval> XRight | |
139 | %token XCompKeyword | |
140 | %token <enumval> XUnsigned | |
141 | %token <enumval> XCompl | |
142 | %token <enumval> XSignbit | |
143 | %token XByteOrderKeyword | |
144 | %token <enumval> XFirst | |
145 | %token <enumval> XLast | |
146 | %token XBitOrderKeyword | |
147 | %token XBitOrderInFieldKeyword | |
148 | %token XBitOrderInOctetKeyword | |
149 | %token XHexOrderKeyword | |
150 | %token <enumval> XLow | |
151 | %token <enumval> XHigh | |
152 | %token XToplevelKeyword | |
153 | %token XRepeatableKeyword | |
3abe9331 | 154 | %token XIntXKeyword |
51fa56b9 | 155 | %token XBitKeyword |
156 | %token XUnsignedKeyword | |
970ed795 EL |
157 | |
158 | /* XER attributes */ | |
159 | %token XKWall "all" | |
160 | %token XKWas "as" | |
161 | %token XKWin "in" | |
162 | %token XKWcapitalized "capitalized" | |
163 | %token XKWuncapitalized "uncapitalized" | |
164 | %token XKWlowercased "lowercased" | |
165 | %token XKWuppercased "uppercased" | |
166 | %token XKWpreserve "preserve" | |
167 | %token XKWreplace "replace" | |
168 | %token XKWcollapse "collapse" | |
169 | %token XKWfrom "from" | |
170 | %token XKWexcept "except" | |
171 | %token XKWunqualified "unqualified" | |
172 | %token XKWqualified "qualified" | |
173 | %token XKWprefix "prefix" | |
174 | ||
175 | ||
51fa56b9 | 176 | %token XKWabstract "abstact" |
970ed795 EL |
177 | %token XKWanyAttributes "anyAttributes" |
178 | %token XKWanyElement "anyElement" | |
179 | %token XKWattribute "attribute" | |
180 | %token XKWattributeFormQualified "attributeFormQualified" | |
51fa56b9 | 181 | %token XKWblock "block" |
970ed795 EL |
182 | %token XKWcontrolNamespace "controlNamespace" |
183 | %token XKWdefaultForEmpty "defaultForEmpty" | |
184 | %token XKWelement "element" | |
185 | %token XKWelementFormQualified "elementFormQualified" | |
186 | %token XKWembedValues "embedValues" | |
187 | %token XKWform "form" | |
188 | %token XKWlist "list" | |
189 | %token XKWname "name" | |
190 | %token XKWnamespace "namespace" | |
191 | %token XKWtext "text" | |
192 | %token XKWuntagged "untagged" | |
193 | %token XKWuseNil "useNil" | |
194 | %token XKWuseNumber "useNumber" | |
195 | %token XKWuseOrder "useOrder" | |
196 | %token XKWuseUnion "useUnion" | |
197 | %token XKWuseType "useType" | |
198 | %token XKWwhiteSpace "whiteSpace" | |
199 | %token XSD "XSD" | |
200 | ||
201 | /* XSD:something */ | |
202 | %token XSDstring "string" | |
203 | %token XSDnormalizedString "normalizedString" | |
204 | %token XSDtoken "token" | |
205 | %token XSDName "Name" | |
206 | %token XSDNMTOKEN "NMTOKEN" | |
207 | %token XSDNCName "NCName" | |
208 | %token XSDID "ID" | |
209 | %token XSDIDREF "IDREF" | |
210 | %token XSDENTITY "ENTITY" | |
211 | %token XSDhexBinary "hexBinary" | |
212 | %token XSDbase64Binary "base64Binary" | |
213 | %token XSDanyURI "anyURI" | |
214 | %token XSDlanguage "language" | |
215 | %token XSDinteger "integer" | |
216 | %token XSDpositiveInteger "positiveInteger" | |
217 | %token XSDnonPositiveInteger "nonPositiveInteger" | |
218 | %token XSDnegativeInteger "negativeInteger" | |
219 | %token XSDnonNegativeInteger "nonNegativeInteger" | |
220 | /* XKWlong instead of %token XSDlong */ | |
221 | %token XSDunsignedLong "unsignedLong" | |
222 | %token XSDint "int" | |
223 | %token XSDunsignedInt "unsignedInt" | |
224 | /* XKWshort instead of %token XSDshort */ | |
225 | %token XSDunsignedShort "unsignedShort" | |
226 | %token XSDbyte "byte" | |
227 | %token XSDunsignedByte "unsignedByte" | |
228 | %token XSDdecimal "decimal" | |
229 | %token XSDfloat "float" | |
230 | %token XSDdouble "double" | |
231 | %token XSDduration "duration" | |
232 | %token XSDdateTime "dateTime" | |
233 | %token XSDtime "time" | |
234 | %token XSDdate "date" | |
235 | %token XSDgYearMonth "gYearMonth" | |
236 | %token XSDgYear "gYear" | |
237 | %token XSDgMonthDay "gMonthDay" | |
238 | %token XSDgDay "gDay" | |
239 | %token XSDgMonth "gMonth" | |
240 | %token XSDNMTOKENS "NMTOKENS" | |
241 | %token XSDIDREFS "IDREFS" | |
242 | %token XSDENTITIES "ENTITIES" | |
243 | %token XSDQName "QName" | |
244 | %token XSDboolean "boolean" | |
245 | %token XSDanySimpleType "anySimpleType" | |
246 | %token XSDanyType "anyType" | |
247 | ||
248 | ||
249 | ||
250 | /* BER attributes */ | |
251 | %token XKWlength "length" | |
252 | %token XKWaccept "accept" | |
253 | %token XKWlong "long" | |
254 | %token XKWshort "short" | |
255 | %token XKWindefinite "indefinite" | |
256 | %token XKWdefinite "definite" | |
257 | ||
258 | ||
259 | // JSON attributes | |
260 | %token XKWjson "JSON" | |
261 | %token XKWomit "omit" | |
262 | %token XKWnull "null" | |
263 | %token XAliasToken "JSON alias" | |
264 | %token XKWvalue "value" | |
265 | %token XKWdefault "default" | |
3abe9331 | 266 | %token XKWextend "extend" |
267 | %token XKWmetainfo "metainfo" | |
268 | %token XKWfor "for" | |
269 | %token XKWunbound "unbound" | |
970ed795 EL |
270 | %token XJsonValueStart "(" |
271 | %token XJsonValueEnd ")" | |
272 | %token XJsonValueSegment "JSON value" | |
273 | ||
274 | ||
275 | %type <enumval> | |
276 | XYesOrNo XMsbOrLsb XFieldOrderDef XPaddingDef XExtensionBitDef XUnitDef | |
277 | XBitsOctets XAlignDef XLeftOrRight XCompDef XCompValues XByteOrderDef | |
278 | XFirstOrLast XBitOrderDef XBitOrderInFieldDef XBitOrderInOctetDef | |
279 | XHexOrderDef XLowOrHigh XYesOrNoOrReverse XFieldLengthDef | |
280 | XPtrOffsetDef XPrePaddingDef XRepeatableDef form | |
281 | ||
282 | %type <fieldlist> | |
283 | XLengthIndexDef XStructFieldRefOrEmpty XStructFieldRef | |
284 | ||
285 | %type <str> | |
3abe9331 | 286 | XEncodeToken XmatchDef XAliasToken XJsonValueSegment XJsonValueCore XJsonValue |
970ed795 EL |
287 | |
288 | %type <decodetoken> | |
289 | XDecodeToken | |
290 | ||
291 | %type <cstr> | |
292 | XTextReservedWord | |
293 | ||
294 | %type <identifier> | |
295 | XPointerToDef XRecordFieldRef XIdentifierOrReserved | |
296 | ||
297 | %type <values> | |
298 | XRvalue | |
299 | ||
300 | %type <taglist> | |
301 | XAssocList | |
302 | ||
303 | /* note: multiple "XSingleEncodingDefs have to be merged into one 'fullspec' */ | |
304 | %type <fullspec> | |
305 | XEncodingDefList XSingleEncodingDef | |
306 | ||
307 | %type <keyid> | |
308 | XKeyId | |
309 | %type <boolval> | |
310 | XmodifierDef | |
311 | ||
312 | %type <singletag> | |
313 | XAssocElement XKeyIdOrIdList XKeyIdList XMultiKeyId | |
314 | ||
315 | %type <toplevel> | |
316 | XToplevelDef XTopDefList XTopDef | |
317 | ||
318 | /* XER */ | |
319 | %type <nsrestr> | |
320 | anyAttributes anyElement optNamespaceRestriction urilist | |
321 | ||
322 | ||
323 | %type <str> defaultForEmpty name newnameOrKeyword keyword optPrefix quotedURIorAbsent | |
324 | ||
325 | %type <nsspec> namespace namespacespecification controlNamespace text | |
326 | ||
327 | %type <intval> whiteSpace | |
328 | ||
329 | /* destructors */ | |
330 | %destructor { Free($$); } | |
331 | XBstring | |
332 | XCstring | |
333 | XEncodeToken | |
334 | XHstring | |
335 | XmatchDef | |
336 | XOstring | |
337 | Xtoken | |
338 | Xstring | |
339 | XAliasToken | |
340 | XJsonValueSegment | |
3abe9331 | 341 | XJsonValueCore |
970ed795 EL |
342 | XJsonValue |
343 | ||
344 | %destructor { delete $$; } | |
345 | XIdentifier | |
346 | XIdentifierOrReserved | |
347 | XPointerToDef | |
348 | XRecordFieldRef | |
349 | ||
350 | %destructor { free_rawAST_field_list($$); } | |
351 | XLengthIndexDef | |
352 | XStructFieldRef | |
353 | XStructFieldRefOrEmpty | |
354 | ||
355 | %destructor { free_rawAST_tag_list(&$$); } | |
356 | XAssocList | |
357 | ||
358 | %destructor { free_rawAST_tag_field_value(&$$); } | |
359 | XKeyId | |
360 | ||
361 | %destructor { free_rawAST_single_tag(&$$); } | |
362 | XAssocElement | |
363 | XKeyIdList | |
364 | XKeyIdOrIdList | |
365 | XMultiKeyId | |
366 | ||
367 | %destructor { | |
368 | Free($$.value); | |
369 | delete $$.v_value; | |
370 | } | |
371 | XRvalue | |
372 | ||
373 | %destructor { Free($$.token); } | |
374 | XDecodeToken | |
375 | ||
376 | %destructor { | |
377 | FreeNamespaceRestriction($$); | |
378 | } | |
379 | anyAttributes anyElement optNamespaceRestriction urilist | |
380 | ||
381 | %destructor { | |
382 | Free($$.uri); | |
383 | Free($$.prefix); | |
384 | } | |
385 | namespace | |
386 | namespacespecification | |
387 | text | |
388 | controlNamespace | |
389 | ||
390 | %start XAttribSpec | |
391 | ||
392 | %% | |
393 | ||
394 | /* BNF, actions */ | |
395 | ||
396 | XAttribSpec : /* Empty */ | |
397 | | XEncodingDefList | |
398 | { } | |
399 | | XERattributes | |
400 | { } | |
401 | | XBERattributes | |
402 | { } | |
403 | ; | |
404 | ||
405 | XBERattributes : | |
406 | XKWlength XKWaccept XKWshort { berstruct->decode_param = BerAST::LENGTH_ACCEPT_SHORT; ber_f=true; } | |
407 | | XKWlength XKWaccept XKWlong { berstruct->decode_param = BerAST::LENGTH_ACCEPT_LONG; ber_f=true; } | |
408 | | XKWlength XKWaccept XKWindefinite { berstruct->decode_param = BerAST::LENGTH_ACCEPT_INDEFINITE; ber_f=true; } | |
409 | | XKWlength XKWaccept XKWdefinite { berstruct->decode_param = BerAST::LENGTH_ACCEPT_DEFINITE; ber_f=true; } | |
410 | ; | |
411 | ||
412 | XEncodingDefList : XSingleEncodingDef | |
413 | { } | |
414 | | XEncodingDefList ',' XSingleEncodingDef | |
415 | { }; | |
416 | ||
417 | XSingleEncodingDef : XPaddingDef | |
418 | { rawstruct->padding=$1;raw_f=true;} | |
419 | | XPrePaddingDef | |
420 | { rawstruct->prepadding=$1;raw_f=true;} | |
421 | | XPaddingPattern { raw_f=true;} | |
422 | | XPaddAll { rawstruct->paddall=XDEFYES;raw_f=true;} | |
423 | | XFieldOrderDef | |
424 | { rawstruct->fieldorder=$1;raw_f=true;} | |
425 | | XExtensionBitDef | |
426 | { rawstruct->extension_bit=$1;raw_f=true;} | |
427 | | XExtensionBitGroupDef | |
428 | { raw_f=true;} | |
429 | | XLengthToDef | |
430 | { raw_f=true;} | |
431 | | XPointerToDef | |
432 | { delete rawstruct->pointerto; | |
433 | rawstruct->pointerto = $1; | |
434 | raw_f=true; | |
435 | } | |
436 | | XUnitDef | |
437 | { rawstruct->unit=$1; raw_f=true;} | |
438 | | XLengthIndexDef | |
439 | { free_rawAST_field_list(rawstruct->lengthindex); | |
440 | rawstruct->lengthindex = $1;raw_f=true; } | |
441 | | XTagDef | |
442 | {raw_f=true; } | |
443 | | XCrossTagDef | |
444 | {raw_f=true; } | |
445 | | XPresenceDef | |
446 | { raw_f=true;} | |
447 | | XFieldLengthDef | |
448 | { rawstruct->fieldlength = $1*length_multiplier; raw_f=true;} | |
449 | | XPtrOffsetDef | |
450 | { raw_f=true; } | |
451 | | XAlignDef | |
452 | { rawstruct->align = $1; raw_f=true;} | |
453 | | XCompDef | |
454 | { rawstruct->comp = $1;raw_f=true; } | |
455 | | XByteOrderDef | |
456 | { rawstruct->byteorder = $1; raw_f=true;} | |
457 | | XBitOrderInFieldDef | |
458 | { rawstruct->bitorderinfield = $1; raw_f=true;} | |
459 | | XBitOrderInOctetDef | |
460 | { rawstruct->bitorderinoctet = $1; raw_f=true;} | |
461 | | XHexOrderDef | |
462 | { rawstruct->hexorder = $1;raw_f=true; } | |
463 | | XRepeatableDef | |
464 | { rawstruct->repeatable = $1;raw_f=true; } | |
465 | | XToplevelDef | |
466 | { rawstruct->topleveleind=1; raw_f=true;} | |
3abe9331 | 467 | | XIntXKeyword |
468 | { rawstruct->intx = true; raw_f = true; } | |
51fa56b9 | 469 | | XBitDef |
470 | { raw_f = true; } | |
970ed795 EL |
471 | /* TEXT encoder keywords */ |
472 | | XBeginDef | |
473 | { text_f=true; } | |
474 | | XEndDef | |
475 | { text_f=true; } | |
476 | | XSeparatorDef | |
477 | { text_f=true; } | |
478 | | XCodingDef | |
479 | { text_f=true; } | |
480 | | XJsonDef | |
481 | { json_f = true; } | |
482 | ; | |
483 | ||
484 | XRepeatableDef : XRepeatableKeyword '(' XYesOrNo ')' { $$ = $3; } | |
485 | ||
486 | /* Padding*/ | |
487 | XPaddingDef : XPaddingKeyword '(' XYesOrNo ')' { $$ = $3==XDEFYES?8:0; } | |
488 | | XPaddingKeyword '(' XBitsOctets ')' { $$ = $3;}; | |
489 | XPrePaddingDef : XPrePaddingKeyword '(' XYesOrNo ')' { $$ = $3==XDEFYES?8:0; } | |
490 | | XPrePaddingKeyword '(' XBitsOctets ')' { $$ = $3;}; | |
491 | XYesOrNo : XYes | XNo; | |
492 | ||
493 | XPaddingPattern: | |
494 | XPaddingPatternKeyword '(' XBstring ')' | |
495 | { | |
496 | Free(rawstruct->padding_pattern); | |
497 | size_t len = strlen($3); | |
498 | if (len > 0) { | |
499 | rawstruct->padding_pattern = mcopystr($3); | |
500 | rawstruct->padding_pattern_length = len; | |
501 | while (rawstruct->padding_pattern_length % 8 != 0) { | |
502 | rawstruct->padding_pattern = mputstr(rawstruct->padding_pattern, $3); | |
503 | rawstruct->padding_pattern_length += len; | |
504 | } | |
505 | } else rawstruct->padding_pattern = NULL; | |
506 | Free($3); | |
507 | } | |
508 | ; | |
509 | ||
510 | XPaddAll: XPaddAllKeyword | |
511 | /* FieldOrder */ | |
512 | XFieldOrderDef : XFieldOrderKeyword '(' XMsbOrLsb ')' | |
513 | { $$ = $3; }; | |
514 | XMsbOrLsb : XMsb | XLsb; | |
515 | ||
516 | /* Extension bit */ | |
517 | XExtensionBitDef : XExtensionBitKeyword '(' XYesOrNoOrReverse ')' | |
518 | { $$ = $3; }; | |
519 | XYesOrNoOrReverse : XYes | XNo | XReverse; | |
520 | ||
521 | XExtensionBitGroupDef: XExtensionBitGroupKeyword '(' XYesOrNoOrReverse ',' | |
522 | XIdentifier ',' XIdentifier ')' | |
523 | { if(rawstruct->ext_bit_goup_num==0){ | |
524 | rawstruct->ext_bit_groups= | |
525 | (rawAST_ext_bit_group*)Malloc(sizeof(rawAST_ext_bit_group)); | |
526 | rawstruct->ext_bit_goup_num=1; | |
527 | } else{ | |
528 | rawstruct->ext_bit_goup_num++; | |
529 | rawstruct->ext_bit_groups=(rawAST_ext_bit_group*) | |
530 | Realloc(rawstruct->ext_bit_groups, | |
531 | rawstruct->ext_bit_goup_num*sizeof(rawAST_ext_bit_group)); | |
532 | } | |
533 | rawstruct->ext_bit_groups[rawstruct->ext_bit_goup_num-1].ext_bit=$3; | |
534 | rawstruct->ext_bit_groups[rawstruct->ext_bit_goup_num-1].from=$5; | |
535 | rawstruct->ext_bit_groups[rawstruct->ext_bit_goup_num-1].to=$7; | |
536 | } | |
537 | ||
538 | /* LengthTo */ | |
539 | XLengthToDef : XLengthToKeyword '(' XRecordFieldRefList ')' | |
540 | { }; | |
541 | ||
542 | /* PointerTo */ | |
543 | XPointerToDef : XPointerToKeyword '(' XRecordFieldRef ')' | |
544 | { $$ = $3; }; | |
545 | ||
546 | /* Unit */ | |
547 | XUnitDef : XUnitKeyword '(' XBitsOctets ')' { $$ = $3; } | |
548 | | XPtrUnitKeyword '(' XBitsOctets ')' { $$ = $3; }; | |
549 | XBitsOctets : XBits {$$=$1;} | |
550 | | XOctets {$$=$1;} | |
551 | | XNumber {$$=$1;}; | |
552 | ||
553 | /* LengthIndex */ | |
554 | XLengthIndexDef : XLengthIndexKeyword '(' XStructFieldRefOrEmpty ')' | |
555 | { $$ = $3; }; | |
556 | ||
557 | ||
558 | /* Tag, Crosstag */ | |
559 | XTagDef : XTagKeyword '(' XAssocList XoptSemiColon ')' | |
560 | { free_rawAST_tag_list(&(rawstruct->taglist)); | |
561 | link_rawAST_tag_list(&(rawstruct->taglist),&$3);}; | |
562 | XCrossTagDef : XCrossTagKeyword '(' XAssocList XoptSemiColon ')' | |
563 | { free_rawAST_tag_list(&(rawstruct->crosstaglist)); | |
564 | link_rawAST_tag_list(&(rawstruct->crosstaglist),&$3);}; | |
565 | ||
566 | XAssocList: | |
567 | XAssocElement | |
568 | { | |
569 | $$.nElements = 1; | |
570 | $$.tag = (rawAST_single_tag*)Malloc(sizeof(*$$.tag)); | |
571 | link_rawAST_single_tag($$.tag, &$1); | |
572 | } | |
573 | | XAssocList XSemiColon XAssocElement | |
574 | { | |
575 | int dupl_id_index = -1; | |
576 | if ($3.nElements > 0) { | |
577 | /* the otherwise element is never merged */ | |
578 | for (int i = 0; i < $1.nElements; i++) | |
579 | if (*$1.tag[i].fieldName == *$3.fieldName) { | |
580 | dupl_id_index = i; | |
581 | break; | |
582 | } | |
583 | } | |
584 | if (dupl_id_index >= 0) { | |
585 | /* this identifier is already specified in XAssocList | |
586 | merge the new parameters to the existing entry */ | |
587 | $$ = $1; | |
588 | rawAST_single_tag *tag = $$.tag + dupl_id_index; | |
589 | tag->keyList = (rawAST_tag_field_value*) | |
590 | Realloc(tag->keyList, (tag->nElements + $3.nElements) | |
591 | * sizeof(*tag->keyList)); | |
592 | memcpy(tag->keyList + tag->nElements, $3.keyList, | |
593 | $3.nElements * sizeof(*$3.keyList)); | |
594 | tag->nElements += $3.nElements; | |
595 | delete $3.fieldName; | |
596 | Free($3.keyList); | |
597 | } else { | |
598 | $$.nElements = $1.nElements + 1; | |
599 | $$.tag = (rawAST_single_tag*) | |
600 | Realloc($1.tag, $$.nElements * sizeof(*$$.tag)); | |
601 | $$.tag[$1.nElements] = $3; | |
602 | } | |
603 | } | |
604 | ; | |
605 | ||
606 | XSemiColon: | |
607 | ';' | |
608 | ; | |
609 | ||
610 | XoptSemiColon: | |
611 | /* Empty */ | |
612 | | ';' | |
613 | ; | |
614 | ||
615 | XAssocElement: | |
616 | XIdentifier ',' XKeyIdOrIdList | |
617 | { | |
618 | $$.fieldName = $1; | |
619 | $$.nElements = $3.nElements; | |
620 | $$.keyList = $3.keyList; | |
621 | } | |
622 | | XIdentifier ',' XOtherwise | |
623 | { | |
624 | $$.fieldName = $1; | |
625 | $$.nElements = 0; | |
626 | $$.keyList = NULL; | |
627 | } | |
628 | ; | |
629 | ||
630 | XKeyIdOrIdList: | |
631 | XKeyId | |
632 | { | |
633 | $$.fieldName = NULL; | |
634 | $$.nElements = 1; | |
635 | $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList)); | |
636 | $$.keyList[0] = $1; | |
637 | } | |
638 | | XKeyIdList { $$ = $1; } | |
639 | ; | |
640 | ||
641 | XKeyIdList: | |
642 | '{' XMultiKeyId '}' { $$ = $2; } | |
643 | ; | |
644 | ||
645 | XMultiKeyId: | |
646 | XKeyId | |
647 | { | |
648 | $$.fieldName = NULL; | |
649 | $$.nElements = 1; | |
650 | $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList)); | |
651 | $$.keyList[0] = $1; | |
652 | } | |
653 | | XMultiKeyId ',' XKeyId | |
654 | { | |
655 | $$.fieldName = NULL; | |
656 | $$.nElements = $1.nElements + 1; | |
657 | $$.keyList = (rawAST_tag_field_value*) | |
658 | Realloc($1.keyList, $$.nElements * sizeof(*$$.keyList)); | |
659 | $$.keyList[$1.nElements] = $3; | |
660 | } | |
661 | ; | |
662 | ||
663 | XKeyId: | |
664 | XStructFieldRef '=' XRvalue | |
665 | { | |
666 | $$.keyField = $1; | |
667 | $$.value = $3.value; | |
668 | $$.v_value = $3.v_value; | |
669 | } | |
670 | ; | |
671 | ||
672 | /* Presence */ | |
673 | XPresenceDef : XPresenceKeyword '(' XKeyIdList XoptSemiColon ')' | |
674 | { free_rawAST_single_tag(&(rawstruct->presence)); | |
675 | link_rawAST_single_tag(&(rawstruct->presence), &$3);} | |
676 | | XPresenceKeyword '(' XMultiKeyId XoptSemiColon ')' | |
677 | { free_rawAST_single_tag(&(rawstruct->presence)); | |
678 | link_rawAST_single_tag(&(rawstruct->presence), &$3);}; | |
679 | ||
680 | ||
681 | /* FieldLength */ | |
682 | XFieldLengthDef : XFieldLengthKeyword '(' XNumber ')' | |
683 | { $$ = $3;}; | |
684 | ||
685 | /* PtrOffset */ | |
686 | XPtrOffsetDef : XPtrOffsetKeyword '(' XNumber ')' | |
687 | { rawstruct->ptroffset = $3; } | |
688 | |XPtrOffsetKeyword '(' XIdentifier ')' | |
689 | { | |
690 | delete rawstruct->ptrbase; | |
691 | rawstruct->ptrbase = $3; | |
692 | } | |
693 | /* Align */ | |
694 | XAlignDef : XAlignKeyword '(' XLeftOrRight ')' | |
695 | { $$ = $3; }; | |
696 | XLeftOrRight : XLeft | XRight; | |
697 | ||
698 | /* Comp */ | |
699 | XCompDef : XCompKeyword '(' XCompValues ')' | |
700 | { $$ = $3; }; | |
701 | XCompValues : XUnsigned | XCompl | XSignbit; | |
702 | ||
703 | /* ByteOrder */ | |
704 | XByteOrderDef : XByteOrderKeyword '(' XFirstOrLast ')' | |
705 | { $$ = $3; }; | |
706 | XFirstOrLast : XFirst | XLast; | |
707 | ||
708 | /* BitOrder */ | |
709 | XBitOrderInFieldDef : XBitOrderInFieldKeyword '(' XMsbOrLsb ')' | |
710 | { $$ = $3; }; | |
711 | XBitOrderInOctetDef : XBitOrderInOctetKeyword '(' XMsbOrLsb ')' | |
712 | { $$ = $3; } | |
713 | | XBitOrderKeyword '(' XMsbOrLsb ')' { $$ = $3; }; | |
714 | XToplevelDef : XToplevelKeyword '(' XTopDefList ')' | |
715 | { }; | |
716 | XTopDefList : XTopDef | |
717 | { } | |
718 | | XTopDefList ',' XTopDef | |
719 | { }; | |
720 | XTopDef : XBitOrderDef | |
721 | { rawstruct->toplevel.bitorder = $1;}; | |
722 | XBitOrderDef : XBitOrderKeyword '(' XMsbOrLsb ')' | |
723 | { $$ = $3; }; | |
724 | ||
725 | /* HexOrder */ | |
726 | XHexOrderDef : XHexOrderKeyword '(' XLowOrHigh ')' | |
727 | { $$ = $3; }; | |
728 | XLowOrHigh : XLow | XHigh; | |
729 | ||
730 | /* General types */ | |
731 | /* FieldRefList */ | |
732 | XRecordFieldRefList : XRecordFieldRef | |
733 | { rawstruct->lengthto_num = 1; | |
734 | rawstruct->lengthto = | |
735 | (Common::Identifier**)Malloc(sizeof(*(rawstruct->lengthto))); | |
736 | rawstruct->lengthto[0] = $1; | |
737 | } | |
738 | | XRecordFieldRefList ',' XRecordFieldRef | |
739 | { rawstruct->lengthto_num++; | |
740 | rawstruct->lengthto = | |
741 | (Common::Identifier**)Realloc(rawstruct->lengthto, | |
742 | rawstruct->lengthto_num*sizeof(*(rawstruct->lengthto))); | |
743 | rawstruct->lengthto[rawstruct->lengthto_num - 1] = $3; | |
744 | } | |
745 | ; | |
746 | ||
747 | XRecordFieldRef : XIdentifier | |
748 | { $$ = $1; }; | |
749 | ||
750 | XStructFieldRefOrEmpty : /* Empty */ | |
751 | { $$ = NULL;} | |
752 | | XStructFieldRef | |
753 | { $$ = $1; }; | |
754 | ||
755 | XStructFieldRef : XIdentifier | |
756 | { $$ = (rawAST_field_list*)Malloc(sizeof(*$$)); | |
757 | $$->nElements=1; | |
758 | $$->names = (Common::Identifier**)Malloc(sizeof(*($$->names))); | |
759 | $$->names[0] = $1; | |
760 | } | |
761 | | XStructFieldRef '.' XIdentifier | |
762 | { $$ = $1; | |
763 | $$->nElements++; | |
764 | $$->names = (Common::Identifier**) | |
765 | Realloc($$->names, $$->nElements*sizeof(*($$->names))); | |
766 | $$->names[$$->nElements - 1] = $3; | |
767 | } | |
768 | ; | |
769 | ||
770 | XRvalue: XIdentifier{ | |
771 | $$.value = mcopystr($1->get_name().c_str()); | |
772 | $$.v_value = new Common::Value(Common::Value::V_UNDEF_LOWERID, $1); | |
773 | $$.v_value->set_location(infile, @$); | |
774 | } | |
775 | | XBstring{ | |
776 | string *str= new string($1); | |
777 | $$.value=mprintf(" %s", mymod->add_bitstring_literal(*str).c_str()); | |
778 | $$.v_value=new Common::Value(Common::Value::V_BSTR,str); | |
779 | $$.v_value->set_location(infile, @$); | |
780 | Free($1); | |
781 | } | |
782 | | XHstring{ | |
783 | string *str= new string($1); | |
784 | $$.value=mprintf(" %s", mymod->add_hexstring_literal(*str).c_str()); | |
785 | $$.v_value=new Common::Value(Common::Value::V_HSTR,str); | |
786 | $$.v_value->set_location(infile, @$); | |
787 | Free($1); | |
788 | } | |
789 | ||
790 | | XOstring{ | |
791 | string *str= new string($1); | |
792 | $$.value=mprintf(" %s", mymod->add_octetstring_literal(*str).c_str()); | |
793 | $$.v_value=new Common::Value(Common::Value::V_OSTR,str); | |
794 | $$.v_value->set_location(infile, @$); | |
795 | Free($1); | |
796 | } | |
797 | | XCstring{ | |
798 | Common::Location loc(infile, @$); | |
799 | string *str = parse_charstring_value($1, loc); | |
800 | Free($1); | |
801 | $$.value=mprintf(" %s", mymod->add_charstring_literal(*str).c_str()); | |
802 | $$.v_value=new Common::Value(Common::Value::V_CSTR,str); | |
803 | $$.v_value->set_location(loc); | |
804 | } | |
805 | | XFloatValue{ | |
806 | $$.value=mcopystr(Common::Real2code($1).c_str()); | |
807 | $$.v_value=new Common::Value(Common::Value::V_REAL, $1); | |
808 | $$.v_value->set_location(infile, @$); | |
809 | } | |
810 | | XNumber{ | |
811 | $$.value = mcopystr(Common::Int2string($1).c_str()); | |
812 | $$.v_value=new Common::Value(Common::Value::V_INT, $1); | |
813 | $$.v_value->set_location(infile, @$); | |
814 | } | |
815 | | XBooleanConst | |
816 | { | |
817 | $$.value = mcopystr($1 ? "TRUE" : "FALSE"); | |
818 | $$.v_value=new Common::Value(Common::Value::V_BOOL, $1); | |
819 | $$.v_value->set_location(infile, @$); | |
820 | } | |
821 | | XVerdictConst | |
822 | { | |
823 | $$.v_value = new Common::Value(Common::Value::V_VERDICT, $1); | |
824 | $$.v_value->set_location(infile, @$); | |
825 | $$.value = mcopystr($$.v_value->get_single_expr().c_str()); | |
826 | } | |
827 | | XNullKeyword | |
828 | { | |
829 | $$.value = mcopystr("NULL_COMPREF"); | |
830 | $$.v_value = new Common::Value(Common::Value::V_TTCN3_NULL); | |
831 | $$.v_value->set_location(infile, @$); | |
832 | } | |
833 | | XNULLKeyword | |
834 | { | |
835 | $$.value = mcopystr("ASN_NULL_VALUE"); | |
836 | $$.v_value = new Common::Value(Common::Value::V_NULL); | |
837 | $$.v_value->set_location(infile, @$); | |
838 | } | |
839 | | XOmitKeyword | |
840 | { | |
841 | $$.value = mcopystr("OMIT_VALUE"); | |
842 | $$.v_value = new Common::Value(Common::Value::V_OMIT); | |
843 | $$.v_value->set_location(infile, @$); | |
844 | } | |
845 | ; | |
846 | ||
51fa56b9 | 847 | /* Alternative RAW attributes for types defined in annex E of the TTCN-3 standard */ |
848 | XBitDef: | |
849 | XNumber XBitKeyword | |
850 | { | |
851 | rawstruct->fieldlength = $1; | |
852 | rawstruct->comp = XDEFSIGNBIT; | |
853 | rawstruct->byteorder = XDEFLAST; | |
854 | } | |
855 | | XUnsignedKeyword XNumber XBitKeyword | |
856 | { | |
857 | rawstruct->fieldlength = $2; | |
858 | rawstruct->comp = XDEFUNSIGNED; | |
859 | rawstruct->byteorder = XDEFLAST; | |
860 | } | |
861 | ; | |
862 | ||
970ed795 EL |
863 | /* Text encoder */ |
864 | XBeginDef: | |
865 | XBeginKeyword '(' XEncodeToken ')' { | |
866 | if(textstruct->begin_val==NULL){ | |
867 | textstruct->begin_val=(textAST_matching_values*) | |
868 | Malloc(sizeof(textAST_matching_values)); | |
869 | init_textAST_matching_values(textstruct->begin_val); | |
870 | } | |
871 | Free(textstruct->begin_val->encode_token); | |
872 | textstruct->begin_val->encode_token=$3; | |
873 | } | |
874 | | XBeginKeyword '(' XEncodeToken ',' XmatchDef ')' { | |
875 | if(textstruct->begin_val==NULL){ | |
876 | textstruct->begin_val=(textAST_matching_values*) | |
877 | Malloc(sizeof(textAST_matching_values)); | |
878 | init_textAST_matching_values(textstruct->begin_val); | |
879 | } | |
880 | Free(textstruct->begin_val->encode_token); | |
881 | textstruct->begin_val->encode_token=$3; | |
882 | if($5){ | |
883 | Free(textstruct->begin_val->decode_token); | |
884 | textstruct->begin_val->decode_token=$5; | |
885 | } | |
886 | } | |
887 | | XBeginKeyword '(' XEncodeToken ',' XmatchDef ',' XmodifierDef ')'{ | |
888 | if(textstruct->begin_val==NULL){ | |
889 | textstruct->begin_val=(textAST_matching_values*) | |
890 | Malloc(sizeof(textAST_matching_values)); | |
891 | init_textAST_matching_values(textstruct->begin_val); | |
892 | } | |
893 | Free(textstruct->begin_val->encode_token); | |
894 | textstruct->begin_val->encode_token=$3; | |
895 | if($5){ | |
896 | Free(textstruct->begin_val->decode_token); | |
897 | textstruct->begin_val->decode_token=$5; | |
898 | } | |
899 | textstruct->begin_val->case_sensitive=$7; | |
900 | } | |
901 | ; | |
902 | ||
903 | XEndDef: | |
904 | XEndKeyword '(' XEncodeToken ')' { | |
905 | if(textstruct->end_val==NULL){ | |
906 | textstruct->end_val=(textAST_matching_values*) | |
907 | Malloc(sizeof(textAST_matching_values)); | |
908 | init_textAST_matching_values(textstruct->end_val); | |
909 | } | |
910 | Free(textstruct->end_val->encode_token); | |
911 | textstruct->end_val->encode_token=$3; | |
912 | } | |
913 | | XEndKeyword '(' XEncodeToken ',' XmatchDef ')'{ | |
914 | if(textstruct->end_val==NULL){ | |
915 | textstruct->end_val=(textAST_matching_values*) | |
916 | Malloc(sizeof(textAST_matching_values)); | |
917 | init_textAST_matching_values(textstruct->end_val); | |
918 | } | |
919 | Free(textstruct->end_val->encode_token); | |
920 | textstruct->end_val->encode_token=$3; | |
921 | if($5){ | |
922 | Free(textstruct->end_val->decode_token); | |
923 | textstruct->end_val->decode_token=$5; | |
924 | } | |
925 | } | |
926 | | XEndKeyword '(' XEncodeToken ',' XmatchDef ',' XmodifierDef ')'{ | |
927 | if(textstruct->end_val==NULL){ | |
928 | textstruct->end_val=(textAST_matching_values*) | |
929 | Malloc(sizeof(textAST_matching_values)); | |
930 | init_textAST_matching_values(textstruct->end_val); | |
931 | } | |
932 | Free(textstruct->end_val->encode_token); | |
933 | textstruct->end_val->encode_token=$3; | |
934 | if($5){ | |
935 | Free(textstruct->end_val->decode_token); | |
936 | textstruct->end_val->decode_token=$5; | |
937 | } | |
938 | textstruct->end_val->case_sensitive=$7; | |
939 | } | |
940 | ; | |
941 | ||
942 | XSeparatorDef: | |
943 | XSeparatorKeyword '(' XEncodeToken ')'{ | |
944 | if(textstruct->separator_val==NULL){ | |
945 | textstruct->separator_val=(textAST_matching_values*) | |
946 | Malloc(sizeof(textAST_matching_values)); | |
947 | init_textAST_matching_values(textstruct->separator_val); | |
948 | } | |
949 | Free(textstruct->separator_val->encode_token); | |
950 | textstruct->separator_val->encode_token=$3; | |
951 | } | |
952 | | XSeparatorKeyword '(' XEncodeToken ',' XmatchDef ')'{ | |
953 | if(textstruct->separator_val==NULL){ | |
954 | textstruct->separator_val=(textAST_matching_values*) | |
955 | Malloc(sizeof(textAST_matching_values)); | |
956 | init_textAST_matching_values(textstruct->separator_val); | |
957 | } | |
958 | Free(textstruct->separator_val->encode_token); | |
959 | textstruct->separator_val->encode_token=$3; | |
960 | if($5){ | |
961 | Free(textstruct->separator_val->decode_token); | |
962 | textstruct->separator_val->decode_token=$5; | |
963 | } | |
964 | } | |
965 | | XSeparatorKeyword '(' XEncodeToken ',' XmatchDef ',' XmodifierDef ')'{ | |
966 | if(textstruct->separator_val==NULL){ | |
967 | textstruct->separator_val=(textAST_matching_values*) | |
968 | Malloc(sizeof(textAST_matching_values)); | |
969 | init_textAST_matching_values(textstruct->separator_val); | |
970 | } | |
971 | Free(textstruct->separator_val->encode_token); | |
972 | textstruct->separator_val->encode_token=$3; | |
973 | if($5){ | |
974 | Free(textstruct->separator_val->decode_token); | |
975 | textstruct->separator_val->decode_token=$5; | |
976 | } | |
977 | textstruct->separator_val->case_sensitive=$7; | |
978 | } | |
979 | ; | |
980 | ||
981 | XCodingDef: | |
982 | XCodingKeyword '(' XCodingRule ')' | |
983 | { } | |
984 | | XCodingKeyword '(' XCodingRule ',' XDecodingRule ')' | |
985 | { } | |
986 | | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ')' { | |
987 | Free(textstruct->decode_token); | |
988 | textstruct->decode_token=$7; | |
989 | } | |
990 | | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ',' | |
991 | XmodifierDef ')' { | |
992 | if($7){ | |
993 | Free(textstruct->decode_token); | |
994 | textstruct->decode_token=$7; | |
995 | } | |
996 | textstruct->case_sensitive=$9; | |
997 | } | |
998 | ; | |
999 | ||
1000 | XCodingRule: | |
1001 | /* empty */ {} | |
1002 | | Xattrlistenc {} | |
1003 | | XtokendefList {} | |
1004 | ; | |
1005 | ||
1006 | XDecodingRule: | |
1007 | /* empty */ {} | |
1008 | | XattrList {} | |
1009 | | XDecodingtokendefList {} | |
1010 | ; | |
1011 | ||
1012 | XattrList: | |
1013 | Xattr {} | |
1014 | | XattrList ';' Xattr {} | |
1015 | ; | |
1016 | ||
1017 | Xattr: | |
1018 | XLengthToken '=' XNumber { | |
1019 | textstruct->decoding_params.min_length=$3; | |
1020 | } | |
1021 | | XLengthToken '=' XNumber '-' XNumber { | |
1022 | textstruct->decoding_params.min_length=$3; | |
1023 | textstruct->decoding_params.max_length=$5; | |
1024 | } | |
1025 | | XConvertToken '=' XLowerToken { | |
1026 | textstruct->decoding_params.convert=-1; | |
1027 | } | |
1028 | | XConvertToken '=' XUpperToken { | |
1029 | textstruct->decoding_params.convert=1; | |
1030 | } | |
1031 | | XJustToken '=' XLeftToken { | |
1032 | textstruct->decoding_params.just=-1; | |
1033 | } | |
1034 | | XJustToken '=' XRightToken { | |
1035 | textstruct->decoding_params.just=1; | |
1036 | } | |
1037 | | XJustToken '=' XCenterToken { | |
1038 | textstruct->decoding_params.just=0; | |
1039 | } | |
1040 | | XLeadingToken '=' XTrueToken { | |
1041 | textstruct->decoding_params.leading_zero=true; | |
1042 | } | |
1043 | | XLeadingToken '=' XFalseToken { | |
1044 | textstruct->decoding_params.leading_zero=false; | |
1045 | } | |
1046 | | XRepeatToken '=' XTrueToken { | |
1047 | textstruct->decoding_params.repeatable=true; | |
1048 | } | |
1049 | | XRepeatToken '=' XFalseToken { | |
1050 | textstruct->decoding_params.repeatable=false; | |
1051 | }; | |
1052 | ||
1053 | Xattrlistenc: | |
1054 | Xattrenc {} | |
1055 | | Xattrlistenc ';' Xattrenc {} | |
1056 | ; | |
1057 | ||
1058 | Xattrenc: | |
1059 | XLengthToken '=' XNumber { | |
1060 | textstruct->coding_params.min_length=$3; | |
1061 | textstruct->decoding_params.min_length=$3; | |
1062 | } | |
1063 | | XLengthToken '=' XNumber '-' XNumber { | |
1064 | textstruct->coding_params.min_length=$3; | |
1065 | textstruct->coding_params.max_length=$5; | |
1066 | textstruct->decoding_params.min_length=$3; | |
1067 | textstruct->decoding_params.max_length=$5; | |
1068 | } | |
1069 | | XConvertToken '=' XLowerToken { | |
1070 | textstruct->coding_params.convert=-1; | |
1071 | textstruct->decoding_params.convert=-1; | |
1072 | } | |
1073 | | XConvertToken '=' XUpperToken { | |
1074 | textstruct->coding_params.convert=1; | |
1075 | textstruct->decoding_params.convert=1; | |
1076 | } | |
1077 | | XJustToken '=' XLeftToken { | |
1078 | textstruct->coding_params.just=-1; | |
1079 | textstruct->decoding_params.just=-1; | |
1080 | } | |
1081 | | XJustToken '=' XRightToken { | |
1082 | textstruct->coding_params.just=1; | |
1083 | textstruct->decoding_params.just=1; | |
1084 | } | |
1085 | | XJustToken '=' XCenterToken { | |
1086 | textstruct->coding_params.just=0; | |
1087 | textstruct->decoding_params.just=0; | |
1088 | } | |
1089 | | XLeadingToken '=' XTrueToken { | |
1090 | textstruct->coding_params.leading_zero=true; | |
1091 | textstruct->decoding_params.leading_zero=true; | |
1092 | } | |
1093 | | XLeadingToken '=' XFalseToken { | |
1094 | textstruct->coding_params.leading_zero=false; | |
1095 | textstruct->decoding_params.leading_zero=false; | |
1096 | } | |
1097 | | XRepeatToken '=' XTrueToken { | |
1098 | textstruct->coding_params.repeatable=true; | |
1099 | textstruct->decoding_params.repeatable=true; | |
1100 | } | |
1101 | | XRepeatToken '=' XFalseToken { | |
1102 | textstruct->coding_params.repeatable=false; | |
1103 | textstruct->decoding_params.repeatable=false; | |
1104 | }; | |
1105 | ||
1106 | ||
1107 | XtokendefList: | |
1108 | Xtokendef {} | |
1109 | | XtokendefList ';' Xtokendef {} | |
1110 | ; | |
1111 | ||
1112 | Xtokendef: | |
1113 | XIdentifierOrReserved ':' XEncodeToken | |
1114 | { | |
1115 | int idx = textstruct->get_field_param_index($1); | |
1116 | if (textstruct->field_params[idx]->value.encode_token) { | |
1117 | Free(textstruct->field_params[idx]->value.encode_token); | |
1118 | Common::Location loc(infile, @3); | |
1119 | loc.error("Duplicate encode token for value `%s'", | |
1120 | $1->get_dispname().c_str()); | |
1121 | } | |
1122 | textstruct->field_params[idx]->value.encode_token = $3; | |
1123 | delete $1; | |
1124 | } | |
1125 | | XTrueToken ':' XEncodeToken | |
1126 | { | |
1127 | if (textstruct->true_params == NULL) { | |
1128 | textstruct->true_params = (textAST_matching_values*) | |
1129 | Malloc(sizeof(textAST_matching_values)); | |
1130 | textstruct->true_params->encode_token = $3; | |
1131 | textstruct->true_params->decode_token = NULL; | |
1132 | textstruct->true_params->case_sensitive = true; | |
1133 | textstruct->true_params->generated_decode_token = false; | |
1134 | } else { | |
1135 | if (textstruct->true_params->encode_token) { | |
1136 | Free(textstruct->true_params->encode_token); | |
1137 | Common::Location loc(infile, @3); | |
1138 | loc.error("Duplicate encode token for true value"); | |
1139 | } | |
1140 | textstruct->true_params->encode_token = $3; | |
1141 | } | |
1142 | } | |
1143 | | XFalseToken ':' XEncodeToken | |
1144 | { | |
1145 | if (textstruct->false_params == NULL) { | |
1146 | textstruct->false_params = (textAST_matching_values*) | |
1147 | Malloc(sizeof(textAST_matching_values)); | |
1148 | textstruct->false_params->encode_token = $3; | |
1149 | textstruct->false_params->decode_token = NULL; | |
1150 | textstruct->false_params->case_sensitive = true; | |
1151 | textstruct->false_params->generated_decode_token = false; | |
1152 | } else { | |
1153 | if (textstruct->false_params->encode_token) { | |
1154 | Free(textstruct->false_params->encode_token); | |
1155 | Common::Location loc(infile, @3); | |
1156 | loc.error("Duplicate encode token for false value"); | |
1157 | } | |
1158 | textstruct->false_params->encode_token = $3; | |
1159 | } | |
1160 | } | |
1161 | ; | |
1162 | ||
1163 | XIdentifierOrReserved: | |
1164 | XIdentifier { $$ = $1; } | |
1165 | | XTextReservedWord | |
1166 | { $$ = new Common::Identifier(Common::Identifier::ID_TTCN, string($1)); } | |
1167 | ; | |
1168 | ||
1169 | XTextReservedWord: | |
1170 | XLengthToken { $$ = "length"; } | |
1171 | | XRepeatToken { $$ = "repeatable"; } | |
1172 | | XConvertToken { $$ = "convert"; } | |
1173 | | XLowerToken { $$ = "lower_case"; } | |
1174 | | XUpperToken { $$ = "upper_case"; } | |
1175 | | XJustToken { $$ = "just"; } | |
1176 | | XLeftToken { $$ = "left"; } | |
1177 | | XRightToken { $$ = "right"; } | |
1178 | | XCenterToken { $$ = "center"; } | |
1179 | | XLeadingToken { $$ = "leading0"; } | |
1180 | | XSensitivToken { $$ = "case_sensitive"; } | |
1181 | | XInSensitivToken { $$ = "case_insensitive"; } | |
1182 | ; | |
1183 | ||
1184 | XDecodingtokendefList: | |
1185 | Xdecodingtokendef {} | |
1186 | | XDecodingtokendefList ';' Xdecodingtokendef {} | |
1187 | ; | |
1188 | ||
1189 | Xdecodingtokendef: | |
1190 | XIdentifierOrReserved ':' XDecodeToken | |
1191 | { | |
1192 | int idx = textstruct->get_field_param_index($1); | |
1193 | if (textstruct->field_params[idx]->value.decode_token) { | |
1194 | Free(textstruct->field_params[idx]->value.decode_token); | |
1195 | Common::Location loc(infile, @3); | |
1196 | loc.error("Duplicate decode token for value `%s'", | |
1197 | $1->get_dispname().c_str()); | |
1198 | } | |
1199 | textstruct->field_params[idx]->value.decode_token = $3.token; | |
1200 | textstruct->field_params[idx]->value.case_sensitive = $3.case_sensitive; | |
1201 | delete $1; | |
1202 | } | |
1203 | | XTrueToken ':' XDecodeToken | |
1204 | { | |
1205 | if (textstruct->true_params == NULL) { | |
1206 | textstruct->true_params = (textAST_matching_values*) | |
1207 | Malloc(sizeof(textAST_matching_values)); | |
1208 | textstruct->true_params->encode_token = NULL; | |
1209 | textstruct->true_params->decode_token = $3.token; | |
1210 | textstruct->true_params->case_sensitive = $3.case_sensitive; | |
1211 | textstruct->true_params->generated_decode_token = false; | |
1212 | } else { | |
1213 | if (textstruct->true_params->decode_token) { | |
1214 | Free(textstruct->true_params->decode_token); | |
1215 | Common::Location loc(infile, @3); | |
1216 | loc.error("Duplicate decode token for true value"); | |
1217 | } | |
1218 | textstruct->true_params->decode_token = $3.token; | |
1219 | textstruct->true_params->case_sensitive = $3.case_sensitive; | |
1220 | } | |
1221 | } | |
1222 | | XFalseToken ':' XDecodeToken | |
1223 | { | |
1224 | if (textstruct->false_params == NULL) { | |
1225 | textstruct->false_params = (textAST_matching_values*) | |
1226 | Malloc(sizeof(textAST_matching_values)); | |
1227 | textstruct->false_params->encode_token = NULL; | |
1228 | textstruct->false_params->decode_token= $3.token; | |
1229 | textstruct->false_params->case_sensitive = $3.case_sensitive; | |
1230 | textstruct->false_params->generated_decode_token = false; | |
1231 | } else { | |
1232 | if (textstruct->false_params->decode_token) { | |
1233 | Free(textstruct->false_params->decode_token); | |
1234 | Common::Location loc(infile, @3); | |
1235 | loc.error("Duplicate decode token for false value"); | |
1236 | } | |
1237 | textstruct->false_params->decode_token = $3.token; | |
1238 | textstruct->false_params->case_sensitive = $3.case_sensitive; | |
1239 | } | |
1240 | } | |
1241 | ; | |
1242 | ||
1243 | XEncodeToken: | |
1244 | Xtoken | |
1245 | { | |
1246 | Common::Location loc(infile, @$); | |
1247 | string *str = parse_charstring_value($1, loc); | |
1248 | Free($1); | |
1249 | $$ = mcopystr(str->c_str()); | |
1250 | delete str; | |
1251 | } | |
1252 | ; | |
1253 | ||
1254 | XDecodeToken: | |
1255 | Xtoken | |
1256 | { | |
1257 | $$.token = $1; | |
1258 | $$.case_sensitive = true; | |
1259 | } | |
1260 | | '{' Xtoken '}' | |
1261 | { | |
1262 | $$.token = $2; | |
1263 | $$.case_sensitive = true; | |
1264 | } | |
1265 | | '{' XmatchDef ',' XmodifierDef '}' | |
1266 | { | |
1267 | $$.token = $2; | |
1268 | $$.case_sensitive = $4; | |
1269 | } | |
1270 | ; | |
1271 | ||
1272 | XmatchDef: | |
1273 | /* empty */ { $$ = NULL; } | |
1274 | | Xtoken { $$ = $1; } | |
1275 | ; | |
1276 | ||
1277 | XmodifierDef: | |
1278 | /* empty */ { $$ = true; } | |
1279 | | XSensitivToken { $$ = true; } | |
1280 | | XInSensitivToken { $$ = false; } | |
1281 | ; | |
1282 | ||
1283 | /********** XERSTUFF "raw" attributes */ | |
1284 | ||
1285 | XERattributes: /* a non-empty list */ | |
1286 | XERattribute { xer_f = true; } | |
1287 | ; | |
1288 | ||
1289 | XERattribute: | |
51fa56b9 | 1290 | XKWabstract { xerstruct->abstract_ = true; } |
1291 | | anyAttributes { FreeNamespaceRestriction(xerstruct->anyAttributes_); xerstruct->anyAttributes_ = $1; } | |
970ed795 EL |
1292 | | anyElement { FreeNamespaceRestriction(xerstruct->anyElement_); xerstruct->anyElement_ = $1; } |
1293 | | XKWattribute { xerstruct->attribute_ = true; } | |
1294 | | XKWattributeFormQualified { xerstruct->form_ |= XerAttributes::ATTRIBUTE_DEFAULT_QUALIFIED; } | |
51fa56b9 | 1295 | | XKWblock { xerstruct->block_ = true; } |
970ed795 EL |
1296 | | controlNamespace /* directly on the module */ |
1297 | { | |
1298 | mymod->set_controlns($1.uri, $1.prefix); | |
1299 | } | |
1300 | | defaultForEmpty { xerstruct->defaultForEmpty_ = $1; } | |
1301 | | XKWelement { xerstruct->element_ = true; } | |
1302 | | XKWelementFormQualified { xerstruct->form_ |= XerAttributes::ELEMENT_DEFAULT_QUALIFIED; } | |
1303 | | XKWembedValues { xerstruct->embedValues_ = true; } | |
1304 | | form { xerstruct->form_ |= $1; } | |
1305 | | XKWlist { xerstruct->list_ = true; } | |
1306 | | name | |
1307 | { /* overwrites any previous name */ | |
1308 | switch (xerstruct->name_.kw_) { | |
1309 | case NamespaceSpecification::NO_MANGLING: | |
1310 | case NamespaceSpecification::CAPITALIZED: | |
1311 | case NamespaceSpecification::UNCAPITALIZED: | |
1312 | case NamespaceSpecification::UPPERCASED: | |
1313 | case NamespaceSpecification::LOWERCASED: | |
1314 | break; // nothing to do | |
1315 | default: // real string, must be freed | |
1316 | Free(xerstruct->name_.nn_); | |
1317 | } | |
1318 | xerstruct->name_.nn_ = $1; | |
1319 | } | |
1320 | | namespace | |
1321 | { /* overwrites any previous namespace */ | |
1322 | Free(xerstruct->namespace_.uri); | |
1323 | Free(xerstruct->namespace_.prefix); | |
1324 | xerstruct->namespace_ = $1; | |
1325 | } | |
1326 | | text | |
1327 | { | |
1328 | xerstruct->text_ = (NamespaceSpecification *)Realloc(xerstruct->text_, | |
1329 | ++xerstruct->num_text_ * sizeof(NamespaceSpecification)); | |
1330 | xerstruct->text_[xerstruct->num_text_-1] = $1; | |
1331 | } | |
1332 | | XKWuntagged { xerstruct->untagged_ = true; } | |
1333 | | XKWuseNil { xerstruct->useNil_ = true; } | |
1334 | | XKWuseNumber { xerstruct->useNumber_ = true; } | |
1335 | | XKWuseOrder { xerstruct->useOrder_ = true; } | |
1336 | | XKWuseUnion { xerstruct->useUnion_ = true; } | |
1337 | | XKWuseType { xerstruct->useType_ = true; } | |
1338 | | whiteSpace | |
1339 | { | |
1340 | xerstruct->whitespace_ = static_cast<XerAttributes::WhitespaceAction>($1); | |
1341 | } | |
1342 | | XSD ':' xsddata {} | |
1343 | ; | |
1344 | ||
1345 | anyAttributes: | |
1346 | XKWanyAttributes optNamespaceRestriction | |
1347 | { $$ = $2; } | |
1348 | ; | |
1349 | ||
1350 | anyElement: | |
1351 | XKWanyElement optNamespaceRestriction | |
1352 | { $$ = $2; } | |
1353 | ; | |
1354 | ||
1355 | optNamespaceRestriction: | |
1356 | /* empty */ { | |
1357 | $$.nElements_ = 0; $$.uris_ = 0; $$.type_ = NamespaceRestriction::NOTHING; | |
1358 | } | |
1359 | | XKWfrom urilist { $$ = $2; $$.type_ = NamespaceRestriction::FROM; } | |
1360 | | XKWexcept urilist { $$ = $2; $$.type_ = NamespaceRestriction::EXCEPT; } | |
1361 | ; | |
1362 | ||
1363 | urilist: /* a non-empty list */ | |
1364 | quotedURIorAbsent { | |
1365 | $$.nElements_ = 1; | |
1366 | $$.uris_ = (char**)Malloc(sizeof($$.uris_[0])); | |
1367 | $$.uris_[0] = $1; | |
1368 | } | |
1369 | | urilist ',' quotedURIorAbsent | |
1370 | { | |
1371 | $$ = $1; | |
1372 | $$.uris_ = (char**)Realloc($$.uris_, ++$$.nElements_ * sizeof($$.uris_[0])); | |
1373 | $$.uris_[$$.nElements_-1] = $3; | |
1374 | } | |
1375 | ; | |
1376 | ||
1377 | quotedURIorAbsent: | |
1378 | Xstring /* as quotedURI */ | |
1379 | | XKWunqualified { $$ = NULL; } | |
1380 | ; | |
1381 | ||
1382 | controlNamespace: /* nsspec */ | |
1383 | XKWcontrolNamespace Xstring /* <-- as the QuotedURI */ XKWprefix Xstring | |
1384 | /* Prefix is required by TTCN-3; it is optional in the ASN.1 standard | |
1385 | * but the OSS ASN.1 compiler seems to require it anyway */ | |
1386 | { | |
1387 | $$.uri = $2; | |
1388 | $$.prefix = $4; | |
1389 | } | |
1390 | ; | |
1391 | ||
1392 | ||
1393 | form: | |
1394 | XKWform XKWas XKWunqualified { $$ = XerAttributes::UNQUALIFIED; } | |
1395 | | XKWform XKWas XKWqualified { $$ = XerAttributes::QUALIFIED; } | |
1396 | ||
1397 | ||
1398 | name: | |
1399 | XKWname XKWas newnameOrKeyword { $$ = $3; } | |
1400 | ; | |
1401 | ||
1402 | newnameOrKeyword: keyword | |
1403 | | Xstring { $$ = $1; } | |
1404 | ; | |
1405 | ||
1406 | keyword: | |
1407 | XKWcapitalized { $$ = (char*)NamespaceSpecification::CAPITALIZED; } | |
1408 | | XKWuncapitalized { $$ = (char*)NamespaceSpecification::UNCAPITALIZED; } | |
1409 | | XKWlowercased { $$ = (char*)NamespaceSpecification::LOWERCASED; } | |
1410 | | XKWuppercased { $$ = (char*)NamespaceSpecification::UPPERCASED; } | |
1411 | ; | |
1412 | ||
1413 | namespace: | |
1414 | XKWnamespace namespacespecification | |
1415 | { $$ = $2; } | |
1416 | ; | |
1417 | ||
1418 | namespacespecification: | |
1419 | XKWas | |
1420 | Xstring /* as QuotedURI, required */ | |
1421 | optPrefix | |
1422 | { | |
1423 | if (*$2) { | |
1424 | $$.uri = $2; $$.prefix = $3; | |
1425 | } | |
1426 | else { /* URI is empty */ | |
1427 | if (*$3) { /* prefix not empty, error */ | |
1428 | Common::Location loc(infile, @2); | |
1429 | loc.error("Empty string is not a valid URI"); | |
1430 | } | |
1431 | else { | |
1432 | /* Both are empty strings, use one of the non-string values | |
1433 | * to signal "override and remove any namespace" */ | |
1434 | Free($2); | |
1435 | Free($3); | |
1436 | $$.keyword = NamespaceSpecification::UNCAPITALIZED; | |
1437 | $$.prefix = NULL; | |
1438 | } | |
1439 | } | |
1440 | } | |
1441 | ; | |
1442 | ||
1443 | optPrefix: /* empty */ { $$ = memptystr(); } | |
1444 | | XKWprefix Xstring | |
1445 | { $$ = $2; } | |
1446 | ; | |
1447 | ||
1448 | text: | |
1449 | XKWtext Xstring XKWas newnameOrKeyword | |
1450 | { $$.uri = $4; $$.prefix = $2; } | |
1451 | | XKWtext XKWall XKWas newnameOrKeyword | |
1452 | { $$.uri = $4; $$.prefix = (char*)NamespaceSpecification::ALL; } | |
1453 | | XKWtext | |
1454 | { $$.uri = 0; $$.prefix = 0; } | |
1455 | /* "text as <something>" is not allowed */ | |
1456 | ; | |
1457 | ||
1458 | defaultForEmpty: | |
1459 | XKWdefaultForEmpty XKWas Xstring | |
1460 | { $$ = $3; } | |
1461 | ; | |
1462 | ||
1463 | ||
1464 | ||
1465 | whiteSpace: | |
1466 | XKWwhiteSpace XKWpreserve { $$ = XerAttributes::PRESERVE; } | |
1467 | | XKWwhiteSpace XKWreplace { $$ = XerAttributes::REPLACE; } | |
1468 | | XKWwhiteSpace XKWcollapse { $$ = XerAttributes::COLLAPSE; } | |
1469 | ; | |
1470 | ||
1471 | xsddata: /* XSD:something */ | |
1472 | XSDbase64Binary { | |
1473 | xerstruct->base64_ = true; | |
1474 | } | |
1475 | | XSDdecimal { | |
1476 | xerstruct->decimal_ = true; | |
1477 | } | |
1478 | | XSDhexBinary { | |
1479 | xerstruct->hex_ = true; | |
1480 | } | |
1481 | | XSDQName { | |
1482 | xerstruct->useQName_ = true; | |
1483 | } | |
1484 | /* everything below is recognized and ignored */ | |
1485 | | XKWshort {} | |
1486 | | XKWlong {} | |
1487 | | XSDstring {} | |
1488 | | XSDnormalizedString {} | |
1489 | | XSDtoken {} | |
1490 | | XSDName {} | |
1491 | | XSDNMTOKEN {} | |
1492 | | XSDNCName {} | |
1493 | | XSDID {} | |
1494 | | XSDIDREF {} | |
1495 | | XSDENTITY {} | |
1496 | | XSDanyURI {} | |
1497 | | XSDlanguage {} | |
1498 | /* TODO apply subtype to the types below */ | |
1499 | | XSDinteger {} | |
1500 | | XSDpositiveInteger {} | |
1501 | | XSDnonPositiveInteger {} | |
1502 | | XSDnegativeInteger {} | |
1503 | | XSDnonNegativeInteger {} | |
1504 | | XSDunsignedLong {} | |
1505 | | XSDint {} | |
1506 | | XSDunsignedInt {} | |
1507 | | XSDunsignedShort {} | |
1508 | | XSDbyte {} | |
1509 | | XSDunsignedByte {} | |
1510 | | XSDfloat {} | |
1511 | | XSDdouble {} | |
1512 | | XSDduration {} | |
1513 | | XSDdateTime {} | |
1514 | | XSDtime {} | |
1515 | | XSDdate {} | |
1516 | | XSDgYearMonth {} | |
1517 | | XSDgYear {} | |
1518 | | XSDgMonthDay {} | |
1519 | | XSDgDay {} | |
1520 | | XSDgMonth {} | |
1521 | | XSDNMTOKENS {} | |
1522 | | XSDIDREFS {} | |
1523 | | XSDENTITIES {} | |
1524 | | XSDboolean {} | |
1525 | ||
1526 | | XSDanySimpleType {} | |
1527 | | XSDanyType {} | |
1528 | ||
1529 | ; | |
1530 | ||
1531 | // JSON encoder | |
1532 | XJsonDef: | |
3abe9331 | 1533 | XOptSpaces XKWjson XOptSpaces ':' XOptSpaces XJsonAttribute XOptSpaces |
970ed795 EL |
1534 | ; |
1535 | ||
1536 | XJsonAttribute: | |
1537 | XOmitAsNull | |
1538 | | XNameAs | |
1539 | | XAsValue | |
1540 | | XDefault | |
3abe9331 | 1541 | | XExtend |
1542 | | XMetainfoForUnbound | |
970ed795 EL |
1543 | ; |
1544 | ||
1545 | XOmitAsNull: | |
1546 | XKWomit XSpaces XKWas XSpaces XKWnull { jsonstruct->omit_as_null = true; } | |
1547 | ; | |
1548 | ||
1549 | XNameAs: | |
1550 | XKWname XSpaces XKWas XSpaces XAliasToken { jsonstruct->alias = mcopystr($5); } | |
1551 | ; | |
1552 | ||
1553 | XAsValue: | |
1554 | XKWas XSpaces XKWvalue { jsonstruct->as_value = true; } | |
1555 | ; | |
1556 | ||
1557 | XDefault: | |
3abe9331 | 1558 | XKWdefault XOptSpaces XJsonValue { jsonstruct->default_value = mcopystr($3); } |
1559 | ; | |
1560 | ||
1561 | XExtend: | |
1562 | XKWextend XOptSpaces XJsonValue XOptSpaces ':' XOptSpaces XJsonValue | |
1563 | { jsonstruct->schema_extensions.add(new JsonSchemaExtension($3, $7)); } | |
970ed795 EL |
1564 | ; |
1565 | ||
1566 | XJsonValue: | |
3abe9331 | 1567 | XJsonValueStart XJsonValueCore XJsonValueEnd { $$ = mcopystr($2); } |
1568 | | XJsonValueStart XJsonValueEnd { $$ = mcopystr(""); } | |
1569 | ; | |
1570 | ||
1571 | XJsonValueCore: | |
1572 | XJsonValueCore XJsonValueSegment { $$ = mcopystr($1); $$ = mputstr($$, $2); } | |
1573 | | XJsonValueSegment { $$ = mcopystr($1); } | |
1574 | ; | |
1575 | ||
1576 | XMetainfoForUnbound: | |
1577 | XKWmetainfo XOptSpaces XKWfor XOptSpaces XKWunbound { jsonstruct->metainfo_unbound = true; } | |
970ed795 EL |
1578 | ; |
1579 | ||
1580 | XOptSpaces: | |
1581 | /* Empty */ | |
1582 | | XSpaces | |
1583 | ; | |
1584 | ||
1585 | XSpaces: | |
1586 | XSpaces XSpace | |
1587 | | XSpace | |
1588 | ; | |
1589 | ||
1590 | XSpace: | |
1591 | ' ' | |
1592 | | '\t' | |
1593 | ; | |
1594 | ||
1595 | %% | |
1596 | ||
1597 | /* parse_rawAST(), which calls our rawAST_parse, is over in rawASST.l */ | |
1598 | ||
1599 | #ifndef NDEBUG | |
1600 | static void yyprint(FILE *file, int type, const YYSTYPE& value) | |
1601 | { | |
1602 | switch (type) { | |
1603 | case XIdentifier: | |
1604 | fprintf(file, "``%s''", value.identifier->get_name().c_str()); | |
1605 | break; | |
1606 | case Xstring: | |
1607 | fprintf(file, "``%s''", value.str); | |
1608 | break; | |
1609 | default: | |
1610 | fprintf(file, "# %d", type); | |
1611 | break; | |
1612 | } | |
1613 | } | |
1614 | #endif | |
1615 | ||
1616 | /* | |
1617 | Local Variables: | |
1618 | mode: C | |
1619 | indent-tabs-mode: nil | |
1620 | c-basic-offset: 4 | |
1621 | End: | |
1622 | */ |