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 ******************************************************************************/
9 %option never-interactive
11 %option prefix="comptype_attrib_"
15 #include "../Identifier.hh"
16 #include "../Setting.hh"
17 #include "../CompilerError.hh"
18 #include "Attributes.hh"
19 #include "AST_ttcn3.hh"
20 #include "../CompType.hh"
22 extern void parseExtendsCompTypeRefList(Ttcn::AttributeSpec *attrib,
23 Common::CompTypeRefList*& attr_comp_refs);
25 /** states of the extension attribute parser */
26 enum extension_attr_parser_state_t {
27 INITIAL_STATE, /**< state at the beginning, valid on return */
28 EXTENDS_STATE, /**< INITIAL_STATE + "extends" or REFID[2]_STATE + "," ,
30 REFID_STATE, /**< EXTENDS_STATE + IDENTIFIER , valid on return */
31 IDDOT_STATE, /**< REFID_STATE + "." , invalid on return */
32 REFID2_STATE /**< IDDOT_STATE + IDENTIFIER , valid on return */
35 #define YY_DECL static int yylex(Common::CompTypeRefList*& attr_comp_refs, \
36 int current_line, int current_column, const char *current_file)
38 #define FATAL_ERROR_INVALID_STATE \
39 FATAL_ERROR("comptype_attr.l: invalid parser state");
41 #define ERROR_UNEXPECTED_EOF \
43 Common::Location loc(current_file, current_line, current_column, \
44 current_line, current_column+1); \
45 loc.error("Unexpected end of extension attribute"); \
48 #define ERROR_UNEXPECTED_TOKEN \
50 Common::Location loc(current_file, current_line, current_column, \
51 current_line, current_column+yyleng); \
52 loc.error("Syntax error in extension attribute, unexpected token `%s'", \
58 if (!id) FATAL_ERROR("ADD_REFID"); \
59 Ttcn::Reference *ref = new Ttcn::Reference(id); \
60 ref->set_location(current_file, id_loc); \
61 if (!attr_comp_refs) attr_comp_refs = new Common::CompTypeRefList(); \
62 attr_comp_refs->add_ref(ref); \
66 /** return from yylex with cleanup */
67 #define YYLEX_RETURN \
77 IDENTIFIER [A-Za-z][A-Za-z0-9_]*
78 LINECOMMENT "//"[^\r\n]*{NEWLINE}
83 Common::Identifier *id=0;
87 extension_attr_parser_state_t parser_state = INITIAL_STATE;
91 start_line = current_line;
92 start_column = current_column;
93 current_column+=yyleng;
94 BEGIN(SC_blockcomment);
99 "*/" { current_column+=yyleng; BEGIN(INITIAL); }
100 {NEWLINE} { current_line++; current_column=0; }
103 Common::Location loc(current_file, start_line, start_column,
104 current_line, current_column);
105 loc.error("Unterminated block comment in extension attribute");
110 {LINECOMMENT} { current_line++; current_column=0; }
111 {WHITESPACE} current_column+=yyleng;
112 {NEWLINE} { current_line++; current_column=0; }
115 switch (parser_state) {
117 parser_state = EXTENDS_STATE;
123 ERROR_UNEXPECTED_TOKEN;
126 FATAL_ERROR_INVALID_STATE;
128 current_column+=yyleng;
132 switch (parser_state) {
136 id = new Common::Identifier(Common::Identifier::ID_TTCN, string(yytext));
137 id_loc.first_line = id_loc.last_line = current_line;
138 id_loc.first_column = current_column;
139 id_loc.last_column = current_column + yyleng;
140 parser_state = REFID_STATE;
143 Common::Identifier *id2 =
144 new Common::Identifier(Common::Identifier::ID_TTCN, string(yytext));
145 if (!id || !id2) FATAL_ERROR("ADD_REFID2");
146 Ttcn::Reference *ref = new Ttcn::Reference(id, id2);
147 ref->set_location(current_file, id_loc.first_line, id_loc.first_column,
148 current_line, current_column+yyleng);
149 if (!attr_comp_refs) attr_comp_refs = new Common::CompTypeRefList();
150 attr_comp_refs->add_ref(ref);
152 parser_state = REFID2_STATE;
157 ERROR_UNEXPECTED_TOKEN;
160 FATAL_ERROR_INVALID_STATE;
162 current_column+=yyleng;
166 switch (parser_state) {
171 parser_state = IDDOT_STATE;
176 ERROR_UNEXPECTED_TOKEN;
179 FATAL_ERROR_INVALID_STATE;
181 current_column+=yyleng;
185 switch (parser_state) {
192 parser_state = EXTENDS_STATE;
196 ERROR_UNEXPECTED_TOKEN;
199 FATAL_ERROR_INVALID_STATE;
201 current_column+=yyleng;
205 int c = (unsigned char)yytext[0];
206 Common::Location loc(current_file, current_line, current_column,
207 current_line, current_column+yyleng);
208 loc.error("Invalid character `%c' (0x%02X) in extension attribute",
209 isprint(c) ? c : '?', c);
210 current_column+=yyleng;
214 switch (parser_state) {
215 /* valid return states */
220 /* invalid return states */
223 ERROR_UNEXPECTED_EOF;
226 FATAL_ERROR_INVALID_STATE;
233 void parseExtendsCompTypeRefList(Ttcn::AttributeSpec const& attrib,
234 Common::CompTypeRefList*& attr_comp_refs)
236 const string& s = attrib.get_spec();
237 struct yy_buffer_state *flex_buffer = yy_scan_bytes(s.c_str(), s.size());
239 FATAL_ERROR("parseExtendsCompTypeRefList(): flex buffer creation failed");
240 yylex(attr_comp_refs, attrib.get_first_line(),
241 attrib.get_first_column() + 1, attrib.get_filename() );