1 /* -*- fundamental -*- */ 2 /* 3 * libxlu_cfg_l.l - xl configuration file parsing: lexer 4 * 5 * Copyright (C) 2010 Citrix Ltd. 6 * Author Ian Jackson <ian.jackson@eu.citrix.com> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published 10 * by the Free Software Foundation; version 2.1 only. with the special 11 * exception on linking described in file LICENSE. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 */ 18 19 %{ 20 #include "libxlu_cfg_i.h" 21 22 #define ctx ((CfgParseContext*)yyextra) 23 #define YY_NO_INPUT 24 25 #define GOT(x) do{ \ 26 yylloc->first_line= yylineno; \ 27 return (x); \ 28 }while(0) 29 30 /* Some versions of flex have a bug (Fedora bugzilla 612465) which causes 31 * it to fail to declare these functions, which it defines. So declare 32 * them ourselves. Hopefully we won't have to simultaneously support 33 * a flex version which declares these differently somehow. */ 34 int xlu__cfg_yyget_column(yyscan_t yyscanner); 35 void xlu__cfg_yyset_column(int column_no, yyscan_t yyscanner); 36 37 %} 38 39 %option warn 40 %option nodefault 41 %option batch 42 %option 8bit 43 %option yylineno 44 %option noyywrap 45 %option bison-bridge 46 %option bison-locations 47 %option reentrant 48 %option prefix="xlu__cfg_yy" 49 %option nounput 50 51 %x lexerr 52 53 %% 54 55 [a-z][._0-9a-z]* { 56 yylval->string= xlu__cfgl_strdup(ctx,yytext); 57 GOT(IDENT); 58 } 59 [0-9][0-9a-fx]* { 60 yylval->string= xlu__cfgl_strdup(ctx,yytext); 61 GOT(NUMBER); 62 } 63 64 [ \t] 65 66 , { GOT(','); } 67 \[ { GOT('['); } 68 \] { GOT(']'); } 69 \+\= { GOT(OP_ADD); } 70 \= { GOT('='); } 71 \; { GOT(';'); } 72 73 \n|\#.*\n { yylloc->first_line= yylineno-1; return NEWLINE; } 74 75 \'([^\'\\\n]|\\.)*\' { 76 yylval->string= xlu__cfgl_dequote(ctx,yytext); 77 GOT(STRING); 78 } 79 \"([^\"\\\n]|\\.)*\" { 80 yylval->string= xlu__cfgl_dequote(ctx,yytext); 81 GOT(STRING); 82 } 83 84 [+-.():] { 85 ctx->likely_python= 1; 86 BEGIN(lexerr); 87 yymore(); 88 } 89 90 . { 91 BEGIN(lexerr); 92 yymore(); 93 } 94 95 <lexerr>[^ \t\n]*|[ \t] { 96 xlu__cfgl_lexicalerror(ctx,"lexical error"); 97 BEGIN(0); 98 } 99 100 <lexerr>\n { 101 xlu__cfgl_lexicalerror(ctx,"lexical error"); 102 BEGIN(0); 103 GOT(NEWLINE); 104 } 105