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