Sync with 5.4.0
[deliverable/titan.core.git] / compiler2 / asn1 / asn1_preparser.l
CommitLineData
970ed795 1/******************************************************************************
3abe9331 2 * Copyright (c) 2000-2015 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
7 ******************************************************************************/
8%option noyywrap
9%option never-interactive
10%option nounput
11
12%{
13
14#include "asn1_preparser.h"
15#include "../../common/memory.h"
16#include "../error.h"
17
18/** This inefficient macro is needed to cope with binary files.
19 * The scanner must stop immediately when it encounters a zero byte,
20 * which might cause confusion in the internal algorithm of flex. */
21#define YY_INPUT(buf,result,max_size) \
22{\
23 int c = getc(yyin); \
24 if (c == EOF || c == '\0') result = YY_NULL; \
25 else { \
26 buf[0] = c; \
27 result = 1; \
28 } \
29}
30
31#define YY_DECL static int yylex(char **module_name)
32
33%}
34
35ASN1MODULENAME [A-Z](-?[A-Za-z0-9]+)*
36
37WHITESPACE [ \t\n\v\f\r]
38LINECOMMENT --(-?[^\-\n\v\f\r]+)*(--|-?[\n\v\f\r])
39
40%x SC_blockcomment
41%s SC_moduleidentifier SC_definitiveidentifier SC_definitions
42
43%%
44 int blockcomment_caller = INITIAL, comment_depth = 0;
45 BEGIN(INITIAL);
46
47{WHITESPACE}|{LINECOMMENT}
48
49"/*" {
50 blockcomment_caller = YY_START;
51 comment_depth = 1;
52 BEGIN(SC_blockcomment);
53}
54
55<SC_blockcomment>
56{
57"/*" comment_depth++;
58"*/" if (--comment_depth == 0) BEGIN(blockcomment_caller);
59.|\n
60}
61
62<INITIAL>{ASN1MODULENAME} {
63 if (module_name != NULL) *module_name = mcopystr(yytext);
64 BEGIN(SC_moduleidentifier);
65}
66
67<SC_moduleidentifier>"{" BEGIN(SC_definitiveidentifier);
68
69<SC_definitiveidentifier>
70{
71"}" BEGIN(SC_definitions);
72.
73}
74
75<SC_moduleidentifier,SC_definitions>"DEFINITIONS" return 1;
76
77. |
78<*><<EOF>> return 0;
79
80%%
81
82int is_asn1_module(const char *file_name, FILE *fp, char **module_name)
83{
84 int ret_val;
85 if (module_name != NULL) *module_name = NULL;
86 if (fseek(fp, 0L, SEEK_SET)) {
87 ERROR("Seeking to the beginning of file `%s' failed: %s", file_name,
88 strerror(errno));
89 errno = 0;
90 return 0;
91 }
92 yyin = fp;
93 ret_val = yylex(module_name);
94 yy_flush_buffer(YY_CURRENT_BUFFER);
95 if (ret_val == 0 && module_name != NULL && *module_name != NULL) {
96 Free(*module_name);
97 *module_name = NULL;
98 }
99 yylex_destroy();
100 return ret_val;
101}
This page took 0.131912 seconds and 5 git commands to generate.