1 /******************************************************************************
2 * Copyright (c) 2000-2016 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
14 * Szabo, Janos Zoltan – initial implementation
16 ******************************************************************************/
18 %option never-interactive
28 #include "ttcn3_preparser.h"
29 #include "../../common/memory.h"
32 /** This inefficient macro is needed to cope with binary files.
33 * The scanner must stop immediately when it encounters a zero byte,
34 * which might cause confusion in the internal algorithm of flex. */
35 #define YY_INPUT(buf,result,max_size) \
38 if (c == EOF || c == '\0') result = YY_NULL; \
45 #define YY_DECL static int yylex(char **module_name)
49 TTCN3MODULENAME [A-Za-z][A-Za-z0-9_]*
52 LINECOMMENT "//"[^\r\n]*{NEWLINE}
54 %x SC_blockcomment SC_ppdirective
55 %s SC_ttcn3module SC_ttcn3modulebody
58 int blockcomment_caller = INITIAL, ppdirective_caller = INITIAL;
61 <INITIAL,SC_ppdirective,SC_ttcn3module,SC_ttcn3modulebody>"/*" {
62 blockcomment_caller = YY_START;
63 BEGIN(SC_blockcomment);
67 ppdirective_caller = YY_START;
68 BEGIN(SC_ppdirective);
71 {WHITESPACE}|{NEWLINE}|{LINECOMMENT}
75 "*/" BEGIN(blockcomment_caller);
81 {NEWLINE} BEGIN(ppdirective_caller);
85 <INITIAL>"module" BEGIN(SC_ttcn3module);
87 <SC_ttcn3module>{TTCN3MODULENAME} {
88 if (module_name != NULL) *module_name = mcopystr(yytext);
89 BEGIN(SC_ttcn3modulebody);
92 <SC_ttcn3modulebody>"{"|"."|"language" return 1;
99 int is_ttcn3_module(const char *file_name, FILE *fp, char **module_name)
102 if (module_name != NULL) *module_name = NULL;
103 if (fseek(fp, 0L, SEEK_SET)) {
104 ERROR("Seeking to the beginning of file `%s' failed: %s", file_name,
110 ret_val = yylex(module_name);
111 yy_flush_buffer(YY_CURRENT_BUFFER);
112 if (ret_val == 0 && module_name != NULL && *module_name != NULL) {