27
27
*/
28
28
29
29
package org. opensolaris. opengrok. analysis. python;
30
- import org. opensolaris. opengrok. analysis. JFlexXref ;
30
+ import org. opensolaris. opengrok. analysis. JFlexXrefSimple ;
31
31
import java. io. IOException;
32
32
import java. io. Writer;
33
33
import java. io. Reader;
34
+ import org. opensolaris. opengrok. web. HtmlConsts;
34
35
import org. opensolaris. opengrok. web. Util;
35
36
36
37
% %
37
38
%public
38
39
%class PythonXref
39
- %extends JFlexXref
40
+ %extends JFlexXrefSimple
40
41
%unicode
41
- %ignorecase
42
42
%int
43
43
%include CommonXref.lexh
44
44
%{
@@ -49,7 +49,9 @@ import org.opensolaris.opengrok.web.Util;
49
49
protected void setLineNumber(int x) { yyline = x; }
50
50
%}
51
51
52
- File = [ a- zA- Z] {FNameChar} * "." ( "py" | "pm" | "conf" | "txt" | "htm" | "html" | "xml" | "ini" | "diff" | "patch" )
52
+ File = [ a- zA- Z] {FNameChar} * "." ( [ Pp][ Yy] | [ Pp][ Mm] | [ Cc][ Oo][ Nn][ Ff] |
53
+ [ Tt][ Xx][ Tt] | [ Hh][ Tt][ Mm][ Ll] ? | [ Xx][ Mm][ Ll] | [ Ii][ Nn][ Ii] |
54
+ [ Dd][ Ii][ Ff][ Ff] | [ Pp][ Aa][ Tt][ Cc][ Hh] )
53
55
54
56
%state STRING LSTRING SCOMMENT QSTRING LQSTRING
55
57
@@ -83,62 +85,83 @@ File = [a-zA-Z]{FNameChar}* "." ("py"|"pm"|"conf"|"txt"|"htm"|"html"|"xml"|"ini"
83
85
out. write(" >" );
84
86
}
85
87
86
- {Number} { out. write(" <span class=\" n\" >" ); out. write(yytext()); out. write(" </span>" ); }
87
-
88
- \" { yybegin(STRING );out. write(" <span class=\" s\" >\" " );}
89
- \"\"\" { yybegin(LSTRING );out. write(" <span class=\" s\" >\"\"\" " );}
90
- \' { yybegin(QSTRING );out. write(" <span class=\" s\" >\' " );}
91
- \'\'\' { yybegin(LQSTRING );out. write(" <span class=\" s\" >\'\'\' " );}
92
- "#" { yybegin(SCOMMENT );out. write(" <span class=\" c\" >#" );}
88
+ {Number} {
89
+ disjointSpan(HtmlConsts . NUMBER_CLASS );
90
+ out. write(yytext());
91
+ disjointSpan(null );
92
+ }
93
+
94
+ \" {
95
+ pushSpan(STRING , HtmlConsts . STRING_CLASS );
96
+ out. write(htmlize(yytext()));
97
+ }
98
+ \"\"\" {
99
+ pushSpan(LSTRING , HtmlConsts . STRING_CLASS );
100
+ out. write(htmlize(yytext()));
101
+ }
102
+ \' {
103
+ pushSpan(QSTRING , HtmlConsts . STRING_CLASS );
104
+ out. write(htmlize(yytext()));
105
+ }
106
+ \'\'\' {
107
+ pushSpan(LQSTRING , HtmlConsts . STRING_CLASS );
108
+ out. write(htmlize(yytext()));
109
+ }
110
+ "#" {
111
+ pushSpan(SCOMMENT , HtmlConsts . COMMENT_CLASS );
112
+ out. write(yytext());
113
+ }
93
114
}
94
115
95
116
<STRING> {
96
- \" { yybegin(YYINITIAL ); out. write(" \" </span>" ); }
97
- \\\\ { out. write(" \\\\ " ); }
98
- \\\" { out. write(" \\\" " ); }
117
+ \\ [ \"\\ ] { out. write(htmlize(yytext())); }
118
+ \" {
119
+ out. write(htmlize(yytext()));
120
+ yypop();
121
+ }
99
122
{WhspChar} * {EOL} {
100
- yybegin( YYINITIAL ); out . write( " </span> " );
123
+ yypop( );
101
124
startNewLine();
102
125
}
103
126
}
104
127
105
128
<QSTRING> {
106
- "\\\\ " { out. write(" \\\\ " ); }
107
- "\\\' " { out. write(" \\\' " ); }
108
- \' {WhiteSpace} \' { out. write(yytext()); }
109
- \' { yybegin(YYINITIAL ); out. write(" '</span>" ); }
129
+ \\ [ \'\\ ] { out. write(htmlize(yytext())); }
130
+ \' {
131
+ out. write(htmlize(yytext()));
132
+ yypop();
133
+ }
110
134
{WhspChar} * {EOL} {
111
- yybegin( YYINITIAL ); out . write( " </span> " );
135
+ yypop( );
112
136
startNewLine();
113
137
}
114
138
}
115
139
116
140
<LSTRING> {
117
- \" {WhiteSpace} \" { out. write(yytext());}
118
- \"\"\" { yybegin(YYINITIAL ); out. write(" \"\"\" </span>" ); }
119
- \\\\ { out. write(" \\\\ " ); }
120
- \\\" { out. write(" \\\" " ); }
141
+ \\ [ \"\\ ] { out. write(htmlize(yytext()));}
142
+ \"\"\" {
143
+ out. write(htmlize(yytext()));
144
+ yypop();
145
+ }
121
146
}
122
147
123
148
<LQSTRING> {
124
- "\\\\ " { out. write(" \\\\ " ); }
125
- "\\\' " { out. write(" \\\' " ); }
126
- \' {WhiteSpace} \' { out. write(yytext()); }
127
- \'\'\' { yybegin(YYINITIAL ); out. write(" '''</span>" ); }
149
+ \\ [ \'\\ ] { out. write(htmlize(yytext())); }
150
+ \'\'\' {
151
+ out. write(htmlize(yytext()));
152
+ yypop();
153
+ }
128
154
}
129
155
130
156
<SCOMMENT> {
131
157
{WhspChar} * {EOL} {
132
- yybegin( YYINITIAL ); out . write( " </span> " );
158
+ yypop( );
133
159
startNewLine();
134
160
}
135
161
}
136
162
137
-
138
163
<YYINITIAL, STRING, SCOMMENT, QSTRING , LSTRING, LQSTRING> {
139
- "&" { out. write( " &" );}
140
- "<" { out. write( " <" );}
141
- ">" { out. write( " >" );}
164
+ [ &<>\'\" ] { out. write(htmlize(yytext())); }
142
165
{WhspChar} * {EOL} { startNewLine(); }
143
166
{WhiteSpace} { out. write(yytext()); }
144
167
[ !- ~] { out. write(yycharat(0 )); }
0 commit comments