27
27
*/
28
28
29
29
package org. opensolaris. opengrok. analysis. golang;
30
- import org. opensolaris. opengrok. analysis. JFlexXref;
30
+ import org. opensolaris. opengrok. analysis. JFlexXrefSimple;
31
+ import org. opensolaris. opengrok. web. HtmlConsts;
31
32
import org. opensolaris. opengrok. web. Util;
32
33
33
34
/**
@@ -37,9 +38,8 @@ import org.opensolaris.opengrok.web.Util;
37
38
% %
38
39
%public
39
40
%class GolangXref
40
- %extends JFlexXref
41
+ %extends JFlexXrefSimple
41
42
%unicode
42
- %ignorecase
43
43
%int
44
44
%include CommonXref.lexh
45
45
%{
@@ -50,7 +50,8 @@ import org.opensolaris.opengrok.web.Util;
50
50
protected void setLineNumber(int x) { yyline = x; }
51
51
%}
52
52
53
- File = [ a- zA- Z] {FNameChar} * "." ( "go" | "txt" | "htm" | "html" | "diff" | "patch" )
53
+ File = [ a- zA- Z] {FNameChar} * "." ( [ Gg][ Oo] | [ Tt][ Xx][ Tt] | [ Hh][ Tt][ Mm][ Ll] ? |
54
+ [ Dd][ Ii][ Ff][ Ff] | [ Pp][ Aa][ Tt][ Cc][ Hh] )
54
55
55
56
%state STRING COMMENT SCOMMENT QSTRING
56
57
@@ -64,11 +65,27 @@ File = [a-zA-Z]{FNameChar}* "." ("go"|"txt"|"htm"|"html"|"diff"|"patch")
64
65
String id = yytext();
65
66
writeSymbol(id, Consts . kwd, yyline);
66
67
}
67
- {Number} { out. write(" <span class=\" n\" >" ); out. write(yytext()); out. write(" </span>" ); }
68
- \" { yybegin(STRING ); out. write(" <span class=\" s\" >\" " ); }
69
- \' { yybegin(QSTRING ); out. write(" <span class=\" s\" >\' " ); }
70
- "/*" { yybegin(COMMENT ); out. write(" <span class=\" c\" >/*" ); }
71
- "//" { yybegin(SCOMMENT ); out. write(" <span class=\" c\" >//" ); }
68
+ {Number} {
69
+ disjointSpan(HtmlConsts . NUMBER_CLASS );
70
+ out. write(yytext());
71
+ disjointSpan(null );
72
+ }
73
+ \" {
74
+ pushSpan(STRING , HtmlConsts . STRING_CLASS );
75
+ out. write(htmlize(yytext()));
76
+ }
77
+ \' {
78
+ pushSpan(QSTRING , HtmlConsts . STRING_CLASS );
79
+ out. write(htmlize(yytext()));
80
+ }
81
+ "/*" {
82
+ pushSpan(COMMENT , HtmlConsts . COMMENT_CLASS );
83
+ out. write(yytext());
84
+ }
85
+ "//" {
86
+ pushSpan(SCOMMENT , HtmlConsts . COMMENT_CLASS );
87
+ out. write(yytext());
88
+ }
72
89
}
73
90
74
91
"<" ( {File} | {FPath} ) ">" {
@@ -85,33 +102,42 @@ File = [a-zA-Z]{FNameChar}* "." ("go"|"txt"|"htm"|"html"|"diff"|"patch")
85
102
}
86
103
87
104
<STRING> {
88
- \" {WhiteSpace} \" { out. write(yytext()); }
89
- \" { yybegin(YYINITIAL ); out. write(" \" </span>" ); }
90
- \\\\ { out. write(" \\\\ " ); }
91
- \\\" { out. write(" \\\" " ); }
105
+ \\ [ \"\\ ] |
106
+ \" {WhiteSpace} \" { out. write(htmlize(yytext())); }
107
+ \" {
108
+ out. write(htmlize(yytext()));
109
+ yypop();
110
+ }
92
111
}
93
112
94
113
<QSTRING> {
95
- "\\\\ " { out. write(" \\\\ " ); }
96
- "\\ '" { out. write(" \\\' " ); }
97
- \' {WhiteSpace} \' { out. write(yytext()); }
98
- \' { yybegin(YYINITIAL ); out. write(" '</span>" ); }
114
+ \\ [ \'\\ ] |
115
+ \' {WhiteSpace} \' { out. write(htmlize(yytext())); }
116
+ \' {
117
+ out. write(htmlize(yytext()));
118
+ yypop();
119
+ }
99
120
}
100
121
101
122
<COMMENT> {
102
- "*/" { yybegin(YYINITIAL ); out. write(" */</span>" ); }
123
+ "*/" {
124
+ out. write(yytext());
125
+ yypop();
126
+ }
103
127
}
104
128
105
129
<SCOMMENT> {
106
- {WhspChar} * {EOL} { yybegin(YYINITIAL ); out. write(" </span>" ); startNewLine(); }
130
+ {WhspChar} * {EOL} {
131
+ yypop();
132
+ startNewLine();
133
+ }
107
134
}
108
135
109
136
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
110
- "&" { out. write( " &" ); }
111
- "<" { out. write( " <" ); }
112
- ">" { out. write( " >" ); }
137
+ [ &<>\'\" ] { out. write(htmlize(yytext())); }
113
138
{WhspChar} * {EOL} { startNewLine(); }
114
139
{WhiteSpace} { out. write(yytext()); }
140
+ [ !- ~] { out. write(yycharat(0 )); }
115
141
[^\n] { writeUnicodeChar(yycharat(0 )); }
116
142
}
117
143
0 commit comments