Skip to content

Commit addd9b5

Browse files
authored
Merge pull request #1931 from idodeclare/bugfix/ruby_end_interp
Bugfix/ruby end interp
2 parents a9c5b1e + f98a847 commit addd9b5

File tree

8 files changed

+51
-9
lines changed

8 files changed

+51
-9
lines changed

src/org/opensolaris/opengrok/analysis/ruby/RubyLexHelper.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*/
4040
interface RubyLexer extends JFlexJointLexer {
4141
void maybeIntraState();
42+
void popHelper();
4243
}
4344

4445
/**
@@ -188,6 +189,12 @@ public void qop(String op, int namelength, boolean nointerp)
188189
*/
189190
public void qop(boolean doWrite, String capture, int namelength,
190191
boolean nointerp) throws IOException {
192+
193+
// N.b. the following will write anyway -- despite any `doWrite'
194+
// setting -- if interpolation is truly ending, but that is OK as a
195+
// quote-like operator is not starting in that case.
196+
if (maybeEndInterpolation(capture)) return;
197+
191198
// If namelength is positive, allow that a non-zero-width word boundary
192199
// character may have needed to be matched since jflex does not conform
193200
// with \b as a zero-width simple word boundary. Excise it into
@@ -272,6 +279,8 @@ private void setEndQuoteChar(char opener) {
272279
* to output.
273280
*/
274281
public void hqopPunc(String capture) throws IOException {
282+
if (maybeEndInterpolation(capture)) return;
283+
275284
// `preceding' is everything before the '/'; 'lede' is the initial part
276285
// before any whitespace; and `intervening' is any whitespace.
277286
String preceding = capture.substring(0, capture.length() - 1);
@@ -293,6 +302,8 @@ public void hqopPunc(String capture) throws IOException {
293302
* parts to output.
294303
*/
295304
public void hqopSymbol(String capture) throws IOException {
305+
if (maybeEndInterpolation(capture)) return;
306+
296307
// `preceding' is everything before the '/'; 'lede' is the initial part
297308
// before any whitespace; and `intervening' is any whitespace.
298309
String preceding = capture.substring(0, capture.length() - 1);
@@ -452,12 +463,19 @@ public void interpop() {
452463
* {@code nendbrace}.
453464
* @return true if the interpolation state should end
454465
*/
455-
public boolean maybeEndInterpolation(String capture) {
466+
public boolean maybeEndInterpolation(String capture) throws IOException {
456467
if (nendbrace <= 0) {
457468
return false;
458469
}
459470
if (capture.startsWith("}")) {
460471
if (--nendbrace <= 0) {
472+
int rem = capture.length() - 1;
473+
String opener = capture.substring(0, 1);
474+
lexer.popHelper();
475+
lexer.yypop();
476+
lexer.disjointSpan(HtmlConsts.STRING_CLASS);
477+
lexer.offerNonword(opener);
478+
if (rem > 0) lexer.yypushback(rem);
461479
return true;
462480
}
463481
} else if (capture.startsWith("{")) {

src/org/opensolaris/opengrok/analysis/ruby/RubyProductions.lexh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,9 @@ Here_EOF3 = [\`][^\r\n\`]*[\`]
324324

325325
[\{\}] {
326326
String capture = yytext();
327-
if (h.maybeEndInterpolation(capture)) {
328-
popHelper();
329-
yypop();
330-
disjointSpan(HtmlConsts.STRING_CLASS);
327+
if (!h.maybeEndInterpolation(capture)) {
328+
offerNonword(capture);
331329
}
332-
offerNonword(capture);
333330
}
334331
}
335332

src/org/opensolaris/opengrok/analysis/ruby/RubySymbolTokenizer.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ import org.opensolaris.opengrok.web.Util;
133133
h = getNewHelper();
134134
}
135135

136-
protected void popHelper() {
136+
public void popHelper() {
137137
h = helpers.pop();
138138
}
139139

src/org/opensolaris/opengrok/analysis/ruby/RubyXref.lex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ import org.opensolaris.opengrok.web.Util;
121121
h = getNewHelper();
122122
}
123123

124-
protected void popHelper() {
124+
public void popHelper() {
125125
h = helpers.pop();
126126
}
127127

test/org/opensolaris/opengrok/analysis/ruby/RubyXrefTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.io.InputStreamReader;
3232
import java.io.OutputStream;
3333
import java.io.PrintStream;
34+
import java.io.StringReader;
3435
import java.io.StringWriter;
3536
import java.io.Writer;
3637
import org.junit.Test;
@@ -71,6 +72,26 @@ public void sampleTest() throws IOException {
7172
assertLinesEqual("Ruby xref", estr, ostr);
7273
}
7374

75+
@Test
76+
public void colonQuoteAfterInterpolation() throws IOException {
77+
final String RUBY_COLON_QUOTE =
78+
"\"from #{logfn}:\"\n";
79+
RubyXref xref = new RubyXref(new StringReader(RUBY_COLON_QUOTE));
80+
81+
StringWriter out = new StringWriter();
82+
xref.write(out);
83+
String xout = out.toString();
84+
85+
final String xexpected = "<a class=\"l\" name=\"1\" href=\"#1\">1</a>"
86+
+ "<span class=\"s\">&quot;from #{</span>"
87+
+ "<a href=\"/source/s?defs=logfn\" "
88+
+ "class=\"intelliWindow-symbol\" "
89+
+ "data-definition-place=\"undefined-in-file\">logfn</a>"
90+
+ "<span class=\"s\">}:&quot;</span>\n" +
91+
"<a class=\"l\" name=\"2\" href=\"#2\">2</a>\n";
92+
assertLinesEqual("Ruby colon-quote", xexpected, xout);
93+
}
94+
7495
private void writeRubyXref(InputStream iss, PrintStream oss)
7596
throws IOException {
7697
oss.print(getHtmlBegin());

test/org/opensolaris/opengrok/analysis/ruby/ruby_xrefres.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,7 @@
183183
<a class="l" name="175" href="#175">175</a><b>end</b>
184184
<a class="l" name="176" href="#176">176</a><b>print</b> <span class="s">&quot;\n&quot;</span>
185185
<a class="l" name="177" href="#177">177</a><b>print</b> <span class="s">&apos;<a href="http://example.com">http://example.com</a>&apos;</span>
186-
<a class="l" name="178" href="#178">178</a></body>
186+
<a class="l" name="178" href="#178">178</a><b>puts</b> <span class="s">&quot;Last #{</span><a href="/source/s?defs=log_lines" class="intelliWindow-symbol" data-definition-place="undefined-in-file">log_lines</a><span class="s">} lines from #{</span><a href="/source/s?defs=logfn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">logfn</a><span class="s">}:&quot;</span>
187+
<a class="l" name="179" href="#179">179</a><b>print</b> <span class="s">&quot;\n&quot;</span>
188+
<a class="hl" name="180" href="#180">180</a></body>
187189
</html>

test/org/opensolaris/opengrok/analysis/ruby/sample.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,5 @@ def right
175175
end
176176
print "\n"
177177
print 'http://example.com'
178+
puts "Last #{log_lines} lines from #{logfn}:"
179+
print "\n"

test/org/opensolaris/opengrok/analysis/ruby/samplesymbols.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,5 @@ over?
184184
STDIN
185185
bd
186186
reset
187+
log_lines # 177:puts "Last #{log_lines} lines from #{logfn}:"
188+
logfn

0 commit comments

Comments
 (0)