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
160 %token XKWcapitalized "capitalized"
161 %token XKWuncapitalized "uncapitalized"
162 %token XKWlowercased "lowercased"
163 %token XKWuppercased "uppercased"
164 %token XKWpreserve "preserve"
165 %token XKWreplace "replace"
166 %token XKWcollapse "collapse"
167 %token XKWfrom "from"
168 %token XKWexcept "except"
169 %token XKWunqualified "unqualified"
170 %token XKWqualified "qualified"
171 %token XKWprefix "prefix"
174 %token XKWanyAttributes "anyAttributes"
175 %token XKWanyElement "anyElement"
176 %token XKWattribute "attribute"
177 %token XKWattributeFormQualified "attributeFormQualified"
178 %token XKWcontrolNamespace "controlNamespace"
179 %token XKWdefaultForEmpty "defaultForEmpty"
180 %token XKWelement "element"
181 %token XKWelementFormQualified "elementFormQualified"
182 %token XKWembedValues "embedValues"
183 %token XKWform "form"
184 %token XKWlist "list"
185 %token XKWname "name"
186 %token XKWnamespace "namespace"
187 %token XKWtext "text"
188 %token XKWuntagged "untagged"
189 %token XKWuseNil "useNil"
190 %token XKWuseNumber "useNumber"
191 %token XKWuseOrder "useOrder"
192 %token XKWuseUnion "useUnion"
193 %token XKWuseType "useType"
194 %token XKWwhiteSpace "whiteSpace"
198 %token XSDstring "string"
199 %token XSDnormalizedString "normalizedString"
200 %token XSDtoken "token"
201 %token XSDName "Name"
202 %token XSDNMTOKEN "NMTOKEN"
203 %token XSDNCName "NCName"
205 %token XSDIDREF "IDREF"
206 %token XSDENTITY "ENTITY"
207 %token XSDhexBinary "hexBinary"
208 %token XSDbase64Binary "base64Binary"
209 %token XSDanyURI "anyURI"
210 %token XSDlanguage "language"
211 %token XSDinteger "integer"
212 %token XSDpositiveInteger "positiveInteger"
213 %token XSDnonPositiveInteger "nonPositiveInteger"
214 %token XSDnegativeInteger "negativeInteger"
215 %token XSDnonNegativeInteger "nonNegativeInteger"
216 /* XKWlong instead of %token XSDlong */
217 %token XSDunsignedLong "unsignedLong"
219 %token XSDunsignedInt "unsignedInt"
220 /* XKWshort instead of %token XSDshort */
221 %token XSDunsignedShort "unsignedShort"
222 %token XSDbyte "byte"
223 %token XSDunsignedByte "unsignedByte"
224 %token XSDdecimal "decimal"
225 %token XSDfloat "float"
226 %token XSDdouble "double"
227 %token XSDduration "duration"
228 %token XSDdateTime "dateTime"
229 %token XSDtime "time"
230 %token XSDdate "date"
231 %token XSDgYearMonth "gYearMonth"
232 %token XSDgYear "gYear"
233 %token XSDgMonthDay "gMonthDay"
234 %token XSDgDay "gDay"
235 %token XSDgMonth "gMonth"
236 %token XSDNMTOKENS "NMTOKENS"
237 %token XSDIDREFS "IDREFS"
238 %token XSDENTITIES "ENTITIES"
239 %token XSDQName "QName"
240 %token XSDboolean "boolean"
241 %token XSDanySimpleType "anySimpleType"
242 %token XSDanyType "anyType"
247 %token XKWlength "length"
248 %token XKWaccept "accept"
249 %token XKWlong "long"
250 %token XKWshort "short"
251 %token XKWindefinite "indefinite"
252 %token XKWdefinite "definite"
256 %token XKWjson "JSON"
257 %token XKWomit "omit"
258 %token XKWnull "null"
259 %token XAliasToken "JSON alias"
260 %token XKWvalue "value"
261 %token XKWdefault "default"
262 %token XKWextend "extend"
263 %token XKWmetainfo "metainfo"
265 %token XKWunbound "unbound"
266 %token XJsonValueStart "("
267 %token XJsonValueEnd ")"
268 %token XJsonValueSegment "JSON value"
272 XYesOrNo XMsbOrLsb XFieldOrderDef XPaddingDef XExtensionBitDef XUnitDef
273 XBitsOctets XAlignDef XLeftOrRight XCompDef XCompValues XByteOrderDef
274 XFirstOrLast XBitOrderDef XBitOrderInFieldDef XBitOrderInOctetDef
275 XHexOrderDef XLowOrHigh XYesOrNoOrReverse XFieldLengthDef
276 XPtrOffsetDef XPrePaddingDef XRepeatableDef form
279 XLengthIndexDef XStructFieldRefOrEmpty XStructFieldRef
282 XEncodeToken XmatchDef XAliasToken XJsonValueSegment XJsonValueCore XJsonValue
291 XPointerToDef XRecordFieldRef XIdentifierOrReserved
299 /* note: multiple "XSingleEncodingDefs have to be merged into one 'fullspec' */
301 XEncodingDefList XSingleEncodingDef
309 XAssocElement XKeyIdOrIdList XKeyIdList XMultiKeyId
312 XToplevelDef XTopDefList XTopDef
316 anyAttributes anyElement optNamespaceRestriction urilist
319 %type <str> defaultForEmpty name newnameOrKeyword keyword optPrefix quotedURIorAbsent
321 %type <nsspec> namespace namespacespecification controlNamespace text
323 %type <intval> whiteSpace
326 %destructor { Free($$); }
340 %destructor { delete $$; }
342 XIdentifierOrReserved
346 %destructor { free_rawAST_field_list($$); }
349 XStructFieldRefOrEmpty
351 %destructor { free_rawAST_tag_list(&$$); }
354 %destructor { free_rawAST_tag_field_value(&$$); }
357 %destructor { free_rawAST_single_tag(&$$); }
369 %destructor { Free($$.token); }
373 FreeNamespaceRestriction($$);
375 anyAttributes anyElement optNamespaceRestriction urilist
382 namespacespecification
392 XAttribSpec : /* Empty */
402 XKWlength XKWaccept XKWshort { berstruct->decode_param = BerAST::LENGTH_ACCEPT_SHORT; ber_f=true; }
403 | XKWlength XKWaccept XKWlong { berstruct->decode_param = BerAST::LENGTH_ACCEPT_LONG; ber_f=true; }
404 | XKWlength XKWaccept XKWindefinite { berstruct->decode_param = BerAST::LENGTH_ACCEPT_INDEFINITE; ber_f=true; }
405 | XKWlength XKWaccept XKWdefinite { berstruct->decode_param = BerAST::LENGTH_ACCEPT_DEFINITE; ber_f=true; }
408 XEncodingDefList : XSingleEncodingDef
410 | XEncodingDefList ',' XSingleEncodingDef
413 XSingleEncodingDef : XPaddingDef
414 { rawstruct->padding=$1;raw_f=true;}
416 { rawstruct->prepadding=$1;raw_f=true;}
417 | XPaddingPattern { raw_f=true;}
418 | XPaddAll { rawstruct->paddall=XDEFYES;raw_f=true;}
420 { rawstruct->fieldorder=$1;raw_f=true;}
422 { rawstruct->extension_bit=$1;raw_f=true;}
423 | XExtensionBitGroupDef
428 { delete rawstruct->pointerto;
429 rawstruct->pointerto = $1;
433 { rawstruct->unit=$1; raw_f=true;}
435 { free_rawAST_field_list(rawstruct->lengthindex);
436 rawstruct->lengthindex = $1;raw_f=true; }
444 { rawstruct->fieldlength = $1*length_multiplier; raw_f=true;}
448 { rawstruct->align = $1; raw_f=true;}
450 { rawstruct->comp = $1;raw_f=true; }
452 { rawstruct->byteorder = $1; raw_f=true;}
453 | XBitOrderInFieldDef
454 { rawstruct->bitorderinfield = $1; raw_f=true;}
455 | XBitOrderInOctetDef
456 { rawstruct->bitorderinoctet = $1; raw_f=true;}
458 { rawstruct->hexorder = $1;raw_f=true; }
460 { rawstruct->repeatable = $1;raw_f=true; }
462 { rawstruct->topleveleind=1; raw_f=true;}
464 { rawstruct->intx = true; raw_f = true; }
465 /* TEXT encoder keywords */
478 XRepeatableDef : XRepeatableKeyword '(' XYesOrNo ')' { $$ = $3; }
481 XPaddingDef : XPaddingKeyword '(' XYesOrNo ')' { $$ = $3==XDEFYES?8:0; }
482 | XPaddingKeyword '(' XBitsOctets ')' { $$ = $3;};
483 XPrePaddingDef : XPrePaddingKeyword '(' XYesOrNo ')' { $$ = $3==XDEFYES?8:0; }
484 | XPrePaddingKeyword '(' XBitsOctets ')' { $$ = $3;};
485 XYesOrNo : XYes | XNo;
488 XPaddingPatternKeyword '(' XBstring ')'
490 Free(rawstruct->padding_pattern);
491 size_t len = strlen($3);
493 rawstruct->padding_pattern = mcopystr($3);
494 rawstruct->padding_pattern_length = len;
495 while (rawstruct->padding_pattern_length % 8 != 0) {
496 rawstruct->padding_pattern = mputstr(rawstruct->padding_pattern, $3);
497 rawstruct->padding_pattern_length += len;
499 } else rawstruct->padding_pattern = NULL;
504 XPaddAll: XPaddAllKeyword
506 XFieldOrderDef : XFieldOrderKeyword '(' XMsbOrLsb ')'
508 XMsbOrLsb : XMsb | XLsb;
511 XExtensionBitDef : XExtensionBitKeyword '(' XYesOrNoOrReverse ')'
513 XYesOrNoOrReverse : XYes | XNo | XReverse;
515 XExtensionBitGroupDef: XExtensionBitGroupKeyword '(' XYesOrNoOrReverse ','
516 XIdentifier ',' XIdentifier ')'
517 { if(rawstruct->ext_bit_goup_num==0){
518 rawstruct->ext_bit_groups=
519 (rawAST_ext_bit_group*)Malloc(sizeof(rawAST_ext_bit_group));
520 rawstruct->ext_bit_goup_num=1;
522 rawstruct->ext_bit_goup_num++;
523 rawstruct->ext_bit_groups=(rawAST_ext_bit_group*)
524 Realloc(rawstruct->ext_bit_groups,
525 rawstruct->ext_bit_goup_num*sizeof(rawAST_ext_bit_group));
527 rawstruct->ext_bit_groups[rawstruct->ext_bit_goup_num-1].ext_bit=$3;
528 rawstruct->ext_bit_groups[rawstruct->ext_bit_goup_num-1].from=$5;
529 rawstruct->ext_bit_groups[rawstruct->ext_bit_goup_num-1].to=$7;
533 XLengthToDef : XLengthToKeyword '(' XRecordFieldRefList ')'
537 XPointerToDef : XPointerToKeyword '(' XRecordFieldRef ')'
541 XUnitDef : XUnitKeyword '(' XBitsOctets ')' { $$ = $3; }
542 | XPtrUnitKeyword '(' XBitsOctets ')' { $$ = $3; };
543 XBitsOctets : XBits {$$=$1;}
548 XLengthIndexDef : XLengthIndexKeyword '(' XStructFieldRefOrEmpty ')'
553 XTagDef : XTagKeyword '(' XAssocList XoptSemiColon ')'
554 { free_rawAST_tag_list(&(rawstruct->taglist));
555 link_rawAST_tag_list(&(rawstruct->taglist),&$3);};
556 XCrossTagDef : XCrossTagKeyword '(' XAssocList XoptSemiColon ')'
557 { free_rawAST_tag_list(&(rawstruct->crosstaglist));
558 link_rawAST_tag_list(&(rawstruct->crosstaglist),&$3);};
564 $$.tag = (rawAST_single_tag*)Malloc(sizeof(*$$.tag));
565 link_rawAST_single_tag($$.tag, &$1);
567 | XAssocList XSemiColon XAssocElement
569 int dupl_id_index = -1;
570 if ($3.nElements > 0) {
571 /* the otherwise element is never merged */
572 for (int i = 0; i < $1.nElements; i++)
573 if (*$1.tag[i].fieldName == *$3.fieldName) {
578 if (dupl_id_index >= 0) {
579 /* this identifier is already specified in XAssocList
580 merge the new parameters to the existing entry */
582 rawAST_single_tag *tag = $$.tag + dupl_id_index;
583 tag->keyList = (rawAST_tag_field_value*)
584 Realloc(tag->keyList, (tag->nElements + $3.nElements)
585 * sizeof(*tag->keyList));
586 memcpy(tag->keyList + tag->nElements, $3.keyList,
587 $3.nElements * sizeof(*$3.keyList));
588 tag->nElements += $3.nElements;
592 $$.nElements = $1.nElements + 1;
593 $$.tag = (rawAST_single_tag*)
594 Realloc($1.tag, $$.nElements * sizeof(*$$.tag));
595 $$.tag[$1.nElements] = $3;
610 XIdentifier ',' XKeyIdOrIdList
613 $$.nElements = $3.nElements;
614 $$.keyList = $3.keyList;
616 | XIdentifier ',' XOtherwise
629 $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList));
632 | XKeyIdList { $$ = $1; }
636 '{' XMultiKeyId '}' { $$ = $2; }
644 $$.keyList = (rawAST_tag_field_value*)Malloc(sizeof(*$$.keyList));
647 | XMultiKeyId ',' XKeyId
650 $$.nElements = $1.nElements + 1;
651 $$.keyList = (rawAST_tag_field_value*)
652 Realloc($1.keyList, $$.nElements * sizeof(*$$.keyList));
653 $$.keyList[$1.nElements] = $3;
658 XStructFieldRef '=' XRvalue
662 $$.v_value = $3.v_value;
667 XPresenceDef : XPresenceKeyword '(' XKeyIdList XoptSemiColon ')'
668 { free_rawAST_single_tag(&(rawstruct->presence));
669 link_rawAST_single_tag(&(rawstruct->presence), &$3);}
670 | XPresenceKeyword '(' XMultiKeyId XoptSemiColon ')'
671 { free_rawAST_single_tag(&(rawstruct->presence));
672 link_rawAST_single_tag(&(rawstruct->presence), &$3);};
676 XFieldLengthDef : XFieldLengthKeyword '(' XNumber ')'
680 XPtrOffsetDef : XPtrOffsetKeyword '(' XNumber ')'
681 { rawstruct->ptroffset = $3; }
682 |XPtrOffsetKeyword '(' XIdentifier ')'
684 delete rawstruct->ptrbase;
685 rawstruct->ptrbase = $3;
688 XAlignDef : XAlignKeyword '(' XLeftOrRight ')'
690 XLeftOrRight : XLeft | XRight;
693 XCompDef : XCompKeyword '(' XCompValues ')'
695 XCompValues : XUnsigned | XCompl | XSignbit;
698 XByteOrderDef : XByteOrderKeyword '(' XFirstOrLast ')'
700 XFirstOrLast : XFirst | XLast;
703 XBitOrderInFieldDef : XBitOrderInFieldKeyword '(' XMsbOrLsb ')'
705 XBitOrderInOctetDef : XBitOrderInOctetKeyword '(' XMsbOrLsb ')'
707 | XBitOrderKeyword '(' XMsbOrLsb ')' { $$ = $3; };
708 XToplevelDef : XToplevelKeyword '(' XTopDefList ')'
710 XTopDefList : XTopDef
712 | XTopDefList ',' XTopDef
714 XTopDef : XBitOrderDef
715 { rawstruct->toplevel.bitorder = $1;};
716 XBitOrderDef : XBitOrderKeyword '(' XMsbOrLsb ')'
720 XHexOrderDef : XHexOrderKeyword '(' XLowOrHigh ')'
722 XLowOrHigh : XLow | XHigh;
726 XRecordFieldRefList : XRecordFieldRef
727 { rawstruct->lengthto_num = 1;
728 rawstruct->lengthto =
729 (Common::Identifier**)Malloc(sizeof(*(rawstruct->lengthto)));
730 rawstruct->lengthto[0] = $1;
732 | XRecordFieldRefList ',' XRecordFieldRef
733 { rawstruct->lengthto_num++;
734 rawstruct->lengthto =
735 (Common::Identifier**)Realloc(rawstruct->lengthto,
736 rawstruct->lengthto_num*sizeof(*(rawstruct->lengthto)));
737 rawstruct->lengthto[rawstruct->lengthto_num - 1] = $3;
741 XRecordFieldRef : XIdentifier
744 XStructFieldRefOrEmpty : /* Empty */
749 XStructFieldRef : XIdentifier
750 { $$ = (rawAST_field_list*)Malloc(sizeof(*$$));
752 $$->names = (Common::Identifier**)Malloc(sizeof(*($$->names)));
755 | XStructFieldRef '.' XIdentifier
758 $$->names = (Common::Identifier**)
759 Realloc($$->names, $$->nElements*sizeof(*($$->names)));
760 $$->names[$$->nElements - 1] = $3;
764 XRvalue: XIdentifier{
765 $$.value = mcopystr($1->get_name().c_str());
766 $$.v_value = new Common::Value(Common::Value::V_UNDEF_LOWERID, $1);
767 $$.v_value->set_location(infile, @$);
770 string *str= new string($1);
771 $$.value=mprintf(" %s", mymod->add_bitstring_literal(*str).c_str());
772 $$.v_value=new Common::Value(Common::Value::V_BSTR,str);
773 $$.v_value->set_location(infile, @$);
777 string *str= new string($1);
778 $$.value=mprintf(" %s", mymod->add_hexstring_literal(*str).c_str());
779 $$.v_value=new Common::Value(Common::Value::V_HSTR,str);
780 $$.v_value->set_location(infile, @$);
785 string *str= new string($1);
786 $$.value=mprintf(" %s", mymod->add_octetstring_literal(*str).c_str());
787 $$.v_value=new Common::Value(Common::Value::V_OSTR,str);
788 $$.v_value->set_location(infile, @$);
792 Common::Location loc(infile, @$);
793 string *str = parse_charstring_value($1, loc);
795 $$.value=mprintf(" %s", mymod->add_charstring_literal(*str).c_str());
796 $$.v_value=new Common::Value(Common::Value::V_CSTR,str);
797 $$.v_value->set_location(loc);
800 $$.value=mcopystr(Common::Real2code($1).c_str());
801 $$.v_value=new Common::Value(Common::Value::V_REAL, $1);
802 $$.v_value->set_location(infile, @$);
805 $$.value = mcopystr(Common::Int2string($1).c_str());
806 $$.v_value=new Common::Value(Common::Value::V_INT, $1);
807 $$.v_value->set_location(infile, @$);
811 $$.value = mcopystr($1 ? "TRUE" : "FALSE");
812 $$.v_value=new Common::Value(Common::Value::V_BOOL, $1);
813 $$.v_value->set_location(infile, @$);
817 $$.v_value = new Common::Value(Common::Value::V_VERDICT, $1);
818 $$.v_value->set_location(infile, @$);
819 $$.value = mcopystr($$.v_value->get_single_expr().c_str());
823 $$.value = mcopystr("NULL_COMPREF");
824 $$.v_value = new Common::Value(Common::Value::V_TTCN3_NULL);
825 $$.v_value->set_location(infile, @$);
829 $$.value = mcopystr("ASN_NULL_VALUE");
830 $$.v_value = new Common::Value(Common::Value::V_NULL);
831 $$.v_value->set_location(infile, @$);
835 $$.value = mcopystr("OMIT_VALUE");
836 $$.v_value = new Common::Value(Common::Value::V_OMIT);
837 $$.v_value->set_location(infile, @$);
843 XBeginKeyword '(' XEncodeToken ')' {
844 if(textstruct->begin_val==NULL){
845 textstruct->begin_val=(textAST_matching_values*)
846 Malloc(sizeof(textAST_matching_values));
847 init_textAST_matching_values(textstruct->begin_val);
849 Free(textstruct->begin_val->encode_token);
850 textstruct->begin_val->encode_token=$3;
852 | XBeginKeyword '(' XEncodeToken ',' XmatchDef ')' {
853 if(textstruct->begin_val==NULL){
854 textstruct->begin_val=(textAST_matching_values*)
855 Malloc(sizeof(textAST_matching_values));
856 init_textAST_matching_values(textstruct->begin_val);
858 Free(textstruct->begin_val->encode_token);
859 textstruct->begin_val->encode_token=$3;
861 Free(textstruct->begin_val->decode_token);
862 textstruct->begin_val->decode_token=$5;
865 | XBeginKeyword '(' XEncodeToken ',' XmatchDef ',' XmodifierDef ')'{
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 Free(textstruct->begin_val->decode_token);
875 textstruct->begin_val->decode_token=$5;
877 textstruct->begin_val->case_sensitive=$7;
882 XEndKeyword '(' XEncodeToken ')' {
883 if(textstruct->end_val==NULL){
884 textstruct->end_val=(textAST_matching_values*)
885 Malloc(sizeof(textAST_matching_values));
886 init_textAST_matching_values(textstruct->end_val);
888 Free(textstruct->end_val->encode_token);
889 textstruct->end_val->encode_token=$3;
891 | XEndKeyword '(' XEncodeToken ',' XmatchDef ')'{
892 if(textstruct->end_val==NULL){
893 textstruct->end_val=(textAST_matching_values*)
894 Malloc(sizeof(textAST_matching_values));
895 init_textAST_matching_values(textstruct->end_val);
897 Free(textstruct->end_val->encode_token);
898 textstruct->end_val->encode_token=$3;
900 Free(textstruct->end_val->decode_token);
901 textstruct->end_val->decode_token=$5;
904 | XEndKeyword '(' XEncodeToken ',' XmatchDef ',' XmodifierDef ')'{
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 Free(textstruct->end_val->decode_token);
914 textstruct->end_val->decode_token=$5;
916 textstruct->end_val->case_sensitive=$7;
921 XSeparatorKeyword '(' XEncodeToken ')'{
922 if(textstruct->separator_val==NULL){
923 textstruct->separator_val=(textAST_matching_values*)
924 Malloc(sizeof(textAST_matching_values));
925 init_textAST_matching_values(textstruct->separator_val);
927 Free(textstruct->separator_val->encode_token);
928 textstruct->separator_val->encode_token=$3;
930 | XSeparatorKeyword '(' XEncodeToken ',' XmatchDef ')'{
931 if(textstruct->separator_val==NULL){
932 textstruct->separator_val=(textAST_matching_values*)
933 Malloc(sizeof(textAST_matching_values));
934 init_textAST_matching_values(textstruct->separator_val);
936 Free(textstruct->separator_val->encode_token);
937 textstruct->separator_val->encode_token=$3;
939 Free(textstruct->separator_val->decode_token);
940 textstruct->separator_val->decode_token=$5;
943 | XSeparatorKeyword '(' XEncodeToken ',' XmatchDef ',' XmodifierDef ')'{
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 Free(textstruct->separator_val->decode_token);
953 textstruct->separator_val->decode_token=$5;
955 textstruct->separator_val->case_sensitive=$7;
960 XCodingKeyword '(' XCodingRule ')'
962 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ')'
964 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ')' {
965 Free(textstruct->decode_token);
966 textstruct->decode_token=$7;
968 | XCodingKeyword '(' XCodingRule ',' XDecodingRule ',' XmatchDef ','
971 Free(textstruct->decode_token);
972 textstruct->decode_token=$7;
974 textstruct->case_sensitive=$9;
987 | XDecodingtokendefList {}
992 | XattrList ';' Xattr {}
996 XLengthToken '=' XNumber {
997 textstruct->decoding_params.min_length=$3;
999 | XLengthToken '=' XNumber '-' XNumber {
1000 textstruct->decoding_params.min_length=$3;
1001 textstruct->decoding_params.max_length=$5;
1003 | XConvertToken '=' XLowerToken {
1004 textstruct->decoding_params.convert=-1;
1006 | XConvertToken '=' XUpperToken {
1007 textstruct->decoding_params.convert=1;
1009 | XJustToken '=' XLeftToken {
1010 textstruct->decoding_params.just=-1;
1012 | XJustToken '=' XRightToken {
1013 textstruct->decoding_params.just=1;
1015 | XJustToken '=' XCenterToken {
1016 textstruct->decoding_params.just=0;
1018 | XLeadingToken '=' XTrueToken {
1019 textstruct->decoding_params.leading_zero=true;
1021 | XLeadingToken '=' XFalseToken {
1022 textstruct->decoding_params.leading_zero=false;
1024 | XRepeatToken '=' XTrueToken {
1025 textstruct->decoding_params.repeatable=true;
1027 | XRepeatToken '=' XFalseToken {
1028 textstruct->decoding_params.repeatable=false;
1033 | Xattrlistenc ';' Xattrenc {}
1037 XLengthToken '=' XNumber {
1038 textstruct->coding_params.min_length=$3;
1039 textstruct->decoding_params.min_length=$3;
1041 | XLengthToken '=' XNumber '-' XNumber {
1042 textstruct->coding_params.min_length=$3;
1043 textstruct->coding_params.max_length=$5;
1044 textstruct->decoding_params.min_length=$3;
1045 textstruct->decoding_params.max_length=$5;
1047 | XConvertToken '=' XLowerToken {
1048 textstruct->coding_params.convert=-1;
1049 textstruct->decoding_params.convert=-1;
1051 | XConvertToken '=' XUpperToken {
1052 textstruct->coding_params.convert=1;
1053 textstruct->decoding_params.convert=1;
1055 | XJustToken '=' XLeftToken {
1056 textstruct->coding_params.just=-1;
1057 textstruct->decoding_params.just=-1;
1059 | XJustToken '=' XRightToken {
1060 textstruct->coding_params.just=1;
1061 textstruct->decoding_params.just=1;
1063 | XJustToken '=' XCenterToken {
1064 textstruct->coding_params.just=0;
1065 textstruct->decoding_params.just=0;
1067 | XLeadingToken '=' XTrueToken {
1068 textstruct->coding_params.leading_zero=true;
1069 textstruct->decoding_params.leading_zero=true;
1071 | XLeadingToken '=' XFalseToken {
1072 textstruct->coding_params.leading_zero=false;
1073 textstruct->decoding_params.leading_zero=false;
1075 | XRepeatToken '=' XTrueToken {
1076 textstruct->coding_params.repeatable=true;
1077 textstruct->decoding_params.repeatable=true;
1079 | XRepeatToken '=' XFalseToken {
1080 textstruct->coding_params.repeatable=false;
1081 textstruct->decoding_params.repeatable=false;
1087 | XtokendefList ';' Xtokendef {}
1091 XIdentifierOrReserved ':' XEncodeToken
1093 int idx = textstruct->get_field_param_index($1);
1094 if (textstruct->field_params[idx]->value.encode_token) {
1095 Free(textstruct->field_params[idx]->value.encode_token);
1096 Common::Location loc(infile, @3);
1097 loc.error("Duplicate encode token for value `%s'",
1098 $1->get_dispname().c_str());
1100 textstruct->field_params[idx]->value.encode_token = $3;
1103 | XTrueToken ':' XEncodeToken
1105 if (textstruct->true_params == NULL) {
1106 textstruct->true_params = (textAST_matching_values*)
1107 Malloc(sizeof(textAST_matching_values));
1108 textstruct->true_params->encode_token = $3;
1109 textstruct->true_params->decode_token = NULL;
1110 textstruct->true_params->case_sensitive = true;
1111 textstruct->true_params->generated_decode_token = false;
1113 if (textstruct->true_params->encode_token) {
1114 Free(textstruct->true_params->encode_token);
1115 Common::Location loc(infile, @3);
1116 loc.error("Duplicate encode token for true value");
1118 textstruct->true_params->encode_token = $3;
1121 | XFalseToken ':' XEncodeToken
1123 if (textstruct->false_params == NULL) {
1124 textstruct->false_params = (textAST_matching_values*)
1125 Malloc(sizeof(textAST_matching_values));
1126 textstruct->false_params->encode_token = $3;
1127 textstruct->false_params->decode_token = NULL;
1128 textstruct->false_params->case_sensitive = true;
1129 textstruct->false_params->generated_decode_token = false;
1131 if (textstruct->false_params->encode_token) {
1132 Free(textstruct->false_params->encode_token);
1133 Common::Location loc(infile, @3);
1134 loc.error("Duplicate encode token for false value");
1136 textstruct->false_params->encode_token = $3;
1141 XIdentifierOrReserved:
1142 XIdentifier { $$ = $1; }
1144 { $$ = new Common::Identifier(Common::Identifier::ID_TTCN, string($1)); }
1148 XLengthToken { $$ = "length"; }
1149 | XRepeatToken { $$ = "repeatable"; }
1150 | XConvertToken { $$ = "convert"; }
1151 | XLowerToken { $$ = "lower_case"; }
1152 | XUpperToken { $$ = "upper_case"; }
1153 | XJustToken { $$ = "just"; }
1154 | XLeftToken { $$ = "left"; }
1155 | XRightToken { $$ = "right"; }
1156 | XCenterToken { $$ = "center"; }
1157 | XLeadingToken { $$ = "leading0"; }
1158 | XSensitivToken { $$ = "case_sensitive"; }
1159 | XInSensitivToken { $$ = "case_insensitive"; }
1162 XDecodingtokendefList:
1163 Xdecodingtokendef {}
1164 | XDecodingtokendefList ';' Xdecodingtokendef {}
1168 XIdentifierOrReserved ':' XDecodeToken
1170 int idx = textstruct->get_field_param_index($1);
1171 if (textstruct->field_params[idx]->value.decode_token) {
1172 Free(textstruct->field_params[idx]->value.decode_token);
1173 Common::Location loc(infile, @3);
1174 loc.error("Duplicate decode token for value `%s'",
1175 $1->get_dispname().c_str());
1177 textstruct->field_params[idx]->value.decode_token = $3.token;
1178 textstruct->field_params[idx]->value.case_sensitive = $3.case_sensitive;
1181 | XTrueToken ':' XDecodeToken
1183 if (textstruct->true_params == NULL) {
1184 textstruct->true_params = (textAST_matching_values*)
1185 Malloc(sizeof(textAST_matching_values));
1186 textstruct->true_params->encode_token = NULL;
1187 textstruct->true_params->decode_token = $3.token;
1188 textstruct->true_params->case_sensitive = $3.case_sensitive;
1189 textstruct->true_params->generated_decode_token = false;
1191 if (textstruct->true_params->decode_token) {
1192 Free(textstruct->true_params->decode_token);
1193 Common::Location loc(infile, @3);
1194 loc.error("Duplicate decode token for true value");
1196 textstruct->true_params->decode_token = $3.token;
1197 textstruct->true_params->case_sensitive = $3.case_sensitive;
1200 | XFalseToken ':' XDecodeToken
1202 if (textstruct->false_params == NULL) {
1203 textstruct->false_params = (textAST_matching_values*)
1204 Malloc(sizeof(textAST_matching_values));
1205 textstruct->false_params->encode_token = NULL;
1206 textstruct->false_params->decode_token= $3.token;
1207 textstruct->false_params->case_sensitive = $3.case_sensitive;
1208 textstruct->false_params->generated_decode_token = false;
1210 if (textstruct->false_params->decode_token) {
1211 Free(textstruct->false_params->decode_token);
1212 Common::Location loc(infile, @3);
1213 loc.error("Duplicate decode token for false value");
1215 textstruct->false_params->decode_token = $3.token;
1216 textstruct->false_params->case_sensitive = $3.case_sensitive;
1224 Common::Location loc(infile, @$);
1225 string *str = parse_charstring_value($1, loc);
1227 $$ = mcopystr(str->c_str());
1236 $$.case_sensitive = true;
1241 $$.case_sensitive = true;
1243 | '{' XmatchDef ',' XmodifierDef '}'
1246 $$.case_sensitive = $4;
1251 /* empty */ { $$ = NULL; }
1252 | Xtoken { $$ = $1; }
1256 /* empty */ { $$ = true; }
1257 | XSensitivToken { $$ = true; }
1258 | XInSensitivToken { $$ = false; }
1261 /********** XERSTUFF "raw" attributes */
1263 XERattributes: /* a non-empty list */
1264 XERattribute { xer_f = true; }
1268 anyAttributes { FreeNamespaceRestriction(xerstruct->anyAttributes_); xerstruct->anyAttributes_ = $1; }
1269 | anyElement { FreeNamespaceRestriction(xerstruct->anyElement_); xerstruct->anyElement_ = $1; }
1270 | XKWattribute { xerstruct->attribute_ = true; }
1271 | XKWattributeFormQualified { xerstruct->form_ |= XerAttributes::ATTRIBUTE_DEFAULT_QUALIFIED; }
1272 | controlNamespace /* directly on the module */
1274 mymod->set_controlns($1.uri, $1.prefix);
1276 | defaultForEmpty { xerstruct->defaultForEmpty_ = $1; }
1277 | XKWelement { xerstruct->element_ = true; }
1278 | XKWelementFormQualified { xerstruct->form_ |= XerAttributes::ELEMENT_DEFAULT_QUALIFIED; }
1279 | XKWembedValues { xerstruct->embedValues_ = true; }
1280 | form { xerstruct->form_ |= $1; }
1281 | XKWlist { xerstruct->list_ = true; }
1283 { /* overwrites any previous name */
1284 switch (xerstruct->name_.kw_) {
1285 case NamespaceSpecification::NO_MANGLING:
1286 case NamespaceSpecification::CAPITALIZED:
1287 case NamespaceSpecification::UNCAPITALIZED:
1288 case NamespaceSpecification::UPPERCASED:
1289 case NamespaceSpecification::LOWERCASED:
1290 break; // nothing to do
1291 default: // real string, must be freed
1292 Free(xerstruct->name_.nn_);
1294 xerstruct->name_.nn_ = $1;
1297 { /* overwrites any previous namespace */
1298 Free(xerstruct->namespace_.uri);
1299 Free(xerstruct->namespace_.prefix);
1300 xerstruct->namespace_ = $1;
1304 xerstruct->text_ = (NamespaceSpecification *)Realloc(xerstruct->text_,
1305 ++xerstruct->num_text_ * sizeof(NamespaceSpecification));
1306 xerstruct->text_[xerstruct->num_text_-1] = $1;
1308 | XKWuntagged { xerstruct->untagged_ = true; }
1309 | XKWuseNil { xerstruct->useNil_ = true; }
1310 | XKWuseNumber { xerstruct->useNumber_ = true; }
1311 | XKWuseOrder { xerstruct->useOrder_ = true; }
1312 | XKWuseUnion { xerstruct->useUnion_ = true; }
1313 | XKWuseType { xerstruct->useType_ = true; }
1316 xerstruct->whitespace_ = static_cast<XerAttributes::WhitespaceAction>($1);
1318 | XSD ':' xsddata {}
1322 XKWanyAttributes optNamespaceRestriction
1327 XKWanyElement optNamespaceRestriction
1331 optNamespaceRestriction:
1333 $$.nElements_ = 0; $$.uris_ = 0; $$.type_ = NamespaceRestriction::NOTHING;
1335 | XKWfrom urilist { $$ = $2; $$.type_ = NamespaceRestriction::FROM; }
1336 | XKWexcept urilist { $$ = $2; $$.type_ = NamespaceRestriction::EXCEPT; }
1339 urilist: /* a non-empty list */
1342 $$.uris_ = (char**)Malloc(sizeof($$.uris_[0]));
1345 | urilist ',' quotedURIorAbsent
1348 $$.uris_ = (char**)Realloc($$.uris_, ++$$.nElements_ * sizeof($$.uris_[0]));
1349 $$.uris_[$$.nElements_-1] = $3;
1354 Xstring /* as quotedURI */
1355 | XKWunqualified { $$ = NULL; }
1358 controlNamespace: /* nsspec */
1359 XKWcontrolNamespace Xstring /* <-- as the QuotedURI */ XKWprefix Xstring
1360 /* Prefix is required by TTCN-3; it is optional in the ASN.1 standard
1361 * but the OSS ASN.1 compiler seems to require it anyway */
1370 XKWform XKWas XKWunqualified { $$ = XerAttributes::UNQUALIFIED; }
1371 | XKWform XKWas XKWqualified { $$ = XerAttributes::QUALIFIED; }
1375 XKWname XKWas newnameOrKeyword { $$ = $3; }
1378 newnameOrKeyword: keyword
1379 | Xstring { $$ = $1; }
1383 XKWcapitalized { $$ = (char*)NamespaceSpecification::CAPITALIZED; }
1384 | XKWuncapitalized { $$ = (char*)NamespaceSpecification::UNCAPITALIZED; }
1385 | XKWlowercased { $$ = (char*)NamespaceSpecification::LOWERCASED; }
1386 | XKWuppercased { $$ = (char*)NamespaceSpecification::UPPERCASED; }
1390 XKWnamespace namespacespecification
1394 namespacespecification:
1396 Xstring /* as QuotedURI, required */
1400 $$.uri = $2; $$.prefix = $3;
1402 else { /* URI is empty */
1403 if (*$3) { /* prefix not empty, error */
1404 Common::Location loc(infile, @2);
1405 loc.error("Empty string is not a valid URI");
1408 /* Both are empty strings, use one of the non-string values
1409 * to signal "override and remove any namespace" */
1412 $$.keyword = NamespaceSpecification::UNCAPITALIZED;
1419 optPrefix: /* empty */ { $$ = memptystr(); }
1425 XKWtext Xstring XKWas newnameOrKeyword
1426 { $$.uri = $4; $$.prefix = $2; }
1427 | XKWtext XKWall XKWas newnameOrKeyword
1428 { $$.uri = $4; $$.prefix = (char*)NamespaceSpecification::ALL; }
1430 { $$.uri = 0; $$.prefix = 0; }
1431 /* "text as <something>" is not allowed */
1435 XKWdefaultForEmpty XKWas Xstring
1442 XKWwhiteSpace XKWpreserve { $$ = XerAttributes::PRESERVE; }
1443 | XKWwhiteSpace XKWreplace { $$ = XerAttributes::REPLACE; }
1444 | XKWwhiteSpace XKWcollapse { $$ = XerAttributes::COLLAPSE; }
1447 xsddata: /* XSD:something */
1449 xerstruct->base64_ = true;
1452 xerstruct->decimal_ = true;
1455 xerstruct->hex_ = true;
1458 xerstruct->useQName_ = true;
1460 /* everything below is recognized and ignored */
1464 | XSDnormalizedString {}
1474 /* TODO apply subtype to the types below */
1476 | XSDpositiveInteger {}
1477 | XSDnonPositiveInteger {}
1478 | XSDnegativeInteger {}
1479 | XSDnonNegativeInteger {}
1480 | XSDunsignedLong {}
1483 | XSDunsignedShort {}
1485 | XSDunsignedByte {}
1502 | XSDanySimpleType {}
1509 XOptSpaces XKWjson XOptSpaces ':' XOptSpaces XJsonAttribute XOptSpaces
1518 | XMetainfoForUnbound
1522 XKWomit XSpaces XKWas XSpaces XKWnull { jsonstruct->omit_as_null = true; }
1526 XKWname XSpaces XKWas XSpaces XAliasToken { jsonstruct->alias = mcopystr($5); }
1530 XKWas XSpaces XKWvalue { jsonstruct->as_value = true; }
1534 XKWdefault XOptSpaces XJsonValue { jsonstruct->default_value = mcopystr($3); }
1538 XKWextend XOptSpaces XJsonValue XOptSpaces ':' XOptSpaces XJsonValue
1539 { jsonstruct->schema_extensions.add(new JsonSchemaExtension($3, $7)); }
1543 XJsonValueStart XJsonValueCore XJsonValueEnd { $$ = mcopystr($2); }
1544 | XJsonValueStart XJsonValueEnd { $$ = mcopystr(""); }
1548 XJsonValueCore XJsonValueSegment { $$ = mcopystr($1); $$ = mputstr($$, $2); }
1549 | XJsonValueSegment { $$ = mcopystr($1); }
1552 XMetainfoForUnbound:
1553 XKWmetainfo XOptSpaces XKWfor XOptSpaces XKWunbound { jsonstruct->metainfo_unbound = true; }
1573 /* parse_rawAST(), which calls our rawAST_parse, is over in rawASST.l */
1576 static void yyprint(FILE *file, int type, const YYSTYPE& value)
1580 fprintf(file, "``%s''", value.identifier->get_name().c_str());
1583 fprintf(file, "``%s''", value.str);
1586 fprintf(file, "# %d", type);
1595 indent-tabs-mode: nil