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 */
14 #include "../../common/memory.h"
17 #include "../Value.hh"
18 #include "AST_ttcn3.hh"
19 #include "rawASTspec.h"
21 #include "../XerAttributes.hh"
25 extern void rawAST_error(const char *str);
26 extern int rawAST_lex();
28 extern RawAST* rawstruct;
29 extern Common::Module *mymod;
30 extern int length_multiplier;
31 extern TextAST *textstruct;
37 extern XerAttributes* xerstruct;
38 extern BerAST* berstruct;
39 extern JsonAST* jsonstruct;
41 extern string *parse_charstring_value(const char *str,
42 const Common::Location& loc);
44 #define YYERROR_VERBOSE
48 static void yyprint(FILE *file, int type, const YYSTYPE& value);
49 #define YYPRINT(f,t,v) yyprint(f,t,v)
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;
73 NamespaceSpecification nsspec;
74 NamespaceRestriction nsrestr;
77 %token <intval> XNumber
78 %token <floatval> XFloatValue
79 %token <identifier> XIdentifier
85 %token <boolval> XBooleanConst
86 %token <verdictval> XVerdictConst
94 %token XSeparatorKeyword
105 %token XSensitivToken
106 %token XInSensitivToken
111 %token XPaddingKeyword
112 %token XPaddAllKeyword
113 %token XPrePaddingKeyword
114 %token XPaddingPatternKeyword
116 %token <enumval> XYes
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
127 %token XPtrUnitKeyword
128 %token XPtrOffsetKeyword
129 %token <enumval> XBits
130 %token <enumval> XOctets
131 %token XLengthIndexKeyword
133 %token XCrossTagKeyword
134 %token XPresenceKeyword
135 %token XFieldLengthKeyword
137 %token <enumval> XLeft
138 %token <enumval> XRight
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
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"
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"
197 %token XSDstring "string"
198 %token XSDnormalizedString "normalizedString"
199 %token XSDtoken "token"
200 %token XSDName "Name"
201 %token XSDNMTOKEN "NMTOKEN"
202 %token XSDNCName "NCName"
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"
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"
246 %token XKWlength "length"
247 %token XKWaccept "accept"
248 %token XKWlong "long"
249 %token XKWshort "short"
250 %token XKWindefinite "indefinite"
251 %token XKWdefinite "definite"
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"
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
274 XLengthIndexDef XStructFieldRefOrEmpty XStructFieldRef
277 XEncodeToken XmatchDef XAliasToken XJsonValueSegment XJsonValue
286 XPointerToDef XRecordFieldRef XIdentifierOrReserved
294 /* note: multiple "XSingleEncodingDefs have to be merged into one 'fullspec' */
296 XEncodingDefList XSingleEncodingDef
304 XAssocElement XKeyIdOrIdList XKeyIdList XMultiKeyId
307 XToplevelDef XTopDefList XTopDef
311 anyAttributes anyElement optNamespaceRestriction urilist
314 %type <str> defaultForEmpty name newnameOrKeyword keyword optPrefix quotedURIorAbsent
316 %type <nsspec> namespace namespacespecification controlNamespace text
318 %type <intval> whiteSpace
321 %destructor { Free($$); }
334 %destructor { delete $$; }
336 XIdentifierOrReserved
340 %destructor { free_rawAST_field_list($$); }
343 XStructFieldRefOrEmpty
345 %destructor { free_rawAST_tag_list(&$$); }
348 %destructor { free_rawAST_tag_field_value(&$$); }
351 %destructor { free_rawAST_single_tag(&$$); }
363 %destructor { Free($$.token); }
367 FreeNamespaceRestriction($$);
369 anyAttributes anyElement optNamespaceRestriction urilist
376 namespacespecification
386 XAttribSpec : /* Empty */
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; }
402 XEncodingDefList : XSingleEncodingDef
404 | XEncodingDefList ',' XSingleEncodingDef
407 XSingleEncodingDef : XPaddingDef
408 { rawstruct->padding=$1;raw_f=true;}
410 { rawstruct->prepadding=$1;raw_f=true;}
411 | XPaddingPattern { raw_f=true;}
412 | XPaddAll { rawstruct->paddall=XDEFYES;raw_f=true;}
414 { rawstruct->fieldorder=$1;raw_f=true;}
416 { rawstruct->extension_bit=$1;raw_f=true;}
417 | XExtensionBitGroupDef
422 { delete rawstruct->pointerto;
423 rawstruct->pointerto = $1;
427 { rawstruct->unit=$1; raw_f=true;}
429 { free_rawAST_field_list(rawstruct->lengthindex);
430 rawstruct->lengthindex = $1;raw_f=true; }
438 { rawstruct->fieldlength = $1*length_multiplier; raw_f=true;}
442 { rawstruct->align = $1; raw_f=true;}
444 { rawstruct->comp = $1;raw_f=true; }
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;}
452 { rawstruct->hexorder = $1;raw_f=true; }
454 { rawstruct->repeatable = $1;raw_f=true; }
456 { rawstruct->topleveleind=1; raw_f=true;}
457 /* TEXT encoder keywords */
470 XRepeatableDef : XRepeatableKeyword '(' XYesOrNo ')' { $$ = $3; }
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;
480 XPaddingPatternKeyword '(' XBstring ')'
482 Free(rawstruct->padding_pattern);
483 size_t len = strlen($3);
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;
491 } else rawstruct->padding_pattern = NULL;
496 XPaddAll: XPaddAllKeyword
498 XFieldOrderDef : XFieldOrderKeyword '(' XMsbOrLsb ')'
500 XMsbOrLsb : XMsb | XLsb;
503 XExtensionBitDef : XExtensionBitKeyword '(' XYesOrNoOrReverse ')'
505 XYesOrNoOrReverse : XYes | XNo | XReverse;
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;
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));
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;
525 XLengthToDef : XLengthToKeyword '(' XRecordFieldRefList ')'
529 XPointerToDef : XPointerToKeyword '(' XRecordFieldRef ')'
533 XUnitDef : XUnitKeyword '(' XBitsOctets ')' { $$ = $3; }
534 | XPtrUnitKeyword '(' XBitsOctets ')' { $$ = $3; };
535 XBitsOctets : XBits {$$=$1;}
540 XLengthIndexDef : XLengthIndexKeyword '(' XStructFieldRefOrEmpty ')'
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);};
556 $$.tag = (rawAST_single_tag*)Malloc(sizeof(*$$.tag));
557 link_rawAST_single_tag($$.tag, &$1);
559 | XAssocList XSemiColon XAssocElement
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) {
570 if (dupl_id_index >= 0) {
571 /* this identifier is already specified in XAssocList
572 merge the new parameters to the existing entry */
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;
584 $$.nElements = $1.nElements + 1;
585 $$.tag = (rawAST_single_tag*)
586 Realloc($1.tag, $$.nElements * sizeof(*$$.tag));
587 $$.tag[$1.nElements] = $3;
602 XIdentifier ',' XKeyIdOrIdList
605 $$.nElements = $3.nElements;
606 $$.keyList = $3.keyList;
608 | XIdentifier ',' XOtherwise
621 $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList));
624 | XKeyIdList { $$ = $1; }
628 '{' XMultiKeyId '}' { $$ = $2; }
636 $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList));
639 | XMultiKeyId ',' XKeyId
642 $$.nElements = $1.nElements + 1;
643 $$.keyList = (rawAST_tag_field_value*)
644 Realloc($1.keyList, $$.nElements * sizeof(*$$.keyList));
645 $$.keyList[$1.nElements] = $3;
650 XStructFieldRef '=' XRvalue
654 $$.v_value = $3.v_value;
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);};
668 XFieldLengthDef : XFieldLengthKeyword '(' XNumber ')'
672 XPtrOffsetDef : XPtrOffsetKeyword '(' XNumber ')'
673 { rawstruct->ptroffset = $3; }
674 |XPtrOffsetKeyword '(' XIdentifier ')'
676 delete rawstruct->ptrbase;
677 rawstruct->ptrbase = $3;
680 XAlignDef : XAlignKeyword '(' XLeftOrRight ')'
682 XLeftOrRight : XLeft | XRight;
685 XCompDef : XCompKeyword '(' XCompValues ')'
687 XCompValues : XUnsigned | XCompl | XSignbit;
690 XByteOrderDef : XByteOrderKeyword '(' XFirstOrLast ')'
692 XFirstOrLast : XFirst | XLast;
695 XBitOrderInFieldDef : XBitOrderInFieldKeyword '(' XMsbOrLsb ')'
697 XBitOrderInOctetDef : XBitOrderInOctetKeyword '(' XMsbOrLsb ')'
699 | XBitOrderKeyword '(' XMsbOrLsb ')' { $$ = $3; };
700 XToplevelDef : XToplevelKeyword '(' XTopDefList ')'
702 XTopDefList : XTopDef
704 | XTopDefList ',' XTopDef
706 XTopDef : XBitOrderDef
707 { rawstruct->toplevel.bitorder = $1;};
708 XBitOrderDef : XBitOrderKeyword '(' XMsbOrLsb ')'
712 XHexOrderDef : XHexOrderKeyword '(' XLowOrHigh ')'
714 XLowOrHigh : XLow | XHigh;
718 XRecordFieldRefList : XRecordFieldRef
719 { rawstruct->lengthto_num = 1;
720 rawstruct->lengthto =
721 (Common::Identifier**)Malloc(sizeof(*(rawstruct->lengthto)));
722 rawstruct->lengthto[0] = $1;
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;
733 XRecordFieldRef : XIdentifier
736 XStructFieldRefOrEmpty : /* Empty */
741 XStructFieldRef : XIdentifier
742 { $$ = (rawAST_field_list*)Malloc(sizeof(*$$));
744 $$->names = (Common::Identifier**)Malloc(sizeof(*($$->names)));
747 | XStructFieldRef '.' XIdentifier
750 $$->names = (Common::Identifier**)
751 Realloc($$->names, $$->nElements*sizeof(*($$->names)));
752 $$->names[$$->nElements - 1] = $3;
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, @$);
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, @$);
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, @$);
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, @$);
784 Common::Location loc(infile, @$);
785 string *str = parse_charstring_value($1, loc);
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);
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, @$);
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, @$);
803 $$.value = mcopystr($1 ? "TRUE" : "FALSE");
804 $$.v_value=new Common::Value(Common::Value::V_BOOL, $1);
805 $$.v_value->set_location(infile, @$);
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());
815 $$.value = mcopystr("NULL_COMPREF");
816 $$.v_value = new Common::Value(Common::Value::V_TTCN3_NULL);
817 $$.v_value->set_location(infile, @$);
821 $$.value = mcopystr("ASN_NULL_VALUE");
822 $$.v_value = new Common::Value(Common::Value::V_NULL);
823 $$.v_value->set_location(infile, @$);
827 $$.value = mcopystr("OMIT_VALUE");
828 $$.v_value = new Common::Value(Common::Value::V_OMIT);
829 $$.v_value->set_location(infile, @$);
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);
841 Free(textstruct->begin_val->encode_token);
842 textstruct->begin_val->encode_token=$3;
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);
850 Free(textstruct->begin_val->encode_token);
851 textstruct->begin_val->encode_token=$3;
853 Free(textstruct->begin_val->decode_token);
854 textstruct->begin_val->decode_token=$5;
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);
863 Free(textstruct->begin_val->encode_token);
864 textstruct->begin_val->encode_token=$3;
866 Free(textstruct->begin_val->decode_token);
867 textstruct->begin_val->decode_token=$5;
869 textstruct->begin_val->case_sensitive=$7;
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);
880 Free(textstruct->end_val->encode_token);
881 textstruct->end_val->encode_token=$3;
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);
889 Free(textstruct->end_val->encode_token);
890 textstruct->end_val->encode_token=$3;
892 Free(textstruct->end_val->decode_token);
893 textstruct->end_val->decode_token=$5;
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);
902 Free(textstruct->end_val->encode_token);
903 textstruct->end_val->encode_token=$3;
905 Free(textstruct->end_val->decode_token);
906 textstruct->end_val->decode_token=$5;
908 textstruct->end_val->case_sensitive=$7;
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);
919 Free(textstruct->separator_val->encode_token);
920 textstruct->separator_val->encode_token=$3;
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);
928 Free(textstruct->separator_val->encode_token);
929 textstruct->separator_val->encode_token=$3;
931 Free(textstruct->separator_val->decode_token);
932 textstruct->separator_val->decode_token=$5;
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);
941 Free(textstruct->separator_val->encode_token);
942 textstruct->separator_val->encode_token=$3;
944 Free(textstruct->separator_val->decode_token);
945 textstruct->separator_val->decode_token=$5;
947 textstruct->separator_val->case_sensitive=$7;
952 XCodingKeyword '(' XCodingRule ')'
954 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ')'
956 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ')' {
957 Free(textstruct->decode_token);
958 textstruct->decode_token=$7;
960 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ','
963 Free(textstruct->decode_token);
964 textstruct->decode_token=$7;
966 textstruct->case_sensitive=$9;
979 | XDecodingtokendefList {}
984 | XattrList ';' Xattr {}
988 XLengthToken '=' XNumber {
989 textstruct->decoding_params.min_length=$3;
991 | XLengthToken '=' XNumber '-' XNumber {
992 textstruct->decoding_params.min_length=$3;
993 textstruct->decoding_params.max_length=$5;
995 | XConvertToken '=' XLowerToken {
996 textstruct->decoding_params.convert=-1;
998 | XConvertToken '=' XUpperToken {
999 textstruct->decoding_params.convert=1;
1001 | XJustToken '=' XLeftToken {
1002 textstruct->decoding_params.just=-1;
1004 | XJustToken '=' XRightToken {
1005 textstruct->decoding_params.just=1;
1007 | XJustToken '=' XCenterToken {
1008 textstruct->decoding_params.just=0;
1010 | XLeadingToken '=' XTrueToken {
1011 textstruct->decoding_params.leading_zero=true;
1013 | XLeadingToken '=' XFalseToken {
1014 textstruct->decoding_params.leading_zero=false;
1016 | XRepeatToken '=' XTrueToken {
1017 textstruct->decoding_params.repeatable=true;
1019 | XRepeatToken '=' XFalseToken {
1020 textstruct->decoding_params.repeatable=false;
1025 | Xattrlistenc ';' Xattrenc {}
1029 XLengthToken '=' XNumber {
1030 textstruct->coding_params.min_length=$3;
1031 textstruct->decoding_params.min_length=$3;
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;
1039 | XConvertToken '=' XLowerToken {
1040 textstruct->coding_params.convert=-1;
1041 textstruct->decoding_params.convert=-1;
1043 | XConvertToken '=' XUpperToken {
1044 textstruct->coding_params.convert=1;
1045 textstruct->decoding_params.convert=1;
1047 | XJustToken '=' XLeftToken {
1048 textstruct->coding_params.just=-1;
1049 textstruct->decoding_params.just=-1;
1051 | XJustToken '=' XRightToken {
1052 textstruct->coding_params.just=1;
1053 textstruct->decoding_params.just=1;
1055 | XJustToken '=' XCenterToken {
1056 textstruct->coding_params.just=0;
1057 textstruct->decoding_params.just=0;
1059 | XLeadingToken '=' XTrueToken {
1060 textstruct->coding_params.leading_zero=true;
1061 textstruct->decoding_params.leading_zero=true;
1063 | XLeadingToken '=' XFalseToken {
1064 textstruct->coding_params.leading_zero=false;
1065 textstruct->decoding_params.leading_zero=false;
1067 | XRepeatToken '=' XTrueToken {
1068 textstruct->coding_params.repeatable=true;
1069 textstruct->decoding_params.repeatable=true;
1071 | XRepeatToken '=' XFalseToken {
1072 textstruct->coding_params.repeatable=false;
1073 textstruct->decoding_params.repeatable=false;
1079 | XtokendefList ';' Xtokendef {}
1083 XIdentifierOrReserved ':' XEncodeToken
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());
1092 textstruct->field_params[idx]->value.encode_token = $3;
1095 | XTrueToken ':' XEncodeToken
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;
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");
1110 textstruct->true_params->encode_token = $3;
1113 | XFalseToken ':' XEncodeToken
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;
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");
1128 textstruct->false_params->encode_token = $3;
1133 XIdentifierOrReserved:
1134 XIdentifier { $$ = $1; }
1136 { $$ = new Common::Identifier(Common::Identifier::ID_TTCN, string($1)); }
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"; }
1154 XDecodingtokendefList:
1155 Xdecodingtokendef {}
1156 | XDecodingtokendefList ';' Xdecodingtokendef {}
1160 XIdentifierOrReserved ':' XDecodeToken
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());
1169 textstruct->field_params[idx]->value.decode_token = $3.token;
1170 textstruct->field_params[idx]->value.case_sensitive = $3.case_sensitive;
1173 | XTrueToken ':' XDecodeToken
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;
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");
1188 textstruct->true_params->decode_token = $3.token;
1189 textstruct->true_params->case_sensitive = $3.case_sensitive;
1192 | XFalseToken ':' XDecodeToken
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;
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");
1207 textstruct->false_params->decode_token = $3.token;
1208 textstruct->false_params->case_sensitive = $3.case_sensitive;
1216 Common::Location loc(infile, @$);
1217 string *str = parse_charstring_value($1, loc);
1219 $$ = mcopystr(str->c_str());
1228 $$.case_sensitive = true;
1233 $$.case_sensitive = true;
1235 | '{' XmatchDef ',' XmodifierDef '}'
1238 $$.case_sensitive = $4;
1243 /* empty */ { $$ = NULL; }
1244 | Xtoken { $$ = $1; }
1248 /* empty */ { $$ = true; }
1249 | XSensitivToken { $$ = true; }
1250 | XInSensitivToken { $$ = false; }
1253 /********** XERSTUFF "raw" attributes */
1255 XERattributes: /* a non-empty list */
1256 XERattribute { xer_f = true; }
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 */
1266 mymod->set_controlns($1.uri, $1.prefix);
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; }
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_);
1286 xerstruct->name_.nn_ = $1;
1289 { /* overwrites any previous namespace */
1290 Free(xerstruct->namespace_.uri);
1291 Free(xerstruct->namespace_.prefix);
1292 xerstruct->namespace_ = $1;
1296 xerstruct->text_ = (NamespaceSpecification *)Realloc(xerstruct->text_,
1297 ++xerstruct->num_text_ * sizeof(NamespaceSpecification));
1298 xerstruct->text_[xerstruct->num_text_-1] = $1;
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; }
1308 xerstruct->whitespace_ = static_cast<XerAttributes::WhitespaceAction>($1);
1310 | XSD ':' xsddata {}
1314 XKWanyAttributes optNamespaceRestriction
1319 XKWanyElement optNamespaceRestriction
1323 optNamespaceRestriction:
1325 $$.nElements_ = 0; $$.uris_ = 0; $$.type_ = NamespaceRestriction::NOTHING;
1327 | XKWfrom urilist { $$ = $2; $$.type_ = NamespaceRestriction::FROM; }
1328 | XKWexcept urilist { $$ = $2; $$.type_ = NamespaceRestriction::EXCEPT; }
1331 urilist: /* a non-empty list */
1334 $$.uris_ = (char**)Malloc(sizeof($$.uris_[0]));
1337 | urilist ',' quotedURIorAbsent
1340 $$.uris_ = (char**)Realloc($$.uris_, ++$$.nElements_ * sizeof($$.uris_[0]));
1341 $$.uris_[$$.nElements_-1] = $3;
1346 Xstring /* as quotedURI */
1347 | XKWunqualified { $$ = NULL; }
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 */
1362 XKWform XKWas XKWunqualified { $$ = XerAttributes::UNQUALIFIED; }
1363 | XKWform XKWas XKWqualified { $$ = XerAttributes::QUALIFIED; }
1367 XKWname XKWas newnameOrKeyword { $$ = $3; }
1370 newnameOrKeyword: keyword
1371 | Xstring { $$ = $1; }
1375 XKWcapitalized { $$ = (char*)NamespaceSpecification::CAPITALIZED; }
1376 | XKWuncapitalized { $$ = (char*)NamespaceSpecification::UNCAPITALIZED; }
1377 | XKWlowercased { $$ = (char*)NamespaceSpecification::LOWERCASED; }
1378 | XKWuppercased { $$ = (char*)NamespaceSpecification::UPPERCASED; }
1382 XKWnamespace namespacespecification
1386 namespacespecification:
1388 Xstring /* as QuotedURI, required */
1392 $$.uri = $2; $$.prefix = $3;
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");
1400 /* Both are empty strings, use one of the non-string values
1401 * to signal "override and remove any namespace" */
1404 $$.keyword = NamespaceSpecification::UNCAPITALIZED;
1411 optPrefix: /* empty */ { $$ = memptystr(); }
1417 XKWtext Xstring XKWas newnameOrKeyword
1418 { $$.uri = $4; $$.prefix = $2; }
1419 | XKWtext XKWall XKWas newnameOrKeyword
1420 { $$.uri = $4; $$.prefix = (char*)NamespaceSpecification::ALL; }
1422 { $$.uri = 0; $$.prefix = 0; }
1423 /* "text as <something>" is not allowed */
1427 XKWdefaultForEmpty XKWas Xstring
1434 XKWwhiteSpace XKWpreserve { $$ = XerAttributes::PRESERVE; }
1435 | XKWwhiteSpace XKWreplace { $$ = XerAttributes::REPLACE; }
1436 | XKWwhiteSpace XKWcollapse { $$ = XerAttributes::COLLAPSE; }
1439 xsddata: /* XSD:something */
1441 xerstruct->base64_ = true;
1444 xerstruct->decimal_ = true;
1447 xerstruct->hex_ = true;
1450 xerstruct->useQName_ = true;
1452 /* everything below is recognized and ignored */
1456 | XSDnormalizedString {}
1466 /* TODO apply subtype to the types below */
1468 | XSDpositiveInteger {}
1469 | XSDnonPositiveInteger {}
1470 | XSDnegativeInteger {}
1471 | XSDnonNegativeInteger {}
1472 | XSDunsignedLong {}
1475 | XSDunsignedShort {}
1477 | XSDunsignedByte {}
1494 | XSDanySimpleType {}
1501 XKWjson XOptSpaces ':' XOptSpaces XJsonAttribute
1512 XKWomit XSpaces XKWas XSpaces XKWnull { jsonstruct->omit_as_null = true; }
1516 XKWname XSpaces XKWas XSpaces XAliasToken { jsonstruct->alias = mcopystr($5); }
1520 XKWas XSpaces XKWvalue { jsonstruct->as_value = true; }
1524 XKWdefault XOptSpaces XJsonValueStart XJsonValue XJsonValueEnd { jsonstruct->default_value = mcopystr($4); }
1525 | XKWdefault XOptSpaces XJsonValueStart XJsonValueEnd { jsonstruct->default_value = mcopystr(""); }
1529 XJsonValue XJsonValueSegment { $$ = mcopystr($1); $$ = mputstr($$, $2); }
1530 | XJsonValueSegment { $$ = mcopystr($1); }
1550 /* parse_rawAST(), which calls our rawAST_parse, is over in rawASST.l */
1553 static void yyprint(FILE *file, int type, const YYSTYPE& value)
1557 fprintf(file, "``%s''", value.identifier->get_name().c_str());
1560 fprintf(file, "``%s''", value.str);
1563 fprintf(file, "# %d", type);
1572 indent-tabs-mode: nil