Skip to content

Commit d075125

Browse files
committed
fix """ strings in kotlin & swift analyzers
1 parent 94dc2f0 commit d075125

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

src/org/opensolaris/opengrok/analysis/kotlin/KotlinSymbolTokenizer.lex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ return false;
4949

5050
Identifier = [:jletter:] [:jletterdigit:]*
5151

52-
%state STRING COMMENT SCOMMENT QSTRING
52+
%state STRING COMMENT SCOMMENT QSTRING TSTRING
5353

5454
%%
5555

@@ -63,12 +63,12 @@ Identifier = [:jletter:] [:jletterdigit:]*
6363

6464
\" { yybegin(STRING); }
6565
\' { yybegin(QSTRING); }
66+
\"\"\" { yybegin(TSTRING); }
6667
"/*" { yybegin(COMMENT); }
6768
"//" { yybegin(SCOMMENT); }
6869

6970
}
7071

71-
/* TODO : support raw """ strings */
7272
<STRING> {
7373
\" { yybegin(YYINITIAL); }
7474
\\\\ | \\\" {}
@@ -78,6 +78,10 @@ Identifier = [:jletter:] [:jletterdigit:]*
7878
\' { yybegin(YYINITIAL); }
7979
}
8080

81+
<TSTRING> {
82+
\"\"\" { yybegin(YYINITIAL); }
83+
}
84+
8185
<COMMENT> {
8286
"*/" { yybegin(YYINITIAL);}
8387
}
@@ -86,7 +90,7 @@ Identifier = [:jletter:] [:jletterdigit:]*
8690
\n { yybegin(YYINITIAL);}
8791
}
8892

89-
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
93+
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING, TSTRING> {
9094
<<EOF>> { this.finalOffset = zzEndRead; return false;}
9195
[^] {}
9296
}

src/org/opensolaris/opengrok/analysis/kotlin/KotlinXref.lex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ KdocWithParamNameArg = "@param"
6666
ClassName = ({Identifier} ".")* {Identifier}
6767
ParamName = {Identifier} | "<" {Identifier} ">"
6868

69-
%state STRING COMMENT SCOMMENT QSTRING KDOC
69+
%state STRING COMMENT SCOMMENT QSTRING KDOC TSTRING
7070

7171
%%
7272
<YYINITIAL>{
@@ -99,6 +99,7 @@ ParamName = {Identifier} | "<" {Identifier} ">"
9999

100100
\" { yybegin(STRING);out.write("<span class=\"s\">\"");}
101101
\' { yybegin(QSTRING);out.write("<span class=\"s\">\'");}
102+
\"\"\" { yybegin(TSTRING);out.write("<span class=\"s\">\"\"\"");}
102103
"/**" / [^/] { yybegin(KDOC);out.write("<span class=\"c\">/**");}
103104
"/*" { yybegin(COMMENT);out.write("<span class=\"c\">/*");}
104105
"//" { yybegin(SCOMMENT);out.write("<span class=\"c\">//");}
@@ -118,6 +119,12 @@ ParamName = {Identifier} | "<" {Identifier} ">"
118119
\' { yybegin(YYINITIAL); out.write("'</span>"); }
119120
}
120121

122+
<TSTRING> {
123+
"\\\\" { out.write("\\\\"); }
124+
"\\\"" { out.write("\\\""); }
125+
\"\"\" { yybegin(YYINITIAL); out.write("\"\"\"</span>"); }
126+
}
127+
121128
<COMMENT, KDOC> {
122129
"*/" { yybegin(YYINITIAL); out.write("*/</span>"); }
123130
}
@@ -145,7 +152,7 @@ ParamName = {Identifier} | "<" {Identifier} ">"
145152
}
146153

147154

148-
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING, KDOC> {
155+
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING, KDOC, TSTRING> {
149156
"&" {out.write( "&amp;");}
150157
"<" {out.write( "&lt;");}
151158
">" {out.write( "&gt;");}
@@ -155,7 +162,7 @@ ParamName = {Identifier} | "<" {Identifier} ">"
155162
[^\n] { writeUnicodeChar(yycharat(0)); }
156163
}
157164

158-
<STRING, COMMENT, SCOMMENT, STRING, QSTRING, KDOC> {
165+
<STRING, COMMENT, SCOMMENT, STRING, QSTRING, TSTRING, KDOC> {
159166
{Path}
160167
{ out.write(Util.breadcrumbPath(urlPrefix+"path=",yytext(),'/'));}
161168

src/org/opensolaris/opengrok/analysis/swift/SwiftSymbolTokenizer.lex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ return false;
5050
/* TODO add unicode as stated in https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/swift/grammar/identifier-head */
5151
Identifier = [:jletter:] [:jletterdigit:]*
5252

53-
%state STRING COMMENT SCOMMENT QSTRING
53+
%state STRING COMMENT SCOMMENT QSTRING TSTRING
5454

5555
%%
5656

@@ -64,6 +64,7 @@ Identifier = [:jletter:] [:jletterdigit:]*
6464

6565
\" { yybegin(STRING); }
6666
\' { yybegin(QSTRING); }
67+
\"\"\" { yybegin(TSTRING); }
6768
"/*" { yybegin(COMMENT); }
6869
"//" { yybegin(SCOMMENT); }
6970

@@ -79,6 +80,10 @@ Identifier = [:jletter:] [:jletterdigit:]*
7980
\' { yybegin(YYINITIAL); }
8081
}
8182

83+
<TSTRING> {
84+
\"\"\" { yybegin(YYINITIAL); }
85+
}
86+
8287
<COMMENT> {
8388
"*/" { yybegin(YYINITIAL);}
8489
}
@@ -87,7 +92,7 @@ Identifier = [:jletter:] [:jletterdigit:]*
8792
\n { yybegin(YYINITIAL);}
8893
}
8994

90-
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING> {
95+
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING, TSTRING> {
9196
<<EOF>> { this.finalOffset = zzEndRead; return false;}
9297
[^] {}
9398
}

src/org/opensolaris/opengrok/analysis/swift/SwiftXref.lex

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ClassName = "class"{WhiteSpace}+({Identifier} ".")* {Identifier}
6868
ParamName = {Identifier} | "<" {Identifier} ">"
6969
*/
7070

71-
%state STRING COMMENT SCOMMENT QSTRING SDOC
71+
%state STRING COMMENT SCOMMENT QSTRING SDOC TSTRING
7272

7373
%%
7474
<YYINITIAL>{
@@ -101,11 +101,12 @@ ParamName = {Identifier} | "<" {Identifier} ">"
101101

102102
\" { yybegin(STRING);out.write("<span class=\"s\">\"");}
103103
\' { yybegin(QSTRING);out.write("<span class=\"s\">\'");}
104+
\"\"\" { yybegin(TSTRING);out.write("<span class=\"s\">\"\"\"");}
104105
"/**" / [^/] { yybegin(SDOC);out.write("<span class=\"c\">/**");}
105106
"/*" { yybegin(COMMENT);out.write("<span class=\"c\">/*");}
106107
"//" { yybegin(SCOMMENT);out.write("<span class=\"c\">//");}
107108
}
108-
/* TODO : support raw """ strings */
109+
109110
<STRING> {
110111
\" {WhiteSpace} \" { out.write(yytext());}
111112
\" { yybegin(YYINITIAL); out.write("\"</span>"); }
@@ -120,6 +121,12 @@ ParamName = {Identifier} | "<" {Identifier} ">"
120121
\' { yybegin(YYINITIAL); out.write("'</span>"); }
121122
}
122123

124+
<TSTRING> {
125+
"\\\\" { out.write("\\\\"); }
126+
"\\\"" { out.write("\\\""); }
127+
\"\"\" { yybegin(YYINITIAL); out.write("\"\"\"</span>"); }
128+
}
129+
123130
<COMMENT, SDOC> {
124131
"*/" { yybegin(YYINITIAL); out.write("*/</span>"); }
125132
}
@@ -149,7 +156,7 @@ ParamName = {Identifier} | "<" {Identifier} ">"
149156
}
150157

151158

152-
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING, SDOC> {
159+
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING, SDOC, TSTRING> {
153160
"&" {out.write( "&amp;");}
154161
"<" {out.write( "&lt;");}
155162
">" {out.write( "&gt;");}
@@ -159,7 +166,7 @@ ParamName = {Identifier} | "<" {Identifier} ">"
159166
[^\n] { writeUnicodeChar(yycharat(0)); }
160167
}
161168

162-
<STRING, COMMENT, SCOMMENT, STRING, QSTRING, SDOC> {
169+
<STRING, COMMENT, SCOMMENT, STRING, QSTRING, SDOC, TSTRING> {
163170
{Path}
164171
{ out.write(Util.breadcrumbPath(urlPrefix+"path=",yytext(),'/'));}
165172

testdata/sources/swift/helloWorld.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
print("Hello, world!")
44

55

6+
let banner = """
7+
__,
8+
( o /) _/_
9+
`. , , , , // /
10+
(___)(_(_/_(_ //_ (__
11+
/)
12+
(/
13+
"""
14+
615

716

817
func greet(person: String, day: String) -> String {

0 commit comments

Comments
 (0)