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