Skip to content

Commit

Permalink
Showing 4 changed files with 32 additions and 19 deletions.
8 changes: 8 additions & 0 deletions core/src/main/java/org/jruby/lexer/LexingCommon.java
Original file line number Diff line number Diff line change
@@ -95,6 +95,14 @@ protected boolean comment_at_top() {
return true;
}

public int getRubySourceline() {
return ruby_sourceline;
}

public void setRubySourceline(int line) {
ruby_sourceline = line;
}

public ByteList createTokenByteList() {
return new ByteList(lexb.unsafeBytes(), lexb.begin() + tokp, lex_p - tokp, getEncoding(), false);
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/lexer/yacc/HeredocTerm.java
Original file line number Diff line number Diff line change
@@ -167,7 +167,7 @@ public int parseString(RubyLexer lexer) throws java.io.IOException {
Encoding enc[] = new Encoding[1];
enc[0] = lexer.getEncoding();

if ((c = new StringTerm(flags, '\0', '\n').parseStringIntoBuffer(lexer, tok, enc)) == EOF) {
if ((c = new StringTerm(flags, '\0', '\n', lexer.getRubySourceline()).parseStringIntoBuffer(lexer, tok, enc)) == EOF) {
if (lexer.eofp) return error(lexer, len, str, eos);
return restore(lexer);
}
@@ -189,7 +189,7 @@ public int parseString(RubyLexer lexer) throws java.io.IOException {
}

lexer.heredoc_restore(this);
lexer.setStrTerm(new StringTerm(-1, '\0', '\0'));
lexer.setStrTerm(new StringTerm(-1, '\0', '\0', lexer.getRubySourceline()));
lexer.setValue(lexer.createStr(str, 0));
return Tokens.tSTRING_CONTENT;
}
32 changes: 16 additions & 16 deletions core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Original file line number Diff line number Diff line change
@@ -534,53 +534,53 @@ private int parseQuote(int c) throws IOException {

switch (c) {
case 'Q':
lex_strterm = new StringTerm(str_dquote, begin ,end);
lex_strterm = new StringTerm(str_dquote, begin ,end, ruby_sourceline);
yaccValue = "%"+ (shortHand ? (""+end) : ("" + c + begin));
return Tokens.tSTRING_BEG;

case 'q':
lex_strterm = new StringTerm(str_squote, begin, end);
lex_strterm = new StringTerm(str_squote, begin, end, ruby_sourceline);
yaccValue = "%"+c+begin;
return Tokens.tSTRING_BEG;

case 'W':
lex_strterm = new StringTerm(str_dquote | STR_FUNC_QWORDS, begin, end);
lex_strterm = new StringTerm(str_dquote | STR_FUNC_QWORDS, begin, end, ruby_sourceline);
do {c = nextc();} while (Character.isWhitespace(c));
pushback(c);
yaccValue = "%"+c+begin;
return Tokens.tWORDS_BEG;

case 'w':
lex_strterm = new StringTerm(/* str_squote | */ STR_FUNC_QWORDS, begin, end);
lex_strterm = new StringTerm(/* str_squote | */ STR_FUNC_QWORDS, begin, end, ruby_sourceline);
do {c = nextc();} while (Character.isWhitespace(c));
pushback(c);
yaccValue = "%"+c+begin;
return Tokens.tQWORDS_BEG;

case 'x':
lex_strterm = new StringTerm(str_xquote, begin, end);
lex_strterm = new StringTerm(str_xquote, begin, end, ruby_sourceline);
yaccValue = "%"+c+begin;
return Tokens.tXSTRING_BEG;

case 'r':
lex_strterm = new StringTerm(str_regexp, begin, end);
lex_strterm = new StringTerm(str_regexp, begin, end, ruby_sourceline);
yaccValue = "%"+c+begin;
return Tokens.tREGEXP_BEG;

case 's':
lex_strterm = new StringTerm(str_ssym, begin, end);
lex_strterm = new StringTerm(str_ssym, begin, end, ruby_sourceline);
setState(EXPR_FNAME|EXPR_FITEM);
yaccValue = "%"+c+begin;
return Tokens.tSYMBEG;

case 'I':
lex_strterm = new StringTerm(str_dquote | STR_FUNC_QWORDS, begin, end);
lex_strterm = new StringTerm(str_dquote | STR_FUNC_QWORDS, begin, end, ruby_sourceline);
do {c = nextc();} while (Character.isWhitespace(c));
pushback(c);
yaccValue = "%" + c + begin;
return Tokens.tSYMBOLS_BEG;
case 'i':
lex_strterm = new StringTerm(/* str_squote | */STR_FUNC_QWORDS, begin, end);
lex_strterm = new StringTerm(/* str_squote | */STR_FUNC_QWORDS, begin, end, ruby_sourceline);
do {c = nextc();} while (Character.isWhitespace(c));
pushback(c);
yaccValue = "%" + c + begin;
@@ -1164,7 +1164,7 @@ private int backtick(boolean commandState) throws IOException {
return Tokens.tBACK_REF2;
}

lex_strterm = new StringTerm(str_xquote, '\0', '`');
lex_strterm = new StringTerm(str_xquote, '\0', '`', ruby_sourceline);
return Tokens.tXSTRING_BEG;
}

@@ -1237,10 +1237,10 @@ private int colon(boolean spaceSeen) throws IOException {

switch (c) {
case '\'':
lex_strterm = new StringTerm(str_ssym, '\0', c);
lex_strterm = new StringTerm(str_ssym, '\0', c, ruby_sourceline);
break;
case '"':
lex_strterm = new StringTerm(str_dsym, '\0', c);
lex_strterm = new StringTerm(str_dsym, '\0', c, ruby_sourceline);
break;
default:
pushback(c);
@@ -1412,7 +1412,7 @@ private int dot() throws IOException {

private int doubleQuote(boolean commandState) throws IOException {
int label = isLabelPossible(commandState) ? str_label : 0;
lex_strterm = new StringTerm(str_dquote|label, '\0', '"');
lex_strterm = new StringTerm(str_dquote|label, '\0', '"', ruby_sourceline);
yaccValue = "\"";

return Tokens.tSTRING_BEG;
@@ -1918,15 +1918,15 @@ private int rightParen() {

private int singleQuote(boolean commandState) throws IOException {
int label = isLabelPossible(commandState) ? str_label : 0;
lex_strterm = new StringTerm(str_squote|label, '\0', '\'');
lex_strterm = new StringTerm(str_squote|label, '\0', '\'', ruby_sourceline);
yaccValue = "'";

return Tokens.tSTRING_BEG;
}

private int slash(boolean spaceSeen) throws IOException {
if (isBEG()) {
lex_strterm = new StringTerm(str_regexp, '\0', '/');
lex_strterm = new StringTerm(str_regexp, '\0', '/', ruby_sourceline);
yaccValue = "/";
return Tokens.tREGEXP_BEG;
}
@@ -1941,7 +1941,7 @@ private int slash(boolean spaceSeen) throws IOException {
pushback(c);
if (isSpaceArg(c, spaceSeen)) {
arg_ambiguous();
lex_strterm = new StringTerm(str_regexp, '\0', '/');
lex_strterm = new StringTerm(str_regexp, '\0', '/', ruby_sourceline);
yaccValue = "/";
return Tokens.tREGEXP_BEG;
}
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/lexer/yacc/StringTerm.java
Original file line number Diff line number Diff line change
@@ -48,14 +48,18 @@ public class StringTerm extends StrTerm {
// End of string (], ), }, >, ', ", \0)
private final char end;

// Syntax errors (eof) will occur at this position.
private final int startLine;

// How many strings are nested in the current string term
private int nest;

public StringTerm(int flags, int begin, int end) {
public StringTerm(int flags, int begin, int end, int startLine) {
this.flags = flags;
this.begin = (char) begin;
this.end = (char) end;
this.nest = 0;
this.startLine = startLine;
}

public int getFlags() {
@@ -196,6 +200,7 @@ public int parseString(RubyLexer lexer) throws IOException {
enc[0] = lexer.getEncoding();

if (parseStringIntoBuffer(lexer, buffer, enc) == EOF) {
lexer.setRubySourceline(startLine);
lexer.compile_error("unterminated " + ((flags & STR_FUNC_REGEXP) != 0 ? "regexp" : "string") + " meets end of file");
}

0 comments on commit 2721667

Please sign in to comment.