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
19 #include "ttcn3_preparser.h"
20 #include "../../common/memory.h"
23 /** This inefficient macro is needed to cope with binary files.
24 * The scanner must stop immediately when it encounters a zero byte,
25 * which might cause confusion in the internal algorithm of flex. */
26 #define YY_INPUT(buf,result,max_size) \
29 if (c == EOF || c == '\0') result = YY_NULL; \
36 #define YY_DECL static int yylex(char **module_name)
40 TTCN3MODULENAME [A-Za-z][A-Za-z0-9_]*
43 LINECOMMENT "//"[^\r\n]*{NEWLINE}
45 %x SC_blockcomment SC_ppdirective
46 %s SC_ttcn3module SC_ttcn3modulebody
49 int blockcomment_caller = INITIAL, ppdirective_caller = INITIAL;
52 <INITIAL,SC_ppdirective,SC_ttcn3module,SC_ttcn3modulebody>"/*" {
53 blockcomment_caller = YY_START;
54 BEGIN(SC_blockcomment);
58 ppdirective_caller = YY_START;
59 BEGIN(SC_ppdirective);
62 {WHITESPACE}|{NEWLINE}|{LINECOMMENT}
66 "*/" BEGIN(blockcomment_caller);
72 {NEWLINE} BEGIN(ppdirective_caller);
76 <INITIAL>"module" BEGIN(SC_ttcn3module);
78 <SC_ttcn3module>{TTCN3MODULENAME} {
79 if (module_name != NULL) *module_name = mcopystr(yytext);
80 BEGIN(SC_ttcn3modulebody);
83 <SC_ttcn3modulebody>"{"|"."|"language" return 1;
90 int is_ttcn3_module(const char *file_name, FILE *fp, char **module_name)
93 if (module_name != NULL) *module_name = NULL;
94 if (fseek(fp, 0L, SEEK_SET)) {
95 ERROR("Seeking to the beginning of file `%s' failed: %s", file_name,
101 ret_val = yylex(module_name);
102 yy_flush_buffer(YY_CURRENT_BUFFER);
103 if (ret_val == 0 && module_name != NULL && *module_name != NULL) {