summaryrefslogtreecommitdiffstats
path: root/mmss/config.l
diff options
context:
space:
mode:
Diffstat (limited to 'mmss/config.l')
-rw-r--r--mmss/config.l129
1 files changed, 129 insertions, 0 deletions
diff --git a/mmss/config.l b/mmss/config.l
new file mode 100644
index 0000000..6f20423
--- /dev/null
+++ b/mmss/config.l
@@ -0,0 +1,129 @@
+/*
+ Copyright (c) 2013, Matthias Schiffer <mschiffer@universe-factory.net>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+%option prefix="mmss_config_yy"
+%option noyywrap
+%option nounput
+%option noinput
+%option bison-bridge
+%option bison-locations
+%option reentrant
+%option warn
+
+
+%top {
+ #include <config.yy.hpp>
+}
+
+%s NEEDSPACE
+%s STRING
+%s COMMENT
+
+%%
+%{
+ #define UPDATE_LOCATION do { \
+ yylloc->first_line = yylloc->last_line; \
+ yylloc->first_column = yylloc->last_column+1; \
+ yylloc->last_column += yyleng; \
+ } while (0)
+
+ #define TOKEN(tok) do { UPDATE_LOCATION; BEGIN(NEEDSPACE); return tok; } while (0)
+%}
+
+<INITIAL>{
+[0-9]+ { UPDATE_LOCATION; yylval->num = atoi(yytext); BEGIN(NEEDSPACE); return TOK_INTEGER; }
+
+yes { TOKEN(TOK_YES); }
+no { TOKEN(TOK_NO); }
+network { TOKEN(TOK_NETWORK); }
+
+[;:\{\}] { UPDATE_LOCATION; return yytext[0]; }
+
+[ \t] { yylloc->last_column++; }
+\n { yylloc->last_column = 0; yylloc->last_line++; }
+\r ;
+}
+
+<NEEDSPACE>{
+[;:\{\}] { UPDATE_LOCATION; BEGIN(INITIAL); return yytext[0]; }
+
+[ \t] { yylloc->last_column++; BEGIN(INITIAL); }
+\n { yylloc->last_column = 0; yylloc->last_line++; BEGIN(INITIAL); }
+\r ;
+}
+
+<INITIAL>\" { UPDATE_LOCATION; BEGIN(STRING); }
+<STRING>[^"\\\n\r] { yylloc->last_column++; yymore(); }
+<STRING>\n { yylloc->last_line++; yylloc->last_column = 0; yymore(); }
+<STRING>\r { yymore(); }
+<STRING>\\. { yylloc->last_column+=2; yymore(); }
+<STRING>\\\n { yylloc->last_line++; yylloc->last_column = 0; yymore(); }
+<STRING>\" {
+ int i, esc = 0;
+
+ for (i = 0; i < yyleng; i++) {
+ if (yytext[i] == '\\') {
+ i++;
+ if (yytext[i] == '\n') {
+ esc+=2;
+ }
+ else {
+ yytext[i-esc-1] = yytext[i];
+ esc++;
+ }
+ }
+ else if(esc) {
+ yytext[i-esc] = yytext[i];
+ }
+ }
+ yytext[yyleng-esc-1] = 0;
+ yylval->str = mmss_string_stack_dup(yytext);
+ BEGIN(NEEDSPACE);
+ yylloc->last_column++;
+ return TOK_STRING;
+
+ }
+
+<INITIAL,NEEDSPACE>#.* { yylloc->last_column += yyleng; }
+<INITIAL,NEEDSPACE>\/\/.* { yylloc->last_column += yyleng; }
+
+<INITIAL,NEEDSPACE>\/\* { UPDATE_LOCATION; BEGIN(COMMENT); }
+<COMMENT>\*\/ { yylloc->last_column += yyleng; BEGIN(INITIAL); }
+<COMMENT>[^\n\r] { yylloc->last_column++; }
+<COMMENT>\n { yylloc->last_line++; yylloc->last_column = 0; }
+<COMMENT>\r {}
+
+. {
+ yylloc->first_line = yylloc->last_line;
+ yylloc->first_column = yylloc->last_column+1;
+ yylval->error = "syntax error";
+ return -1;
+ }
+
+<INITIAL><<EOF>> { return 0; }
+<COMMENT><<EOF>> { yylval->error = "unterminated block comment"; return -1; }
+<STRING><<EOF>> { yylval->error = "unterminated string"; return -1; }
+%%