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
12 * Szabo, Janos Zoltan – initial implementation
14 * Zalanyi, Balazs Andor
16 ******************************************************************************/
17 /* RAW encoding/decoding specification parser & compiler */
23 #include "../../common/memory.h"
26 #include "../Value.hh"
27 #include "AST_ttcn3.hh"
28 #include "rawASTspec.h"
30 #include "../XerAttributes.hh"
34 extern void rawAST_error(const char *str);
35 extern int rawAST_lex();
37 extern RawAST* rawstruct;
38 extern Common::Module *mymod;
39 extern int length_multiplier;
40 extern TextAST *textstruct;
46 extern XerAttributes* xerstruct;
47 extern BerAST* berstruct;
48 extern JsonAST* jsonstruct;
50 extern string *parse_charstring_value(const char *str,
51 const Common::Location& loc);
53 #define YYERROR_VERBOSE
57 static void yyprint(FILE *file, int type, const YYSTYPE& value);
58 #define YYPRINT(f,t,v) yyprint(f,t,v)
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;
82 NamespaceSpecification nsspec;
83 NamespaceRestriction nsrestr;
86 %token <intval> XNumber
87 %token <floatval> XFloatValue
88 %token <identifier> XIdentifier
94 %token <boolval> XBooleanConst
95 %token <verdictval> XVerdictConst
103 %token XSeparatorKeyword
104 %token XCodingKeyword
114 %token XSensitivToken
115 %token XInSensitivToken
120 %token XPaddingKeyword
121 %token XPaddAllKeyword
122 %token XPrePaddingKeyword
123 %token XPaddingPatternKeyword
125 %token <enumval> XYes
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
136 %token XPtrUnitKeyword
137 %token XPtrOffsetKeyword
138 %token <enumval> XBits
139 %token <enumval> XOctets
140 %token XLengthIndexKeyword
142 %token XCrossTagKeyword
143 %token XPresenceKeyword
144 %token XFieldLengthKeyword
146 %token <enumval> XLeft
147 %token <enumval> XRight
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
165 %token XUnsignedKeyword
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"
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"
211 %token XSDstring "string"
212 %token XSDnormalizedString "normalizedString"
213 %token XSDtoken "token"
214 %token XSDName "Name"
215 %token XSDNMTOKEN "NMTOKEN"
216 %token XSDNCName "NCName"
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"
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"
260 %token XKWlength "length"
261 %token XKWaccept "accept"
262 %token XKWlong "long"
263 %token XKWshort "short"
264 %token XKWindefinite "indefinite"
265 %token XKWdefinite "definite"
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"
278 %token XKWunbound "unbound"
279 %token XJsonValueStart "("
280 %token XJsonValueEnd ")"
281 %token XJsonValueSegment "JSON value"
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
292 XLengthIndexDef XStructFieldRefOrEmpty XStructFieldRef
295 XEncodeToken XmatchDef XAliasToken XJsonValueSegment XJsonValueCore XJsonValue
301 XTextReservedWord XJsonAlias
304 XPointerToDef XRecordFieldRef XIdentifierOrReserved
312 /* note: multiple "XSingleEncodingDefs have to be merged into one 'fullspec' */
314 XEncodingDefList XSingleEncodingDef
322 XAssocElement XKeyIdOrIdList XKeyIdList XMultiKeyId
325 XToplevelDef XTopDefList XTopDef
329 anyAttributes anyElement optNamespaceRestriction urilist
332 %type <str> defaultForEmpty name newnameOrKeyword keyword optPrefix quotedURIorAbsent
334 %type <nsspec> namespace namespacespecification controlNamespace text
336 %type <intval> whiteSpace
339 %destructor { Free($$); }
353 %destructor { delete $$; }
355 XIdentifierOrReserved
359 %destructor { free_rawAST_field_list($$); }
362 XStructFieldRefOrEmpty
364 %destructor { free_rawAST_tag_list(&$$); }
367 %destructor { free_rawAST_tag_field_value(&$$); }
370 %destructor { free_rawAST_single_tag(&$$); }
382 %destructor { Free($$.token); }
386 FreeNamespaceRestriction($$);
388 anyAttributes anyElement optNamespaceRestriction urilist
395 namespacespecification
405 XAttribSpec : /* Empty */
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; }
421 XEncodingDefList : XSingleEncodingDef
423 | XEncodingDefList ',' XSingleEncodingDef
426 XSingleEncodingDef : XPaddingDef
427 { rawstruct->padding=$1;raw_f=true;}
429 { rawstruct->prepadding=$1;raw_f=true;}
430 | XPaddingPattern { raw_f=true;}
431 | XPaddAll { rawstruct->paddall=XDEFYES;raw_f=true;}
433 { rawstruct->fieldorder=$1;raw_f=true;}
435 { rawstruct->extension_bit=$1;raw_f=true;}
436 | XExtensionBitGroupDef
441 { delete rawstruct->pointerto;
442 rawstruct->pointerto = $1;
446 { rawstruct->unit=$1; raw_f=true;}
448 { free_rawAST_field_list(rawstruct->lengthindex);
449 rawstruct->lengthindex = $1;raw_f=true; }
457 { rawstruct->fieldlength = $1*length_multiplier; raw_f=true;}
461 { rawstruct->align = $1; raw_f=true;}
463 { rawstruct->comp = $1;raw_f=true; }
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;}
471 { rawstruct->hexorder = $1;raw_f=true; }
473 { rawstruct->repeatable = $1;raw_f=true; }
475 { rawstruct->topleveleind=1; raw_f=true;}
477 { rawstruct->intx = true; raw_f = true; }
480 /* TEXT encoder keywords */
493 XRepeatableDef : XRepeatableKeyword '(' XYesOrNo ')' { $$ = $3; }
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;
503 XPaddingPatternKeyword '(' XBstring ')'
505 Free(rawstruct->padding_pattern);
506 size_t len = strlen($3);
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;
514 } else rawstruct->padding_pattern = NULL;
519 XPaddAll: XPaddAllKeyword
521 XFieldOrderDef : XFieldOrderKeyword '(' XMsbOrLsb ')'
523 XMsbOrLsb : XMsb | XLsb;
526 XExtensionBitDef : XExtensionBitKeyword '(' XYesOrNoOrReverse ')'
528 XYesOrNoOrReverse : XYes | XNo | XReverse;
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;
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));
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;
548 XLengthToDef : XLengthToKeyword '(' XRecordFieldRefList ')'
552 XPointerToDef : XPointerToKeyword '(' XRecordFieldRef ')'
556 XUnitDef : XUnitKeyword '(' XBitsOctets ')' { $$ = $3; }
557 | XPtrUnitKeyword '(' XBitsOctets ')' { $$ = $3; };
558 XBitsOctets : XBits {$$=$1;}
563 XLengthIndexDef : XLengthIndexKeyword '(' XStructFieldRefOrEmpty ')'
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);};
579 $$.tag = (rawAST_single_tag*)Malloc(sizeof(*$$.tag));
580 link_rawAST_single_tag($$.tag, &$1);
582 | XAssocList XSemiColon XAssocElement
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) {
593 if (dupl_id_index >= 0) {
594 /* this identifier is already specified in XAssocList
595 merge the new parameters to the existing entry */
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;
607 $$.nElements = $1.nElements + 1;
608 $$.tag = (rawAST_single_tag*)
609 Realloc($1.tag, $$.nElements * sizeof(*$$.tag));
610 $$.tag[$1.nElements] = $3;
625 XIdentifier ',' XKeyIdOrIdList
628 $$.nElements = $3.nElements;
629 $$.keyList = $3.keyList;
631 | XIdentifier ',' XOtherwise
644 $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList));
647 | XKeyIdList { $$ = $1; }
651 '{' XMultiKeyId '}' { $$ = $2; }
659 $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList));
662 | XMultiKeyId ',' XKeyId
665 $$.nElements = $1.nElements + 1;
666 $$.keyList = (rawAST_tag_field_value*)
667 Realloc($1.keyList, $$.nElements * sizeof(*$$.keyList));
668 $$.keyList[$1.nElements] = $3;
673 XStructFieldRef '=' XRvalue
677 $$.v_value = $3.v_value;
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);};
691 XFieldLengthDef : XFieldLengthKeyword '(' XNumber ')'
695 XPtrOffsetDef : XPtrOffsetKeyword '(' XNumber ')'
696 { rawstruct->ptroffset = $3; }
697 |XPtrOffsetKeyword '(' XIdentifier ')'
699 delete rawstruct->ptrbase;
700 rawstruct->ptrbase = $3;
703 XAlignDef : XAlignKeyword '(' XLeftOrRight ')'
705 XLeftOrRight : XLeft | XRight;
708 XCompDef : XCompKeyword '(' XCompValues ')'
710 XCompValues : XUnsigned | XCompl | XSignbit;
713 XByteOrderDef : XByteOrderKeyword '(' XFirstOrLast ')'
715 XFirstOrLast : XFirst | XLast;
718 XBitOrderInFieldDef : XBitOrderInFieldKeyword '(' XMsbOrLsb ')'
720 XBitOrderInOctetDef : XBitOrderInOctetKeyword '(' XMsbOrLsb ')'
722 | XBitOrderKeyword '(' XMsbOrLsb ')' { $$ = $3; };
723 XToplevelDef : XToplevelKeyword '(' XTopDefList ')'
725 XTopDefList : XTopDef
727 | XTopDefList ',' XTopDef
729 XTopDef : XBitOrderDef
730 { rawstruct->toplevel.bitorder = $1;};
731 XBitOrderDef : XBitOrderKeyword '(' XMsbOrLsb ')'
735 XHexOrderDef : XHexOrderKeyword '(' XLowOrHigh ')'
737 XLowOrHigh : XLow | XHigh;
741 XRecordFieldRefList : XRecordFieldRef
742 { rawstruct->lengthto_num = 1;
743 rawstruct->lengthto =
744 (Common::Identifier**)Malloc(sizeof(*(rawstruct->lengthto)));
745 rawstruct->lengthto[0] = $1;
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;
756 XRecordFieldRef : XIdentifier
759 XStructFieldRefOrEmpty : /* Empty */
764 XStructFieldRef : XIdentifier
765 { $$ = (rawAST_field_list*)Malloc(sizeof(*$$));
767 $$->names = (Common::Identifier**)Malloc(sizeof(*($$->names)));
770 | XStructFieldRef '.' XIdentifier
773 $$->names = (Common::Identifier**)
774 Realloc($$->names, $$->nElements*sizeof(*($$->names)));
775 $$->names[$$->nElements - 1] = $3;
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, @$);
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, @$);
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, @$);
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, @$);
807 Common::Location loc(infile, @$);
808 string *str = parse_charstring_value($1, loc);
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);
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, @$);
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, @$);
826 $$.value = mcopystr($1 ? "TRUE" : "FALSE");
827 $$.v_value=new Common::Value(Common::Value::V_BOOL, $1);
828 $$.v_value->set_location(infile, @$);
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());
838 $$.value = mcopystr("NULL_COMPREF");
839 $$.v_value = new Common::Value(Common::Value::V_TTCN3_NULL);
840 $$.v_value->set_location(infile, @$);
844 $$.value = mcopystr("ASN_NULL_VALUE");
845 $$.v_value = new Common::Value(Common::Value::V_NULL);
846 $$.v_value->set_location(infile, @$);
850 $$.value = mcopystr("OMIT_VALUE");
851 $$.v_value = new Common::Value(Common::Value::V_OMIT);
852 $$.v_value->set_location(infile, @$);
856 /* Alternative RAW attributes for types defined in annex E of the TTCN-3 standard */
860 rawstruct->fieldlength = $1;
861 rawstruct->comp = XDEFSIGNBIT;
862 rawstruct->byteorder = XDEFLAST;
864 | XUnsignedKeyword XNumber XBitKeyword
866 rawstruct->fieldlength = $2;
867 rawstruct->comp = XDEFUNSIGNED;
868 rawstruct->byteorder = XDEFLAST;
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);
880 Free(textstruct->begin_val->encode_token);
881 textstruct->begin_val->encode_token=$3;
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);
889 Free(textstruct->begin_val->encode_token);
890 textstruct->begin_val->encode_token=$3;
892 Free(textstruct->begin_val->decode_token);
893 textstruct->begin_val->decode_token=$5;
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);
902 Free(textstruct->begin_val->encode_token);
903 textstruct->begin_val->encode_token=$3;
905 Free(textstruct->begin_val->decode_token);
906 textstruct->begin_val->decode_token=$5;
908 textstruct->begin_val->case_sensitive=$7;
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);
919 Free(textstruct->end_val->encode_token);
920 textstruct->end_val->encode_token=$3;
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);
928 Free(textstruct->end_val->encode_token);
929 textstruct->end_val->encode_token=$3;
931 Free(textstruct->end_val->decode_token);
932 textstruct->end_val->decode_token=$5;
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);
941 Free(textstruct->end_val->encode_token);
942 textstruct->end_val->encode_token=$3;
944 Free(textstruct->end_val->decode_token);
945 textstruct->end_val->decode_token=$5;
947 textstruct->end_val->case_sensitive=$7;
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);
958 Free(textstruct->separator_val->encode_token);
959 textstruct->separator_val->encode_token=$3;
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);
967 Free(textstruct->separator_val->encode_token);
968 textstruct->separator_val->encode_token=$3;
970 Free(textstruct->separator_val->decode_token);
971 textstruct->separator_val->decode_token=$5;
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);
980 Free(textstruct->separator_val->encode_token);
981 textstruct->separator_val->encode_token=$3;
983 Free(textstruct->separator_val->decode_token);
984 textstruct->separator_val->decode_token=$5;
986 textstruct->separator_val->case_sensitive=$7;
991 XCodingKeyword '(' XCodingRule ')'
993 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ')'
995 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ')' {
996 Free(textstruct->decode_token);
997 textstruct->decode_token=$7;
999 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ','
1002 Free(textstruct->decode_token);
1003 textstruct->decode_token=$7;
1005 textstruct->case_sensitive=$9;
1018 | XDecodingtokendefList {}
1023 | XattrList ';' Xattr {}
1027 XLengthToken '=' XNumber {
1028 textstruct->decoding_params.min_length=$3;
1030 | XLengthToken '=' XNumber '-' XNumber {
1031 textstruct->decoding_params.min_length=$3;
1032 textstruct->decoding_params.max_length=$5;
1034 | XConvertToken '=' XLowerToken {
1035 textstruct->decoding_params.convert=-1;
1037 | XConvertToken '=' XUpperToken {
1038 textstruct->decoding_params.convert=1;
1040 | XJustToken '=' XLeftToken {
1041 textstruct->decoding_params.just=-1;
1043 | XJustToken '=' XRightToken {
1044 textstruct->decoding_params.just=1;
1046 | XJustToken '=' XCenterToken {
1047 textstruct->decoding_params.just=0;
1049 | XLeadingToken '=' XTrueToken {
1050 textstruct->decoding_params.leading_zero=true;
1052 | XLeadingToken '=' XFalseToken {
1053 textstruct->decoding_params.leading_zero=false;
1055 | XRepeatToken '=' XTrueToken {
1056 textstruct->decoding_params.repeatable=true;
1058 | XRepeatToken '=' XFalseToken {
1059 textstruct->decoding_params.repeatable=false;
1064 | Xattrlistenc ';' Xattrenc {}
1068 XLengthToken '=' XNumber {
1069 textstruct->coding_params.min_length=$3;
1070 textstruct->decoding_params.min_length=$3;
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;
1078 | XConvertToken '=' XLowerToken {
1079 textstruct->coding_params.convert=-1;
1080 textstruct->decoding_params.convert=-1;
1082 | XConvertToken '=' XUpperToken {
1083 textstruct->coding_params.convert=1;
1084 textstruct->decoding_params.convert=1;
1086 | XJustToken '=' XLeftToken {
1087 textstruct->coding_params.just=-1;
1088 textstruct->decoding_params.just=-1;
1090 | XJustToken '=' XRightToken {
1091 textstruct->coding_params.just=1;
1092 textstruct->decoding_params.just=1;
1094 | XJustToken '=' XCenterToken {
1095 textstruct->coding_params.just=0;
1096 textstruct->decoding_params.just=0;
1098 | XLeadingToken '=' XTrueToken {
1099 textstruct->coding_params.leading_zero=true;
1100 textstruct->decoding_params.leading_zero=true;
1102 | XLeadingToken '=' XFalseToken {
1103 textstruct->coding_params.leading_zero=false;
1104 textstruct->decoding_params.leading_zero=false;
1106 | XRepeatToken '=' XTrueToken {
1107 textstruct->coding_params.repeatable=true;
1108 textstruct->decoding_params.repeatable=true;
1110 | XRepeatToken '=' XFalseToken {
1111 textstruct->coding_params.repeatable=false;
1112 textstruct->decoding_params.repeatable=false;
1118 | XtokendefList ';' Xtokendef {}
1122 XIdentifierOrReserved ':' XEncodeToken
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());
1131 textstruct->field_params[idx]->value.encode_token = $3;
1134 | XTrueToken ':' XEncodeToken
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;
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");
1149 textstruct->true_params->encode_token = $3;
1152 | XFalseToken ':' XEncodeToken
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;
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");
1167 textstruct->false_params->encode_token = $3;
1172 XIdentifierOrReserved:
1173 XIdentifier { $$ = $1; }
1175 { $$ = new Common::Identifier(Common::Identifier::ID_TTCN, string($1)); }
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"; }
1193 XDecodingtokendefList:
1194 Xdecodingtokendef {}
1195 | XDecodingtokendefList ';' Xdecodingtokendef {}
1199 XIdentifierOrReserved ':' XDecodeToken
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());
1208 textstruct->field_params[idx]->value.decode_token = $3.token;
1209 textstruct->field_params[idx]->value.case_sensitive = $3.case_sensitive;
1212 | XTrueToken ':' XDecodeToken
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;
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");
1227 textstruct->true_params->decode_token = $3.token;
1228 textstruct->true_params->case_sensitive = $3.case_sensitive;
1231 | XFalseToken ':' XDecodeToken
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;
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");
1246 textstruct->false_params->decode_token = $3.token;
1247 textstruct->false_params->case_sensitive = $3.case_sensitive;
1255 Common::Location loc(infile, @$);
1256 string *str = parse_charstring_value($1, loc);
1258 $$ = mcopystr(str->c_str());
1267 $$.case_sensitive = true;
1272 $$.case_sensitive = true;
1274 | '{' XmatchDef ',' XmodifierDef '}'
1277 $$.case_sensitive = $4;
1282 /* empty */ { $$ = NULL; }
1283 | Xtoken { $$ = $1; }
1287 /* empty */ { $$ = true; }
1288 | XSensitivToken { $$ = true; }
1289 | XInSensitivToken { $$ = false; }
1292 /********** XERSTUFF "raw" attributes */
1294 XERattributes: /* a non-empty list */
1295 XERattribute { xer_f = true; }
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 */
1307 mymod->set_controlns($1.uri, $1.prefix);
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; }
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_);
1327 xerstruct->name_.nn_ = $1;
1330 { /* overwrites any previous namespace */
1331 Free(xerstruct->namespace_.uri);
1332 Free(xerstruct->namespace_.prefix);
1333 xerstruct->namespace_ = $1;
1337 xerstruct->text_ = (NamespaceSpecification *)Realloc(xerstruct->text_,
1338 ++xerstruct->num_text_ * sizeof(NamespaceSpecification));
1339 xerstruct->text_[xerstruct->num_text_-1] = $1;
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; }
1349 xerstruct->whitespace_ = static_cast<XerAttributes::WhitespaceAction>($1);
1351 | XSD ':' xsddata {}
1355 XKWanyAttributes optNamespaceRestriction
1360 XKWanyElement optNamespaceRestriction
1364 optNamespaceRestriction:
1366 $$.nElements_ = 0; $$.uris_ = 0; $$.type_ = NamespaceRestriction::NOTHING;
1368 | XKWfrom urilist { $$ = $2; $$.type_ = NamespaceRestriction::FROM; }
1369 | XKWexcept urilist { $$ = $2; $$.type_ = NamespaceRestriction::EXCEPT; }
1372 urilist: /* a non-empty list */
1375 $$.uris_ = (char**)Malloc(sizeof($$.uris_[0]));
1378 | urilist ',' quotedURIorAbsent
1381 $$.uris_ = (char**)Realloc($$.uris_, ++$$.nElements_ * sizeof($$.uris_[0]));
1382 $$.uris_[$$.nElements_-1] = $3;
1387 Xstring /* as quotedURI */
1388 | XKWunqualified { $$ = NULL; }
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 */
1403 XKWform XKWas XKWunqualified { $$ = XerAttributes::UNQUALIFIED; }
1404 | XKWform XKWas XKWqualified { $$ = XerAttributes::QUALIFIED; }
1408 XKWname XKWas newnameOrKeyword { $$ = $3; }
1411 newnameOrKeyword: keyword
1412 | Xstring { $$ = $1; }
1416 XKWcapitalized { $$ = (char*)NamespaceSpecification::CAPITALIZED; }
1417 | XKWuncapitalized { $$ = (char*)NamespaceSpecification::UNCAPITALIZED; }
1418 | XKWlowercased { $$ = (char*)NamespaceSpecification::LOWERCASED; }
1419 | XKWuppercased { $$ = (char*)NamespaceSpecification::UPPERCASED; }
1423 XKWnamespace namespacespecification
1427 namespacespecification:
1429 Xstring /* as QuotedURI, required */
1433 $$.uri = $2; $$.prefix = $3;
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");
1441 /* Both are empty strings, use one of the non-string values
1442 * to signal "override and remove any namespace" */
1445 $$.keyword = NamespaceSpecification::UNCAPITALIZED;
1452 optPrefix: /* empty */ { $$ = memptystr(); }
1458 XKWtext Xstring XKWas newnameOrKeyword
1459 { $$.uri = $4; $$.prefix = $2; }
1460 | XKWtext XKWall XKWas newnameOrKeyword
1461 { $$.uri = $4; $$.prefix = (char*)NamespaceSpecification::ALL; }
1463 { $$.uri = 0; $$.prefix = 0; }
1464 /* "text as <something>" is not allowed */
1468 XKWdefaultForEmpty XKWas Xstring
1475 XKWwhiteSpace XKWpreserve { $$ = XerAttributes::PRESERVE; }
1476 | XKWwhiteSpace XKWreplace { $$ = XerAttributes::REPLACE; }
1477 | XKWwhiteSpace XKWcollapse { $$ = XerAttributes::COLLAPSE; }
1480 xsddata: /* XSD:something */
1482 xerstruct->base64_ = true;
1485 xerstruct->decimal_ = true;
1488 xerstruct->hex_ = true;
1491 xerstruct->useQName_ = true;
1493 /* everything below is recognized and ignored */
1497 | XSDnormalizedString {}
1507 /* TODO apply subtype to the types below */
1509 | XSDpositiveInteger {}
1510 | XSDnonPositiveInteger {}
1511 | XSDnegativeInteger {}
1512 | XSDnonNegativeInteger {}
1513 | XSDunsignedLong {}
1516 | XSDunsignedShort {}
1518 | XSDunsignedByte {}
1535 | XSDanySimpleType {}
1542 XOptSpaces XKWjson XOptSpaces ':' XOptSpaces XJsonAttribute XOptSpaces
1551 | XMetainfoForUnbound
1555 XKWomit XSpaces XKWas XSpaces XKWnull { jsonstruct->omit_as_null = true; }
1559 XKWname XSpaces XKWas XSpaces XJsonAlias { jsonstruct->alias = mcopystr($5); }
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"; }
1576 XKWas XSpaces XKWvalue { jsonstruct->as_value = true; }
1580 XKWdefault XOptSpaces XJsonValue { jsonstruct->default_value = mcopystr($3); }
1584 XKWextend XOptSpaces XJsonValue XOptSpaces ':' XOptSpaces XJsonValue
1585 { jsonstruct->schema_extensions.add(new JsonSchemaExtension($3, $7)); }
1589 XJsonValueStart XJsonValueCore XJsonValueEnd { $$ = mcopystr($2); }
1590 | XJsonValueStart XJsonValueEnd { $$ = mcopystr(""); }
1594 XJsonValueCore XJsonValueSegment { $$ = mcopystr($1); $$ = mputstr($$, $2); }
1595 | XJsonValueSegment { $$ = mcopystr($1); }
1598 XMetainfoForUnbound:
1599 XKWmetainfo XOptSpaces XKWfor XOptSpaces XKWunbound { jsonstruct->metainfo_unbound = true; }
1619 /* parse_rawAST(), which calls our rawAST_parse, is over in rawASST.l */
1622 static void yyprint(FILE *file, int type, const YYSTYPE& value)
1626 fprintf(file, "``%s''", value.identifier->get_name().c_str());
1629 fprintf(file, "``%s''", value.str);
1632 fprintf(file, "# %d", type);
1641 indent-tabs-mode: nil