1 /******************************************************************************
2 * Copyright (c) 2000-2015 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
8 /* RAW encoding/decoding specification parser & compiler */
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
156 %token XUnsignedKeyword
162 %token XKWcapitalized "capitalized"
163 %token XKWuncapitalized "uncapitalized"
164 %token XKWlowercased "lowercased"
165 %token XKWuppercased "uppercased"
166 %token XKWpreserve "preserve"
167 %token XKWreplace "replace"
168 %token XKWcollapse "collapse"
169 %token XKWfrom "from"
170 %token XKWexcept "except"
171 %token XKWunqualified "unqualified"
172 %token XKWqualified "qualified"
173 %token XKWprefix "prefix"
176 %token XKWabstract "abstact"
177 %token XKWanyAttributes "anyAttributes"
178 %token XKWanyElement "anyElement"
179 %token XKWattribute "attribute"
180 %token XKWattributeFormQualified "attributeFormQualified"
181 %token XKWblock "block"
182 %token XKWcontrolNamespace "controlNamespace"
183 %token XKWdefaultForEmpty "defaultForEmpty"
184 %token XKWelement "element"
185 %token XKWelementFormQualified "elementFormQualified"
186 %token XKWembedValues "embedValues"
187 %token XKWform "form"
188 %token XKWlist "list"
189 %token XKWname "name"
190 %token XKWnamespace "namespace"
191 %token XKWtext "text"
192 %token XKWuntagged "untagged"
193 %token XKWuseNil "useNil"
194 %token XKWuseNumber "useNumber"
195 %token XKWuseOrder "useOrder"
196 %token XKWuseUnion "useUnion"
197 %token XKWuseType "useType"
198 %token XKWwhiteSpace "whiteSpace"
202 %token XSDstring "string"
203 %token XSDnormalizedString "normalizedString"
204 %token XSDtoken "token"
205 %token XSDName "Name"
206 %token XSDNMTOKEN "NMTOKEN"
207 %token XSDNCName "NCName"
209 %token XSDIDREF "IDREF"
210 %token XSDENTITY "ENTITY"
211 %token XSDhexBinary "hexBinary"
212 %token XSDbase64Binary "base64Binary"
213 %token XSDanyURI "anyURI"
214 %token XSDlanguage "language"
215 %token XSDinteger "integer"
216 %token XSDpositiveInteger "positiveInteger"
217 %token XSDnonPositiveInteger "nonPositiveInteger"
218 %token XSDnegativeInteger "negativeInteger"
219 %token XSDnonNegativeInteger "nonNegativeInteger"
220 /* XKWlong instead of %token XSDlong */
221 %token XSDunsignedLong "unsignedLong"
223 %token XSDunsignedInt "unsignedInt"
224 /* XKWshort instead of %token XSDshort */
225 %token XSDunsignedShort "unsignedShort"
226 %token XSDbyte "byte"
227 %token XSDunsignedByte "unsignedByte"
228 %token XSDdecimal "decimal"
229 %token XSDfloat "float"
230 %token XSDdouble "double"
231 %token XSDduration "duration"
232 %token XSDdateTime "dateTime"
233 %token XSDtime "time"
234 %token XSDdate "date"
235 %token XSDgYearMonth "gYearMonth"
236 %token XSDgYear "gYear"
237 %token XSDgMonthDay "gMonthDay"
238 %token XSDgDay "gDay"
239 %token XSDgMonth "gMonth"
240 %token XSDNMTOKENS "NMTOKENS"
241 %token XSDIDREFS "IDREFS"
242 %token XSDENTITIES "ENTITIES"
243 %token XSDQName "QName"
244 %token XSDboolean "boolean"
245 %token XSDanySimpleType "anySimpleType"
246 %token XSDanyType "anyType"
251 %token XKWlength "length"
252 %token XKWaccept "accept"
253 %token XKWlong "long"
254 %token XKWshort "short"
255 %token XKWindefinite "indefinite"
256 %token XKWdefinite "definite"
260 %token XKWjson "JSON"
261 %token XKWomit "omit"
262 %token XKWnull "null"
263 %token XAliasToken "JSON alias"
264 %token XKWvalue "value"
265 %token XKWdefault "default"
266 %token XKWextend "extend"
267 %token XKWmetainfo "metainfo"
269 %token XKWunbound "unbound"
270 %token XJsonValueStart "("
271 %token XJsonValueEnd ")"
272 %token XJsonValueSegment "JSON value"
276 XYesOrNo XMsbOrLsb XFieldOrderDef XPaddingDef XExtensionBitDef XUnitDef
277 XBitsOctets XAlignDef XLeftOrRight XCompDef XCompValues XByteOrderDef
278 XFirstOrLast XBitOrderDef XBitOrderInFieldDef XBitOrderInOctetDef
279 XHexOrderDef XLowOrHigh XYesOrNoOrReverse XFieldLengthDef
280 XPtrOffsetDef XPrePaddingDef XRepeatableDef form
283 XLengthIndexDef XStructFieldRefOrEmpty XStructFieldRef
286 XEncodeToken XmatchDef XAliasToken XJsonValueSegment XJsonValueCore XJsonValue
295 XPointerToDef XRecordFieldRef XIdentifierOrReserved
303 /* note: multiple "XSingleEncodingDefs have to be merged into one 'fullspec' */
305 XEncodingDefList XSingleEncodingDef
313 XAssocElement XKeyIdOrIdList XKeyIdList XMultiKeyId
316 XToplevelDef XTopDefList XTopDef
320 anyAttributes anyElement optNamespaceRestriction urilist
323 %type <str> defaultForEmpty name newnameOrKeyword keyword optPrefix quotedURIorAbsent
325 %type <nsspec> namespace namespacespecification controlNamespace text
327 %type <intval> whiteSpace
330 %destructor { Free($$); }
344 %destructor { delete $$; }
346 XIdentifierOrReserved
350 %destructor { free_rawAST_field_list($$); }
353 XStructFieldRefOrEmpty
355 %destructor { free_rawAST_tag_list(&$$); }
358 %destructor { free_rawAST_tag_field_value(&$$); }
361 %destructor { free_rawAST_single_tag(&$$); }
373 %destructor { Free($$.token); }
377 FreeNamespaceRestriction($$);
379 anyAttributes anyElement optNamespaceRestriction urilist
386 namespacespecification
396 XAttribSpec : /* Empty */
406 XKWlength XKWaccept XKWshort { berstruct->decode_param = BerAST::LENGTH_ACCEPT_SHORT; ber_f=true; }
407 | XKWlength XKWaccept XKWlong { berstruct->decode_param = BerAST::LENGTH_ACCEPT_LONG; ber_f=true; }
408 | XKWlength XKWaccept XKWindefinite { berstruct->decode_param = BerAST::LENGTH_ACCEPT_INDEFINITE; ber_f=true; }
409 | XKWlength XKWaccept XKWdefinite { berstruct->decode_param = BerAST::LENGTH_ACCEPT_DEFINITE; ber_f=true; }
412 XEncodingDefList : XSingleEncodingDef
414 | XEncodingDefList ',' XSingleEncodingDef
417 XSingleEncodingDef : XPaddingDef
418 { rawstruct->padding=$1;raw_f=true;}
420 { rawstruct->prepadding=$1;raw_f=true;}
421 | XPaddingPattern { raw_f=true;}
422 | XPaddAll { rawstruct->paddall=XDEFYES;raw_f=true;}
424 { rawstruct->fieldorder=$1;raw_f=true;}
426 { rawstruct->extension_bit=$1;raw_f=true;}
427 | XExtensionBitGroupDef
432 { delete rawstruct->pointerto;
433 rawstruct->pointerto = $1;
437 { rawstruct->unit=$1; raw_f=true;}
439 { free_rawAST_field_list(rawstruct->lengthindex);
440 rawstruct->lengthindex = $1;raw_f=true; }
448 { rawstruct->fieldlength = $1*length_multiplier; raw_f=true;}
452 { rawstruct->align = $1; raw_f=true;}
454 { rawstruct->comp = $1;raw_f=true; }
456 { rawstruct->byteorder = $1; raw_f=true;}
457 | XBitOrderInFieldDef
458 { rawstruct->bitorderinfield = $1; raw_f=true;}
459 | XBitOrderInOctetDef
460 { rawstruct->bitorderinoctet = $1; raw_f=true;}
462 { rawstruct->hexorder = $1;raw_f=true; }
464 { rawstruct->repeatable = $1;raw_f=true; }
466 { rawstruct->topleveleind=1; raw_f=true;}
468 { rawstruct->intx = true; raw_f = true; }
471 /* TEXT encoder keywords */
484 XRepeatableDef : XRepeatableKeyword '(' XYesOrNo ')' { $$ = $3; }
487 XPaddingDef : XPaddingKeyword '(' XYesOrNo ')' { $$ = $3==XDEFYES?8:0; }
488 | XPaddingKeyword '(' XBitsOctets ')' { $$ = $3;};
489 XPrePaddingDef : XPrePaddingKeyword '(' XYesOrNo ')' { $$ = $3==XDEFYES?8:0; }
490 | XPrePaddingKeyword '(' XBitsOctets ')' { $$ = $3;};
491 XYesOrNo : XYes | XNo;
494 XPaddingPatternKeyword '(' XBstring ')'
496 Free(rawstruct->padding_pattern);
497 size_t len = strlen($3);
499 rawstruct->padding_pattern = mcopystr($3);
500 rawstruct->padding_pattern_length = len;
501 while (rawstruct->padding_pattern_length % 8 != 0) {
502 rawstruct->padding_pattern = mputstr(rawstruct->padding_pattern, $3);
503 rawstruct->padding_pattern_length += len;
505 } else rawstruct->padding_pattern = NULL;
510 XPaddAll: XPaddAllKeyword
512 XFieldOrderDef : XFieldOrderKeyword '(' XMsbOrLsb ')'
514 XMsbOrLsb : XMsb | XLsb;
517 XExtensionBitDef : XExtensionBitKeyword '(' XYesOrNoOrReverse ')'
519 XYesOrNoOrReverse : XYes | XNo | XReverse;
521 XExtensionBitGroupDef: XExtensionBitGroupKeyword '(' XYesOrNoOrReverse ','
522 XIdentifier ',' XIdentifier ')'
523 { if(rawstruct->ext_bit_goup_num==0){
524 rawstruct->ext_bit_groups=
525 (rawAST_ext_bit_group*)Malloc(sizeof(rawAST_ext_bit_group));
526 rawstruct->ext_bit_goup_num=1;
528 rawstruct->ext_bit_goup_num++;
529 rawstruct->ext_bit_groups=(rawAST_ext_bit_group*)
530 Realloc(rawstruct->ext_bit_groups,
531 rawstruct->ext_bit_goup_num*sizeof(rawAST_ext_bit_group));
533 rawstruct->ext_bit_groups[rawstruct->ext_bit_goup_num-1].ext_bit=$3;
534 rawstruct->ext_bit_groups[rawstruct->ext_bit_goup_num-1].from=$5;
535 rawstruct->ext_bit_groups[rawstruct->ext_bit_goup_num-1].to=$7;
539 XLengthToDef : XLengthToKeyword '(' XRecordFieldRefList ')'
543 XPointerToDef : XPointerToKeyword '(' XRecordFieldRef ')'
547 XUnitDef : XUnitKeyword '(' XBitsOctets ')' { $$ = $3; }
548 | XPtrUnitKeyword '(' XBitsOctets ')' { $$ = $3; };
549 XBitsOctets : XBits {$$=$1;}
554 XLengthIndexDef : XLengthIndexKeyword '(' XStructFieldRefOrEmpty ')'
559 XTagDef : XTagKeyword '(' XAssocList XoptSemiColon ')'
560 { free_rawAST_tag_list(&(rawstruct->taglist));
561 link_rawAST_tag_list(&(rawstruct->taglist),&$3);};
562 XCrossTagDef : XCrossTagKeyword '(' XAssocList XoptSemiColon ')'
563 { free_rawAST_tag_list(&(rawstruct->crosstaglist));
564 link_rawAST_tag_list(&(rawstruct->crosstaglist),&$3);};
570 $$.tag = (rawAST_single_tag*)Malloc(sizeof(*$$.tag));
571 link_rawAST_single_tag($$.tag, &$1);
573 | XAssocList XSemiColon XAssocElement
575 int dupl_id_index = -1;
576 if ($3.nElements > 0) {
577 /* the otherwise element is never merged */
578 for (int i = 0; i < $1.nElements; i++)
579 if (*$1.tag[i].fieldName == *$3.fieldName) {
584 if (dupl_id_index >= 0) {
585 /* this identifier is already specified in XAssocList
586 merge the new parameters to the existing entry */
588 rawAST_single_tag *tag = $$.tag + dupl_id_index;
589 tag->keyList = (rawAST_tag_field_value*)
590 Realloc(tag->keyList, (tag->nElements + $3.nElements)
591 * sizeof(*tag->keyList));
592 memcpy(tag->keyList + tag->nElements, $3.keyList,
593 $3.nElements * sizeof(*$3.keyList));
594 tag->nElements += $3.nElements;
598 $$.nElements = $1.nElements + 1;
599 $$.tag = (rawAST_single_tag*)
600 Realloc($1.tag, $$.nElements * sizeof(*$$.tag));
601 $$.tag[$1.nElements] = $3;
616 XIdentifier ',' XKeyIdOrIdList
619 $$.nElements = $3.nElements;
620 $$.keyList = $3.keyList;
622 | XIdentifier ',' XOtherwise
635 $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList));
638 | XKeyIdList { $$ = $1; }
642 '{' XMultiKeyId '}' { $$ = $2; }
650 $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList));
653 | XMultiKeyId ',' XKeyId
656 $$.nElements = $1.nElements + 1;
657 $$.keyList = (rawAST_tag_field_value*)
658 Realloc($1.keyList, $$.nElements * sizeof(*$$.keyList));
659 $$.keyList[$1.nElements] = $3;
664 XStructFieldRef '=' XRvalue
668 $$.v_value = $3.v_value;
673 XPresenceDef : XPresenceKeyword '(' XKeyIdList XoptSemiColon ')'
674 { free_rawAST_single_tag(&(rawstruct->presence));
675 link_rawAST_single_tag(&(rawstruct->presence), &$3);}
676 | XPresenceKeyword '(' XMultiKeyId XoptSemiColon ')'
677 { free_rawAST_single_tag(&(rawstruct->presence));
678 link_rawAST_single_tag(&(rawstruct->presence), &$3);};
682 XFieldLengthDef : XFieldLengthKeyword '(' XNumber ')'
686 XPtrOffsetDef : XPtrOffsetKeyword '(' XNumber ')'
687 { rawstruct->ptroffset = $3; }
688 |XPtrOffsetKeyword '(' XIdentifier ')'
690 delete rawstruct->ptrbase;
691 rawstruct->ptrbase = $3;
694 XAlignDef : XAlignKeyword '(' XLeftOrRight ')'
696 XLeftOrRight : XLeft | XRight;
699 XCompDef : XCompKeyword '(' XCompValues ')'
701 XCompValues : XUnsigned | XCompl | XSignbit;
704 XByteOrderDef : XByteOrderKeyword '(' XFirstOrLast ')'
706 XFirstOrLast : XFirst | XLast;
709 XBitOrderInFieldDef : XBitOrderInFieldKeyword '(' XMsbOrLsb ')'
711 XBitOrderInOctetDef : XBitOrderInOctetKeyword '(' XMsbOrLsb ')'
713 | XBitOrderKeyword '(' XMsbOrLsb ')' { $$ = $3; };
714 XToplevelDef : XToplevelKeyword '(' XTopDefList ')'
716 XTopDefList : XTopDef
718 | XTopDefList ',' XTopDef
720 XTopDef : XBitOrderDef
721 { rawstruct->toplevel.bitorder = $1;};
722 XBitOrderDef : XBitOrderKeyword '(' XMsbOrLsb ')'
726 XHexOrderDef : XHexOrderKeyword '(' XLowOrHigh ')'
728 XLowOrHigh : XLow | XHigh;
732 XRecordFieldRefList : XRecordFieldRef
733 { rawstruct->lengthto_num = 1;
734 rawstruct->lengthto =
735 (Common::Identifier**)Malloc(sizeof(*(rawstruct->lengthto)));
736 rawstruct->lengthto[0] = $1;
738 | XRecordFieldRefList ',' XRecordFieldRef
739 { rawstruct->lengthto_num++;
740 rawstruct->lengthto =
741 (Common::Identifier**)Realloc(rawstruct->lengthto,
742 rawstruct->lengthto_num*sizeof(*(rawstruct->lengthto)));
743 rawstruct->lengthto[rawstruct->lengthto_num - 1] = $3;
747 XRecordFieldRef : XIdentifier
750 XStructFieldRefOrEmpty : /* Empty */
755 XStructFieldRef : XIdentifier
756 { $$ = (rawAST_field_list*)Malloc(sizeof(*$$));
758 $$->names = (Common::Identifier**)Malloc(sizeof(*($$->names)));
761 | XStructFieldRef '.' XIdentifier
764 $$->names = (Common::Identifier**)
765 Realloc($$->names, $$->nElements*sizeof(*($$->names)));
766 $$->names[$$->nElements - 1] = $3;
770 XRvalue: XIdentifier{
771 $$.value = mcopystr($1->get_name().c_str());
772 $$.v_value = new Common::Value(Common::Value::V_UNDEF_LOWERID, $1);
773 $$.v_value->set_location(infile, @$);
776 string *str= new string($1);
777 $$.value=mprintf(" %s", mymod->add_bitstring_literal(*str).c_str());
778 $$.v_value=new Common::Value(Common::Value::V_BSTR,str);
779 $$.v_value->set_location(infile, @$);
783 string *str= new string($1);
784 $$.value=mprintf(" %s", mymod->add_hexstring_literal(*str).c_str());
785 $$.v_value=new Common::Value(Common::Value::V_HSTR,str);
786 $$.v_value->set_location(infile, @$);
791 string *str= new string($1);
792 $$.value=mprintf(" %s", mymod->add_octetstring_literal(*str).c_str());
793 $$.v_value=new Common::Value(Common::Value::V_OSTR,str);
794 $$.v_value->set_location(infile, @$);
798 Common::Location loc(infile, @$);
799 string *str = parse_charstring_value($1, loc);
801 $$.value=mprintf(" %s", mymod->add_charstring_literal(*str).c_str());
802 $$.v_value=new Common::Value(Common::Value::V_CSTR,str);
803 $$.v_value->set_location(loc);
806 $$.value=mcopystr(Common::Real2code($1).c_str());
807 $$.v_value=new Common::Value(Common::Value::V_REAL, $1);
808 $$.v_value->set_location(infile, @$);
811 $$.value = mcopystr(Common::Int2string($1).c_str());
812 $$.v_value=new Common::Value(Common::Value::V_INT, $1);
813 $$.v_value->set_location(infile, @$);
817 $$.value = mcopystr($1 ? "TRUE" : "FALSE");
818 $$.v_value=new Common::Value(Common::Value::V_BOOL, $1);
819 $$.v_value->set_location(infile, @$);
823 $$.v_value = new Common::Value(Common::Value::V_VERDICT, $1);
824 $$.v_value->set_location(infile, @$);
825 $$.value = mcopystr($$.v_value->get_single_expr().c_str());
829 $$.value = mcopystr("NULL_COMPREF");
830 $$.v_value = new Common::Value(Common::Value::V_TTCN3_NULL);
831 $$.v_value->set_location(infile, @$);
835 $$.value = mcopystr("ASN_NULL_VALUE");
836 $$.v_value = new Common::Value(Common::Value::V_NULL);
837 $$.v_value->set_location(infile, @$);
841 $$.value = mcopystr("OMIT_VALUE");
842 $$.v_value = new Common::Value(Common::Value::V_OMIT);
843 $$.v_value->set_location(infile, @$);
847 /* Alternative RAW attributes for types defined in annex E of the TTCN-3 standard */
851 rawstruct->fieldlength = $1;
852 rawstruct->comp = XDEFSIGNBIT;
853 rawstruct->byteorder = XDEFLAST;
855 | XUnsignedKeyword XNumber XBitKeyword
857 rawstruct->fieldlength = $2;
858 rawstruct->comp = XDEFUNSIGNED;
859 rawstruct->byteorder = XDEFLAST;
865 XBeginKeyword '(' XEncodeToken ')' {
866 if(textstruct->begin_val==NULL){
867 textstruct->begin_val=(textAST_matching_values*)
868 Malloc(sizeof(textAST_matching_values));
869 init_textAST_matching_values(textstruct->begin_val);
871 Free(textstruct->begin_val->encode_token);
872 textstruct->begin_val->encode_token=$3;
874 | XBeginKeyword '(' XEncodeToken ',' XmatchDef ')' {
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 Free(textstruct->begin_val->decode_token);
884 textstruct->begin_val->decode_token=$5;
887 | XBeginKeyword '(' XEncodeToken ',' XmatchDef ',' XmodifierDef ')'{
888 if(textstruct->begin_val==NULL){
889 textstruct->begin_val=(textAST_matching_values*)
890 Malloc(sizeof(textAST_matching_values));
891 init_textAST_matching_values(textstruct->begin_val);
893 Free(textstruct->begin_val->encode_token);
894 textstruct->begin_val->encode_token=$3;
896 Free(textstruct->begin_val->decode_token);
897 textstruct->begin_val->decode_token=$5;
899 textstruct->begin_val->case_sensitive=$7;
904 XEndKeyword '(' XEncodeToken ')' {
905 if(textstruct->end_val==NULL){
906 textstruct->end_val=(textAST_matching_values*)
907 Malloc(sizeof(textAST_matching_values));
908 init_textAST_matching_values(textstruct->end_val);
910 Free(textstruct->end_val->encode_token);
911 textstruct->end_val->encode_token=$3;
913 | XEndKeyword '(' XEncodeToken ',' XmatchDef ')'{
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 Free(textstruct->end_val->decode_token);
923 textstruct->end_val->decode_token=$5;
926 | XEndKeyword '(' XEncodeToken ',' XmatchDef ',' XmodifierDef ')'{
927 if(textstruct->end_val==NULL){
928 textstruct->end_val=(textAST_matching_values*)
929 Malloc(sizeof(textAST_matching_values));
930 init_textAST_matching_values(textstruct->end_val);
932 Free(textstruct->end_val->encode_token);
933 textstruct->end_val->encode_token=$3;
935 Free(textstruct->end_val->decode_token);
936 textstruct->end_val->decode_token=$5;
938 textstruct->end_val->case_sensitive=$7;
943 XSeparatorKeyword '(' XEncodeToken ')'{
944 if(textstruct->separator_val==NULL){
945 textstruct->separator_val=(textAST_matching_values*)
946 Malloc(sizeof(textAST_matching_values));
947 init_textAST_matching_values(textstruct->separator_val);
949 Free(textstruct->separator_val->encode_token);
950 textstruct->separator_val->encode_token=$3;
952 | XSeparatorKeyword '(' XEncodeToken ',' XmatchDef ')'{
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 Free(textstruct->separator_val->decode_token);
962 textstruct->separator_val->decode_token=$5;
965 | XSeparatorKeyword '(' XEncodeToken ',' XmatchDef ',' XmodifierDef ')'{
966 if(textstruct->separator_val==NULL){
967 textstruct->separator_val=(textAST_matching_values*)
968 Malloc(sizeof(textAST_matching_values));
969 init_textAST_matching_values(textstruct->separator_val);
971 Free(textstruct->separator_val->encode_token);
972 textstruct->separator_val->encode_token=$3;
974 Free(textstruct->separator_val->decode_token);
975 textstruct->separator_val->decode_token=$5;
977 textstruct->separator_val->case_sensitive=$7;
982 XCodingKeyword '(' XCodingRule ')'
984 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ')'
986 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ')' {
987 Free(textstruct->decode_token);
988 textstruct->decode_token=$7;
990 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ','
993 Free(textstruct->decode_token);
994 textstruct->decode_token=$7;
996 textstruct->case_sensitive=$9;
1009 | XDecodingtokendefList {}
1014 | XattrList ';' Xattr {}
1018 XLengthToken '=' XNumber {
1019 textstruct->decoding_params.min_length=$3;
1021 | XLengthToken '=' XNumber '-' XNumber {
1022 textstruct->decoding_params.min_length=$3;
1023 textstruct->decoding_params.max_length=$5;
1025 | XConvertToken '=' XLowerToken {
1026 textstruct->decoding_params.convert=-1;
1028 | XConvertToken '=' XUpperToken {
1029 textstruct->decoding_params.convert=1;
1031 | XJustToken '=' XLeftToken {
1032 textstruct->decoding_params.just=-1;
1034 | XJustToken '=' XRightToken {
1035 textstruct->decoding_params.just=1;
1037 | XJustToken '=' XCenterToken {
1038 textstruct->decoding_params.just=0;
1040 | XLeadingToken '=' XTrueToken {
1041 textstruct->decoding_params.leading_zero=true;
1043 | XLeadingToken '=' XFalseToken {
1044 textstruct->decoding_params.leading_zero=false;
1046 | XRepeatToken '=' XTrueToken {
1047 textstruct->decoding_params.repeatable=true;
1049 | XRepeatToken '=' XFalseToken {
1050 textstruct->decoding_params.repeatable=false;
1055 | Xattrlistenc ';' Xattrenc {}
1059 XLengthToken '=' XNumber {
1060 textstruct->coding_params.min_length=$3;
1061 textstruct->decoding_params.min_length=$3;
1063 | XLengthToken '=' XNumber '-' XNumber {
1064 textstruct->coding_params.min_length=$3;
1065 textstruct->coding_params.max_length=$5;
1066 textstruct->decoding_params.min_length=$3;
1067 textstruct->decoding_params.max_length=$5;
1069 | XConvertToken '=' XLowerToken {
1070 textstruct->coding_params.convert=-1;
1071 textstruct->decoding_params.convert=-1;
1073 | XConvertToken '=' XUpperToken {
1074 textstruct->coding_params.convert=1;
1075 textstruct->decoding_params.convert=1;
1077 | XJustToken '=' XLeftToken {
1078 textstruct->coding_params.just=-1;
1079 textstruct->decoding_params.just=-1;
1081 | XJustToken '=' XRightToken {
1082 textstruct->coding_params.just=1;
1083 textstruct->decoding_params.just=1;
1085 | XJustToken '=' XCenterToken {
1086 textstruct->coding_params.just=0;
1087 textstruct->decoding_params.just=0;
1089 | XLeadingToken '=' XTrueToken {
1090 textstruct->coding_params.leading_zero=true;
1091 textstruct->decoding_params.leading_zero=true;
1093 | XLeadingToken '=' XFalseToken {
1094 textstruct->coding_params.leading_zero=false;
1095 textstruct->decoding_params.leading_zero=false;
1097 | XRepeatToken '=' XTrueToken {
1098 textstruct->coding_params.repeatable=true;
1099 textstruct->decoding_params.repeatable=true;
1101 | XRepeatToken '=' XFalseToken {
1102 textstruct->coding_params.repeatable=false;
1103 textstruct->decoding_params.repeatable=false;
1109 | XtokendefList ';' Xtokendef {}
1113 XIdentifierOrReserved ':' XEncodeToken
1115 int idx = textstruct->get_field_param_index($1);
1116 if (textstruct->field_params[idx]->value.encode_token) {
1117 Free(textstruct->field_params[idx]->value.encode_token);
1118 Common::Location loc(infile, @3);
1119 loc.error("Duplicate encode token for value `%s'",
1120 $1->get_dispname().c_str());
1122 textstruct->field_params[idx]->value.encode_token = $3;
1125 | XTrueToken ':' XEncodeToken
1127 if (textstruct->true_params == NULL) {
1128 textstruct->true_params = (textAST_matching_values*)
1129 Malloc(sizeof(textAST_matching_values));
1130 textstruct->true_params->encode_token = $3;
1131 textstruct->true_params->decode_token = NULL;
1132 textstruct->true_params->case_sensitive = true;
1133 textstruct->true_params->generated_decode_token = false;
1135 if (textstruct->true_params->encode_token) {
1136 Free(textstruct->true_params->encode_token);
1137 Common::Location loc(infile, @3);
1138 loc.error("Duplicate encode token for true value");
1140 textstruct->true_params->encode_token = $3;
1143 | XFalseToken ':' XEncodeToken
1145 if (textstruct->false_params == NULL) {
1146 textstruct->false_params = (textAST_matching_values*)
1147 Malloc(sizeof(textAST_matching_values));
1148 textstruct->false_params->encode_token = $3;
1149 textstruct->false_params->decode_token = NULL;
1150 textstruct->false_params->case_sensitive = true;
1151 textstruct->false_params->generated_decode_token = false;
1153 if (textstruct->false_params->encode_token) {
1154 Free(textstruct->false_params->encode_token);
1155 Common::Location loc(infile, @3);
1156 loc.error("Duplicate encode token for false value");
1158 textstruct->false_params->encode_token = $3;
1163 XIdentifierOrReserved:
1164 XIdentifier { $$ = $1; }
1166 { $$ = new Common::Identifier(Common::Identifier::ID_TTCN, string($1)); }
1170 XLengthToken { $$ = "length"; }
1171 | XRepeatToken { $$ = "repeatable"; }
1172 | XConvertToken { $$ = "convert"; }
1173 | XLowerToken { $$ = "lower_case"; }
1174 | XUpperToken { $$ = "upper_case"; }
1175 | XJustToken { $$ = "just"; }
1176 | XLeftToken { $$ = "left"; }
1177 | XRightToken { $$ = "right"; }
1178 | XCenterToken { $$ = "center"; }
1179 | XLeadingToken { $$ = "leading0"; }
1180 | XSensitivToken { $$ = "case_sensitive"; }
1181 | XInSensitivToken { $$ = "case_insensitive"; }
1184 XDecodingtokendefList:
1185 Xdecodingtokendef {}
1186 | XDecodingtokendefList ';' Xdecodingtokendef {}
1190 XIdentifierOrReserved ':' XDecodeToken
1192 int idx = textstruct->get_field_param_index($1);
1193 if (textstruct->field_params[idx]->value.decode_token) {
1194 Free(textstruct->field_params[idx]->value.decode_token);
1195 Common::Location loc(infile, @3);
1196 loc.error("Duplicate decode token for value `%s'",
1197 $1->get_dispname().c_str());
1199 textstruct->field_params[idx]->value.decode_token = $3.token;
1200 textstruct->field_params[idx]->value.case_sensitive = $3.case_sensitive;
1203 | XTrueToken ':' XDecodeToken
1205 if (textstruct->true_params == NULL) {
1206 textstruct->true_params = (textAST_matching_values*)
1207 Malloc(sizeof(textAST_matching_values));
1208 textstruct->true_params->encode_token = NULL;
1209 textstruct->true_params->decode_token = $3.token;
1210 textstruct->true_params->case_sensitive = $3.case_sensitive;
1211 textstruct->true_params->generated_decode_token = false;
1213 if (textstruct->true_params->decode_token) {
1214 Free(textstruct->true_params->decode_token);
1215 Common::Location loc(infile, @3);
1216 loc.error("Duplicate decode token for true value");
1218 textstruct->true_params->decode_token = $3.token;
1219 textstruct->true_params->case_sensitive = $3.case_sensitive;
1222 | XFalseToken ':' XDecodeToken
1224 if (textstruct->false_params == NULL) {
1225 textstruct->false_params = (textAST_matching_values*)
1226 Malloc(sizeof(textAST_matching_values));
1227 textstruct->false_params->encode_token = NULL;
1228 textstruct->false_params->decode_token= $3.token;
1229 textstruct->false_params->case_sensitive = $3.case_sensitive;
1230 textstruct->false_params->generated_decode_token = false;
1232 if (textstruct->false_params->decode_token) {
1233 Free(textstruct->false_params->decode_token);
1234 Common::Location loc(infile, @3);
1235 loc.error("Duplicate decode token for false value");
1237 textstruct->false_params->decode_token = $3.token;
1238 textstruct->false_params->case_sensitive = $3.case_sensitive;
1246 Common::Location loc(infile, @$);
1247 string *str = parse_charstring_value($1, loc);
1249 $$ = mcopystr(str->c_str());
1258 $$.case_sensitive = true;
1263 $$.case_sensitive = true;
1265 | '{' XmatchDef ',' XmodifierDef '}'
1268 $$.case_sensitive = $4;
1273 /* empty */ { $$ = NULL; }
1274 | Xtoken { $$ = $1; }
1278 /* empty */ { $$ = true; }
1279 | XSensitivToken { $$ = true; }
1280 | XInSensitivToken { $$ = false; }
1283 /********** XERSTUFF "raw" attributes */
1285 XERattributes: /* a non-empty list */
1286 XERattribute { xer_f = true; }
1290 XKWabstract { xerstruct->abstract_ = true; }
1291 | anyAttributes { FreeNamespaceRestriction(xerstruct->anyAttributes_); xerstruct->anyAttributes_ = $1; }
1292 | anyElement { FreeNamespaceRestriction(xerstruct->anyElement_); xerstruct->anyElement_ = $1; }
1293 | XKWattribute { xerstruct->attribute_ = true; }
1294 | XKWattributeFormQualified { xerstruct->form_ |= XerAttributes::ATTRIBUTE_DEFAULT_QUALIFIED; }
1295 | XKWblock { xerstruct->block_ = true; }
1296 | controlNamespace /* directly on the module */
1298 mymod->set_controlns($1.uri, $1.prefix);
1300 | defaultForEmpty { xerstruct->defaultForEmpty_ = $1; }
1301 | XKWelement { xerstruct->element_ = true; }
1302 | XKWelementFormQualified { xerstruct->form_ |= XerAttributes::ELEMENT_DEFAULT_QUALIFIED; }
1303 | XKWembedValues { xerstruct->embedValues_ = true; }
1304 | form { xerstruct->form_ |= $1; }
1305 | XKWlist { xerstruct->list_ = true; }
1307 { /* overwrites any previous name */
1308 switch (xerstruct->name_.kw_) {
1309 case NamespaceSpecification::NO_MANGLING:
1310 case NamespaceSpecification::CAPITALIZED:
1311 case NamespaceSpecification::UNCAPITALIZED:
1312 case NamespaceSpecification::UPPERCASED:
1313 case NamespaceSpecification::LOWERCASED:
1314 break; // nothing to do
1315 default: // real string, must be freed
1316 Free(xerstruct->name_.nn_);
1318 xerstruct->name_.nn_ = $1;
1321 { /* overwrites any previous namespace */
1322 Free(xerstruct->namespace_.uri);
1323 Free(xerstruct->namespace_.prefix);
1324 xerstruct->namespace_ = $1;
1328 xerstruct->text_ = (NamespaceSpecification *)Realloc(xerstruct->text_,
1329 ++xerstruct->num_text_ * sizeof(NamespaceSpecification));
1330 xerstruct->text_[xerstruct->num_text_-1] = $1;
1332 | XKWuntagged { xerstruct->untagged_ = true; }
1333 | XKWuseNil { xerstruct->useNil_ = true; }
1334 | XKWuseNumber { xerstruct->useNumber_ = true; }
1335 | XKWuseOrder { xerstruct->useOrder_ = true; }
1336 | XKWuseUnion { xerstruct->useUnion_ = true; }
1337 | XKWuseType { xerstruct->useType_ = true; }
1340 xerstruct->whitespace_ = static_cast<XerAttributes::WhitespaceAction>($1);
1342 | XSD ':' xsddata {}
1346 XKWanyAttributes optNamespaceRestriction
1351 XKWanyElement optNamespaceRestriction
1355 optNamespaceRestriction:
1357 $$.nElements_ = 0; $$.uris_ = 0; $$.type_ = NamespaceRestriction::NOTHING;
1359 | XKWfrom urilist { $$ = $2; $$.type_ = NamespaceRestriction::FROM; }
1360 | XKWexcept urilist { $$ = $2; $$.type_ = NamespaceRestriction::EXCEPT; }
1363 urilist: /* a non-empty list */
1366 $$.uris_ = (char**)Malloc(sizeof($$.uris_[0]));
1369 | urilist ',' quotedURIorAbsent
1372 $$.uris_ = (char**)Realloc($$.uris_, ++$$.nElements_ * sizeof($$.uris_[0]));
1373 $$.uris_[$$.nElements_-1] = $3;
1378 Xstring /* as quotedURI */
1379 | XKWunqualified { $$ = NULL; }
1382 controlNamespace: /* nsspec */
1383 XKWcontrolNamespace Xstring /* <-- as the QuotedURI */ XKWprefix Xstring
1384 /* Prefix is required by TTCN-3; it is optional in the ASN.1 standard
1385 * but the OSS ASN.1 compiler seems to require it anyway */
1394 XKWform XKWas XKWunqualified { $$ = XerAttributes::UNQUALIFIED; }
1395 | XKWform XKWas XKWqualified { $$ = XerAttributes::QUALIFIED; }
1399 XKWname XKWas newnameOrKeyword { $$ = $3; }
1402 newnameOrKeyword: keyword
1403 | Xstring { $$ = $1; }
1407 XKWcapitalized { $$ = (char*)NamespaceSpecification::CAPITALIZED; }
1408 | XKWuncapitalized { $$ = (char*)NamespaceSpecification::UNCAPITALIZED; }
1409 | XKWlowercased { $$ = (char*)NamespaceSpecification::LOWERCASED; }
1410 | XKWuppercased { $$ = (char*)NamespaceSpecification::UPPERCASED; }
1414 XKWnamespace namespacespecification
1418 namespacespecification:
1420 Xstring /* as QuotedURI, required */
1424 $$.uri = $2; $$.prefix = $3;
1426 else { /* URI is empty */
1427 if (*$3) { /* prefix not empty, error */
1428 Common::Location loc(infile, @2);
1429 loc.error("Empty string is not a valid URI");
1432 /* Both are empty strings, use one of the non-string values
1433 * to signal "override and remove any namespace" */
1436 $$.keyword = NamespaceSpecification::UNCAPITALIZED;
1443 optPrefix: /* empty */ { $$ = memptystr(); }
1449 XKWtext Xstring XKWas newnameOrKeyword
1450 { $$.uri = $4; $$.prefix = $2; }
1451 | XKWtext XKWall XKWas newnameOrKeyword
1452 { $$.uri = $4; $$.prefix = (char*)NamespaceSpecification::ALL; }
1454 { $$.uri = 0; $$.prefix = 0; }
1455 /* "text as <something>" is not allowed */
1459 XKWdefaultForEmpty XKWas Xstring
1466 XKWwhiteSpace XKWpreserve { $$ = XerAttributes::PRESERVE; }
1467 | XKWwhiteSpace XKWreplace { $$ = XerAttributes::REPLACE; }
1468 | XKWwhiteSpace XKWcollapse { $$ = XerAttributes::COLLAPSE; }
1471 xsddata: /* XSD:something */
1473 xerstruct->base64_ = true;
1476 xerstruct->decimal_ = true;
1479 xerstruct->hex_ = true;
1482 xerstruct->useQName_ = true;
1484 /* everything below is recognized and ignored */
1488 | XSDnormalizedString {}
1498 /* TODO apply subtype to the types below */
1500 | XSDpositiveInteger {}
1501 | XSDnonPositiveInteger {}
1502 | XSDnegativeInteger {}
1503 | XSDnonNegativeInteger {}
1504 | XSDunsignedLong {}
1507 | XSDunsignedShort {}
1509 | XSDunsignedByte {}
1526 | XSDanySimpleType {}
1533 XOptSpaces XKWjson XOptSpaces ':' XOptSpaces XJsonAttribute XOptSpaces
1542 | XMetainfoForUnbound
1546 XKWomit XSpaces XKWas XSpaces XKWnull { jsonstruct->omit_as_null = true; }
1550 XKWname XSpaces XKWas XSpaces XAliasToken { jsonstruct->alias = mcopystr($5); }
1554 XKWas XSpaces XKWvalue { jsonstruct->as_value = true; }
1558 XKWdefault XOptSpaces XJsonValue { jsonstruct->default_value = mcopystr($3); }
1562 XKWextend XOptSpaces XJsonValue XOptSpaces ':' XOptSpaces XJsonValue
1563 { jsonstruct->schema_extensions.add(new JsonSchemaExtension($3, $7)); }
1567 XJsonValueStart XJsonValueCore XJsonValueEnd { $$ = mcopystr($2); }
1568 | XJsonValueStart XJsonValueEnd { $$ = mcopystr(""); }
1572 XJsonValueCore XJsonValueSegment { $$ = mcopystr($1); $$ = mputstr($$, $2); }
1573 | XJsonValueSegment { $$ = mcopystr($1); }
1576 XMetainfoForUnbound:
1577 XKWmetainfo XOptSpaces XKWfor XOptSpaces XKWunbound { jsonstruct->metainfo_unbound = true; }
1597 /* parse_rawAST(), which calls our rawAST_parse, is over in rawASST.l */
1600 static void yyprint(FILE *file, int type, const YYSTYPE& value)
1604 fprintf(file, "``%s''", value.identifier->get_name().c_str());
1607 fprintf(file, "``%s''", value.str);
1610 fprintf(file, "# %d", type);
1619 indent-tabs-mode: nil