1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
%{
/*
* Copyright (C) 1999-2007 Lorenzo Bettini, http://www.lorenzobettini.it
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include "stylekey.h"
#include "formatterfactory.h"
#include "styleparser.h"
#include <sstream>
#include "parsestyles.h"
using namespace srchilite;
static std::ostringstream buff;
extern int line ;
//#define DEBUG_SCANNER
#ifdef DEBUG_SCANNER
#include <iostream> // for debug
#define DEB(s) std::cerr << s << std::endl;
#define DEB2(s,s2) std::cerr << s << ": " << s2 << std::endl;
#else
#define DEB(s)
#define DEB2(s,s2)
#endif
static void buffer(const char *s);
static const std::string *flush_buffer();
%}
%option prefix="stylesc_"
%option noyywrap
ws [ ]+
tabs [\t]+
nl \n
cr \r
IDE [a-zA-Z_]([a-zA-Z0-9_])*
STRING \"[^\"\n]*\"
%s COMMENT_STATE STRING_STATE
%%
{ws}|{tabs} {}
\r {}
<INITIAL>"//" { BEGIN(COMMENT_STATE); }
<COMMENT_STATE>[^\n] {}
<COMMENT_STATE>\n { ++line; BEGIN(INITIAL); }
<INITIAL>"green"|"red"|"darkred"|"blue"|"brown"|"pink"|"yellow"|"cyan"|"purple"|"orange"|"brightorange"|"darkgreen"|"brightgreen"|"black"|"teal"|"gray"|"darkblue"|"white" { stylesc_lval.string = new std::string(yytext) ; return COLOR ; }
<INITIAL>"bgcolor" { return BODY_BG_COLOR ; }
<INITIAL>"bg" { return BG_T ; }
<INITIAL>"b" { stylesc_lval.flag = ISBOLD ; return BOLD ; }
<INITIAL>"i" { stylesc_lval.flag = ISITALIC ; return ITALICS ; }
<INITIAL>"u" { stylesc_lval.flag = ISUNDERLINE ; return UNDERLINE ; }
<INITIAL>"f" { stylesc_lval.flag = ISFIXED; return FIXED; }
<INITIAL>"nf" { stylesc_lval.flag = ISNOTFIXED; return NOTFIXED; }
<INITIAL>"noref" { stylesc_lval.flag = ISNOREF; return NOREF; }
<INITIAL>"," { return ',' ; }
<INITIAL>";" { return ';' ; }
<INITIAL>":" { return ':' ; }
<INITIAL>{IDE} { stylesc_lval.string = new std::string(yytext) ; return KEY ; }
<INITIAL>\" { BEGIN(STRING_STATE); DEB("STRING_STATE"); buffer( yytext ) ; }
<STRING_STATE>\\\\ { buffer( yytext ) ; }
<STRING_STATE>"\\\"" { buffer( "\"" ) ; }
<STRING_STATE>\" { BEGIN(INITIAL) ; buffer( yytext ) ; DEB("END STRING_STATE"); stylesc_lval.string = flush_buffer() ; return STRINGDEF; }
<STRING_STATE>[^\n]|" " { buffer( yytext ) ; }
<STRING_STATE>\n { buffer( "\n" ) ; }
\n { ++line ; }
<INITIAL>. { /* anything else will generate a parsing error */ return yytext[0] ; }
%%
void buffer(const char *s)
{
DEB2("BUFFERING ", s);
buff << s;
}
const std::string *flush_buffer()
{
const std::string *ret = new std::string(buff.str());
buff.str("");
return ret;
}
|