added any2unistr predefined function (artf724008)
[deliverable/titan.core.git] / compiler2 / ttcn3 / ttcn3_preparser.l
CommitLineData
970ed795 1/******************************************************************************
d44e3c4f 2 * Copyright (c) 2000-2016 Ericsson Telecom AB
970ed795
EL
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
d44e3c4f 7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Delic, Adam
11 * Forstner, Matyas
12 * Kremer, Peter
13 * Raduly, Csaba
14 * Szabo, Janos Zoltan – initial implementation
15 *
970ed795
EL
16 ******************************************************************************/
17%option noyywrap
18%option never-interactive
19%option nounput
20
21%{
22
23#include <stdio.h>
24#include <string.h>
25#include <unistd.h>
26#include <errno.h>
27
28#include "ttcn3_preparser.h"
29#include "../../common/memory.h"
30#include "../error.h"
31
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) \
36{\
37 int c = getc(yyin); \
38 if (c == EOF || c == '\0') result = YY_NULL; \
39 else { \
40 buf[0] = c; \
41 result = 1; \
42 } \
43}
44
45#define YY_DECL static int yylex(char **module_name)
46
47%}
48
49TTCN3MODULENAME [A-Za-z][A-Za-z0-9_]*
50NEWLINE \r|\n|\r\n
51WHITESPACE [ \t\v\f]
52LINECOMMENT "//"[^\r\n]*{NEWLINE}
53
54%x SC_blockcomment SC_ppdirective
55%s SC_ttcn3module SC_ttcn3modulebody
56
57%%
58 int blockcomment_caller = INITIAL, ppdirective_caller = INITIAL;
59 BEGIN(INITIAL);
60
61<INITIAL,SC_ppdirective,SC_ttcn3module,SC_ttcn3modulebody>"/*" {
62 blockcomment_caller = YY_START;
63 BEGIN(SC_blockcomment);
64}
65
66^{WHITESPACE}*"#" {
67 ppdirective_caller = YY_START;
68 BEGIN(SC_ppdirective);
69}
70
71{WHITESPACE}|{NEWLINE}|{LINECOMMENT}
72
73<SC_blockcomment>
74{
75"*/" BEGIN(blockcomment_caller);
76.|\n
77}
78
79<SC_ppdirective>
80{
81{NEWLINE} BEGIN(ppdirective_caller);
82.|\\{NEWLINE}
83}
84
85<INITIAL>"module" BEGIN(SC_ttcn3module);
86
87<SC_ttcn3module>{TTCN3MODULENAME} {
88 if (module_name != NULL) *module_name = mcopystr(yytext);
89 BEGIN(SC_ttcn3modulebody);
90}
91
92<SC_ttcn3modulebody>"{"|"."|"language" return 1;
93
94. |
95<*><<EOF>> return 0;
96
97%%
98
99int is_ttcn3_module(const char *file_name, FILE *fp, char **module_name)
100{
101 int ret_val;
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,
105 strerror(errno));
106 errno = 0;
107 return 0;
108 }
109 yyin = fp;
110 ret_val = yylex(module_name);
111 yy_flush_buffer(YY_CURRENT_BUFFER);
112 if (ret_val == 0 && module_name != NULL && *module_name != NULL) {
113 Free(*module_name);
114 *module_name = NULL;
115 }
116 yylex_destroy();
117 return ret_val;
118}
This page took 0.027356 seconds and 5 git commands to generate.