1 /*===- ConfigLexer.l - Scanner for CompilerDriver Config Files -*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the flex scanner for configuration files for the
11 // llvmc CompilerDriver.
13 //===----------------------------------------------------------------------===*/
16 %option prefix="Config"
18 %option never-interactive
23 %option outfile="ConfigLexer.cpp"
31 #include "ConfigLexer.h"
33 #define YY_INPUT(buf,result,max_size) \
35 assert(ConfigLexerInput != 0 && "Oops"); \
36 result = ConfigLexerInput->read(buf,max_size); \
37 if (result == 0 ) result = YY_NULL; \
40 #define YY_FATAL_ERROR(msg) \
42 assert(ConfigLexerInput != 0 && "Oops"); \
43 ConfigLexerInput->error(msg); \
46 #define YY_DECL ConfigLexerTokens llvm::Configlex()
48 #define yyterminate() { return EOFTOK; }
52 inline llvm::ConfigLexerTokens
53 handleNameContext(llvm::ConfigLexerTokens token) {
54 ConfigLexerState.StringVal = yytext;
55 if (ConfigLexerState.in_value)
60 inline llvm::ConfigLexerTokens
61 handleSubstitution(llvm::ConfigLexerTokens token) {
62 if (ConfigLexerState.in_value) {
63 ConfigLexerState.StringVal = yytext;
66 YY_FATAL_ERROR("Substitition tokens not allowed in names" );
70 inline llvm::ConfigLexerTokens handleValueContext(llvm::ConfigLexerTokens token) {
71 ConfigLexerState.StringVal = yytext;
72 if (ConfigLexerState.in_value)
79 ASSEMBLER assembler|Assembler|ASSEMBLER
80 COMMAND command|Command|COMMAND
82 LINKER linker|Linker|LINKER
89 OPTIMIZER optimizer|Optimizer|OPTIMIZER
90 OUTPUT output|Output|OUTPUT
91 PREPROCESSES preprocesses|PreProcesses|PREPROCESSES
92 PREPROCESSOR preprocessor|PreProcessor|PREPROCESSOR
93 REQUIRED required|Required|REQUIRED
94 TRANSLATES translates|Translates|TRANSLATES
95 TRANSLATOR translator|Translator|TRANSLATOR
96 VERSION version|Version|VERSION
98 True true|True|TRUE|on|On|ON|yes|Yes|YES
99 False false|False|FALSE|off|Off|OFF|no|No|NO
100 Bytecode bc|BC|bytecode|Bytecode|BYTECODE
101 Assembly asm|ASM|assembly|Assembly|ASSEMBLY
103 BadSubst \%[^iots][a-zA-Z]\%
104 Comment \#[^\r\n]*\r?\n
108 Option [-A-Za-z0-9_:%+/\\|,][-A-Za-z0-9_:+/\\|,@]*
116 {White} { /* Ignore whitespace */ }
118 {Comment} { /* Ignore comments */
119 ConfigLexerState.in_value = false;
120 ConfigLexerState.lineNum++;
124 {EscNewLine} { ConfigLexerState.lineNum++;
125 /* Don't return EOLTOK! */
128 {NewLine} { ConfigLexerState.in_value = false;
129 ConfigLexerState.lineNum++;
133 {Eq} { ConfigLexerState.in_value = true;
137 {VERSION} { return handleNameContext(VERSION); }
139 {LANG} { return handleNameContext(LANG); }
140 {NAME} { return handleNameContext(NAME); }
141 {OPT1} { return handleNameContext(OPT1); }
142 {OPT2} { return handleNameContext(OPT2); }
143 {OPT3} { return handleNameContext(OPT3); }
144 {OPT4} { return handleNameContext(OPT4); }
145 {OPT5} { return handleNameContext(OPT5); }
147 {PREPROCESSOR} { return handleNameContext(PREPROCESSOR); }
148 {COMMAND} { return handleNameContext(COMMAND); }
149 {REQUIRED} { return handleNameContext(REQUIRED); }
151 {TRANSLATOR} { return handleNameContext(TRANSLATOR); }
152 {PREPROCESSES} { return handleNameContext(PREPROCESSES); }
153 {OUTPUT} { return handleNameContext(OUTPUT); }
155 {OPTIMIZER} { return handleNameContext(OPTIMIZER); }
156 {TRANSLATES} { return handleNameContext(TRANSLATES); }
158 {ASSEMBLER} { return handleNameContext(ASSEMBLER); }
160 {LINKER} { return handleNameContext(LINKER); }
162 %args% { return handleSubstitution(ARGS_SUBST); }
163 %force% { return handleSubstitution(FORCE_SUBST); }
164 %in% { return handleSubstitution(IN_SUBST); }
165 %opt% { return handleSubstitution(OPT_SUBST); }
166 %out% { return handleSubstitution(OUT_SUBST); }
167 %stats% { return handleSubstitution(STATS_SUBST); }
168 %target% { return handleSubstitution(TARGET_SUBST); }
169 %time% { return handleSubstitution(TIME_SUBST); }
170 %verbose% { return handleSubstitution(VERBOSE_SUBST); }
171 {BadSubst} { YY_FATAL_ERROR("Invalid substitution token"); }
173 {Assembly} { return handleValueContext(ASSEMBLY); }
174 {Bytecode} { return handleValueContext(BYTECODE); }
175 {True} { return handleValueContext(TRUETOK); }
176 {False} { return handleValueContext(FALSETOK); }
178 {Option} { ConfigLexerState.StringVal = yytext; return OPTION; }
179 {String} { ConfigLexerState.StringVal = yytext+1; // Nuke start quote
180 ConfigLexerState.StringVal.erase(
181 --ConfigLexerState.StringVal.end());
184 {Sep} { if (ConfigLexerState.in_value) { ConfigLexerState.StringVal = yytext;