Skip to content

Commit f98a847

Browse files
committed
Fix to test for Ruby end-interpolation at a few more spots
1 parent fa7c0e4 commit f98a847

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
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

0 commit comments

Comments
 (0)