Skip to content

Commit

Permalink
Showing 2 changed files with 28 additions and 11 deletions.
38 changes: 28 additions & 10 deletions core/src/main/java/org/jruby/ext/ripper/RipperLexer.java
Original file line number Diff line number Diff line change
@@ -155,11 +155,14 @@ public boolean isVerbose() {
}

public void warn(String message) {
throw new UnsupportedOperationException("Not supported yet.");
parser.dispatch("warn", getRuntime().newString(message));
}

public void warning(String message) {
throw new UnsupportedOperationException("Not supported yet.");

public void warning(String fmt) {
parser.dispatch("warning", getRuntime().newString(fmt));
}
public void warning(String fmt, String arg) {
parser.dispatch("warning", getRuntime().newString(fmt), getRuntime().newString(arg));
}

public enum Keyword {
@@ -302,7 +305,8 @@ public RipperLexer(RipperParserBase parser, LexerSource src) {
commandStart = true;
current_enc = src.getEncoding();
}


int last_cr_line;
protected int tokp = 0; // Where last token started
protected ByteList lexb = null;
protected int lex_p = 0; // Where current position is in current line
@@ -319,7 +323,8 @@ public RipperLexer(RipperParserBase parser, LexerSource src) {
private int ruby_sourceline = 0;
private int heredoc_end = 0;
private int line_count = 0;

private boolean tokenSeen = false;

/**
* Has lexing started yet?
*/
@@ -391,9 +396,15 @@ public int nextc() {

int c = p(lex_p);
lex_p++;
if (c == '\r' && peek('\n')) {
lex_p++;
c = '\n';
if (c == '\r') {
if (peek('\n')) {
lex_p++;
c = '\n';
} else if (ruby_sourceline > last_cr_line) {
last_cr_line = ruby_sourceline;
warn("encountered \\\\r in middle of line, treated as a mere space");
c = ' ';
}
}

// System.out.println("C: " + (char) c + ", LEXP: " + lex_p + ", PEND: "+ lex_pend);
@@ -588,7 +599,10 @@ protected void magicCommentEncoding(ByteList encoding) {

@Override
protected void setCompileOptionFlag(String name, ByteList value) {

if (tokenSeen) {
warning("`%s' is ignored after any tokens", name);
return;
}
}

@Override
@@ -1341,6 +1355,7 @@ private int yylex() throws IOException {
int c;
boolean spaceSeen = false;
boolean commandState;
boolean tokenSeen = this.tokenSeen;

if (lex_strterm != null) {
int tok = lex_strterm.parseString(this, src);
@@ -1365,6 +1380,7 @@ private int yylex() throws IOException {

commandState = commandStart;
commandStart = false;
this.tokenSeen = true;

loop: for(;;) {
boolean fallthru = false;
@@ -1400,6 +1416,7 @@ private int yylex() throws IOException {
continue;
}
case '#': { /* it's a comment */
this.tokenSeen = tokenSeen;
if (!parseMagicComment(getRuntime(), lexb.makeShared(lex_p, lex_pend - lex_p))) {
if (comment_at_top()) set_file_encoding(lex_p, lex_pend);
}
@@ -1410,6 +1427,7 @@ private int yylex() throws IOException {
}
/* fall through */
case '\n':
this.tokenSeen = tokenSeen;
switch (lex_state) {
case EXPR_BEG:
case EXPR_FNAME:
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Original file line number Diff line number Diff line change
@@ -395,7 +395,6 @@ public final void reset() {
private boolean __end__seen = false;
protected boolean eofp = false;
private boolean has_shebang = false;
protected ByteList delayed = null;
private int ruby_sourceline = 0;
private int heredoc_end = 0;
private int line_count = 0;

0 comments on commit 271144b

Please sign in to comment.