File: stylecssscanner.ll

package info (click to toggle)
source-highlight 3.1.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,332 kB
  • ctags: 5,233
  • sloc: sh: 11,270; cpp: 10,206; ansic: 9,515; makefile: 1,865; lex: 1,200; yacc: 1,021; php: 213; perl: 211; awk: 98; erlang: 94; lisp: 90; java: 75; ruby: 69; python: 61; asm: 43; ml: 38; ada: 36; haskell: 27; xml: 23; cs: 11; sql: 8; tcl: 6; sed: 4
file content (217 lines) | stat: -rw-r--r-- 5,528 bytes parent folder | download | duplicates (6)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
%{
/*
 * 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 <string.h>

#include "stylekey.h"

#include "formatterfactory.h"
#include "stylecssparser.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

%}

%option prefix="stylecsssc_"
%option noyywrap

ws [ ]+
tabs [\t]+

nl \n
cr \r
IDE [a-zA-Z_]([a-zA-Z0-9_])*

VALUE [^\n\r:;[:blank:]]+

STRING \"[^\"\n]*\"

%s COMMENT_STATE MULTI_COMMENT_STATE STRING_STATE CSS_SELECTOR CSS_PROPERTIES CSS_COLOR CSS_BG_COLOR CSS_FONT_WEIGHT CSS_FONT_STYLE CSS_FONT_FAMILY CSS_TEXT_DECORATION

%%

{ws}|{tabs} {}

\r {}

"/*" { BEGIN(MULTI_COMMENT_STATE); }
<MULTI_COMMENT_STATE>[^\n] {}
<MULTI_COMMENT_STATE>\n { ++line;  BEGIN(INITIAL); }


<CSS_SELECTOR>"," { return ',' ; }
<CSS_SELECTOR>{IDE} { stylecsssc_lval.string = new std::string(yytext) ; return KEY ; }

\n { ++line ; }

<INITIAL>\.  {
  BEGIN(CSS_SELECTOR) ;
  DEB("CSS SELECTOR");
}
<INITIAL>[bB][oO][dD][yY]  {
  BEGIN(CSS_SELECTOR) ;
  DEB("BODY CSS SELECTOR");
  stylecsssc_lval.string = new std::string(yytext) ;
  return KEY;
}

<CSS_SELECTOR>\.  {
  // in case of comma separated selectors
  DEB("CSS SELECTOR");
}
<CSS_SELECTOR>"{" {
  BEGIN(CSS_PROPERTIES);
  DEB("CSS PROPERTIES");
}
<CSS_PROPERTIES>"color" {
  BEGIN(CSS_COLOR);
  DEB("CSS COLOR");
}
<CSS_COLOR>"green"|"red"|"darkred"|"blue"|"brown"|"pink"|"yellow"|"cyan"|"purple"|"orange"|"brightorange"|"darkgreen"|"brightgreen"|"black"|"teal"|"gray"|"darkblue" {
  BEGIN(CSS_PROPERTIES);
  stylecsssc_lval.string = new std::string(yytext) ;
  DEB2("CSS COLOR", yytext);
  return COLOR ;
}
<CSS_COLOR>[#[:alnum:]]+ {
  BEGIN(CSS_PROPERTIES);
  DEB2("CSS COLOR", yytext);
  /*
    we need to add the " in order to make source-highlight realize
    that this is a direct color specification
  */
  stylecsssc_lval.string = new std::string("\"" + std::string(yytext) + "\"");
  return STRINGDEF;
}
<CSS_PROPERTIES>"background-color" {
  BEGIN(CSS_BG_COLOR);
  DEB("CSS BACKGROUND COLOR");
}
<CSS_BG_COLOR>"green"|"red"|"darkred"|"blue"|"brown"|"pink"|"yellow"|"cyan"|"purple"|"orange"|"brightorange"|"darkgreen"|"brightgreen"|"black"|"teal"|"gray"|"darkblue" {
  BEGIN(CSS_PROPERTIES);
  stylecsssc_lval.string = new std::string(yytext) ;
  DEB2("CSS BG COLOR", yytext);
  return BG_COLOR ;
}
<CSS_BG_COLOR>[#[:alnum:]]+ {
  BEGIN(CSS_PROPERTIES);
  DEB2("CSS BG COLOR", yytext);
  /*
    we need to add the " in order to make source-highlight realize
    that this is a direct color specification
  */
  stylecsssc_lval.string = new std::string("\"" + std::string(yytext) + "\"");
  return BG_STRINGDEF;
}
<CSS_PROPERTIES>"font-weight" {
  BEGIN(CSS_FONT_WEIGHT);
  DEB("CSS FONT WEIGHT");
}
<CSS_FONT_WEIGHT>{VALUE} {
  BEGIN(CSS_PROPERTIES);
  if (strcmp(yytext, "bold") == 0) {
    DEB("CSS BOLD");
    stylecsssc_lval.flag = srchilite::ISBOLD ;
    return BOLD ;
  }
  DEB2("discarding not handled value", yytext);
}
<CSS_PROPERTIES>"font-style" {
  BEGIN(CSS_FONT_STYLE);
  DEB("CSS FONT STYLE");
}
<CSS_FONT_STYLE>{VALUE} {
  BEGIN(CSS_PROPERTIES);
  if (strcmp(yytext, "italic") == 0) {
    DEB("CSS ITALIC");
    stylecsssc_lval.flag = srchilite::ISITALIC ;
    return ITALICS ;
  }
  DEB2("discarding not handled value", yytext);
}
<CSS_PROPERTIES>"font-family" {
  BEGIN(CSS_FONT_FAMILY);
  DEB("CSS FONT FAMILY");
}
<CSS_FONT_FAMILY>{VALUE} {
  BEGIN(CSS_PROPERTIES);
  if (strcmp(yytext, "monospace") == 0) {
    DEB("CSS FIXED");
    stylecsssc_lval.flag = srchilite::ISFIXED ;
    return FIXED ;
  }
  DEB2("discarding not handled value", yytext);
}
<CSS_PROPERTIES>"text-decoration" {
  BEGIN(CSS_TEXT_DECORATION);
  DEB("CSS TEXT DECORATION");
}
<CSS_TEXT_DECORATION>{VALUE} {
  BEGIN(CSS_PROPERTIES);
  if (strcmp(yytext, "underline") == 0) {
    DEB("CSS UNDERLINE");
    stylecsssc_lval.flag = srchilite::ISUNDERLINE ;
    return UNDERLINE ;
  }
  DEB2("discarding not handled value", yytext);
}
<CSS_PROPERTIES>"}" {
  BEGIN(INITIAL);
  DEB("CSS END PROPERTIES");
  /*
    we must return ; since this is the terminator of a style option
    so we simulate it in case of css files
  */
  return ';' ;
}
<CSS_COLOR,CSS_BG_COLOR,CSS_FONT_WEIGHT,CSS_FONT_STYLE,CSS_FONT_FAMILY,CSS_TEXT_DECORATION>":"|";"|[\t]|[[:blank:]] {
  /* discard other characters */
  DEB2("CSS discarding", yytext);
}
<CSS_PROPERTIES>. {
  /* discard other properties */
  DEB2("CSS PROPERTIES discarding", yytext);
}

<INITIAL>.  { return yytext[0] ; }

%%