/* */
1 /*
2 * Copyright (c) 2004, 2005 Tama Communications Corporation
3 *
4 * This file is part of GNU GLOBAL.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef _LEXCOMMON_H
20 #define _LEXCOMMON_H
21
22 #include "incop.h"
23 #include "tab.h"
24
25 /**
26 * @name Definition of LEXTEXT, LEXLENG, LEXIN and LEXRESTART.
27 *
28 * These symbols are substitutions of @CODE{yytext}, @CODE{yyleng}, @CODE{yyin} and @CODE{yyrestart}.
29 * You should write @NAME{lex} code using them.
30 * The usage of this file is, for instance, in @FILE{c.l}:
31 *
32 * @code
33 * #define lex_symbol_generation_rule(x) c_ ## x
34 * #include "lexcommon.h"
35 * @endcode
36 */
37 /** @{ */
38 #ifndef lex_symbol_generation_rule
39 ERROR: lex_symbol_generation_rule(x) macro not defined.
40 lexcommon.h requires the lex_symbol_generation_rule(x) macro for each language
41 to generate language specific symbols.
42 #endif
43 #define LEXTEXT lex_symbol_generation_rule(text)
44 #define LEXLENG lex_symbol_generation_rule(leng)
45 #define LEXIN lex_symbol_generation_rule(in)
46 #define LEXRESTART lex_symbol_generation_rule(restart)
47 /** @} */
48
49 /**
50 * @name
51 * The default action for line control.
52 * These can be applicable to most languages. <br>
53 * You must define @VAR{C_COMMENT}, @VAR{CPP_COMMENT} @VAR{SHELL_COMMENT}, @VAR{LITERAL}, @VAR{STRING}
54 * and @VAR{PREPROCESSOR_LINE} as @CODE{\%start} values, even if they are not used. <br>
55 * It assumed that @VAR{CPP_COMMENT} and @VAR{SHELL_COMMENT} is one line comment.
56 */
57 /** @{ */
58 static int lexcommon_lineno;
59 static int begin_line;
60 /** @} */
61
62 /**
63 * If you want newline to terminate string, set this variable to 1.
64 */
65 static int newline_terminate_string = 0;
66
67 /**
68 * @name Variables for converting tabs to spaces.
69 */
70 /** @{ */
71 static int dest_column;
72 static int left_spaces;
73 /** @} */
74
75 #define YY_INPUT(buf, result, max_size) do { \
76 result = read_file_detabing(buf, max_size, LEXIN, \
77 &dest_column, &left_spaces); \
78 } while (0)
79
80 #define LINENO lexcommon_lineno
81
82 #define DEFAULT_BEGIN_OF_FILE_ACTION { \
83 LEXIN = ip; \
84 LEXRESTART(LEXIN); \
85 LINENO = 1; \
86 begin_line = 1; \
87 dest_column = 0; \
88 left_spaces = 0; \
89 }
90
91 #define DEFAULT_YY_USER_ACTION { \
92 if (begin_line) { \
93 put_begin_of_line(LINENO); \
94 switch (YY_START) { \
95 case C_COMMENT: \
96 case CPP_COMMENT: \
97 case SHELL_COMMENT: \
98 echos(comment_begin); \
99 break; \
100 } \
101 begin_line = 0; \
102 } \
103 }
104
105 #define DEFAULT_END_OF_LINE_ACTION { \
106 switch (YY_START) { \
107 case CPP_COMMENT: \
108 case SHELL_COMMENT: \
109 yy_pop_state(); \
110 /* FALLTHROUGH */ \
111 case C_COMMENT: \
112 echos(comment_end); \
113 break; \
114 case STRING: \
115 case LITERAL: \
116 if (newline_terminate_string) \
117 yy_pop_state(); \
118 break; \
119 } \
120 if (YY_START == PREPROCESSOR_LINE) \
121 yy_pop_state(); \
122 put_end_of_line(LINENO); \
123 /* for the next line */ \
124 LINENO++; \
125 begin_line = 1; \
126 }
127
128 #define DEFAULT_BACKSLASH_NEWLINE_ACTION { \
129 echoc('\\'); \
130 switch (YY_START) { \
131 case CPP_COMMENT: \
132 case C_COMMENT: \
133 case SHELL_COMMENT: \
134 echos(comment_end); \
135 break; \
136 } \
137 put_end_of_line(LINENO); \
138 /* for the next line */ \
139 LINENO++; \
140 begin_line = 1; \
141 }
142
143 /*
144 * Output routine.
145 */
146 extern void echoc(int);
147 extern void echos(const char *);
148 extern const char *generate_guide(int);
149 extern void put_anchor(char *, int, int);
150 extern void put_anchor_force(char *, int, int);
151 extern void put_include_anchor(struct data *, const char *);
152 extern void put_include_anchor_direct(const char *, const char *);
153 extern void put_reserved_word(const char *);
154 extern void put_macro(const char *);
155 extern void unknown_preprocessing_directive(const char *, int);
156 extern void unexpected_eof(int);
157 extern void unknown_yacc_directive(const char *, int);
158 extern void missing_left(const char *, int);
159 extern void put_char(int);
160 extern void put_string(const char *);
161 extern void put_brace(const char *);
162 extern void put_begin_of_line(int);
163 extern void put_end_of_line(int);
164
165 #endif /* ! _LEXCOMMON_H */
/* */