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