Skip to content

Commit

Permalink
Horrific fix for global and ivar characters which are not interpolato…
Browse files Browse the repository at this point in the history
…rs fix. Cleanup next fix
  • Loading branch information
enebo committed Oct 29, 2014
1 parent ce10121 commit c11cb6e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
15 changes: 14 additions & 1 deletion core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Expand Up @@ -1637,7 +1637,20 @@ private int dollar() throws IOException {
return identifierToken(Tokens.tGVAR, tokenBuffer.toString().intern());
}
}


// FIXME: I added number gvars here and they did not.
public boolean isGlobalCharPunct(int c) {
switch (c) {
case '_': case '~': case '*': case '$': case '?': case '!': case '@':
case '/': case '\\': case ';': case ',': case '.': case '=': case ':':
case '<': case '>': case '\"': case '-': case '&': case '`': case '\'':
case '+': case '1': case '2': case '3': case '4': case '5': case '6':
case '7': case '8': case '9': case '0':
return true;
}
return isIdentifierChar(c);
}

private int dot() throws IOException {
int c;

Expand Down
58 changes: 53 additions & 5 deletions core/src/main/java/org/jruby/lexer/yacc/StringTerm.java
Expand Up @@ -109,11 +109,59 @@ public int parseString(RubyLexer lexer, LexerSource src) throws IOException {
if ((flags & RubyLexer.STR_FUNC_EXPAND) != 0 && c == '#') {
c = src.read();
switch (c) {
case '$':
case '@':
src.unread(c);
lexer.setValue("#" + c);
return Tokens.tSTRING_DVAR;
case '$': {
int c2 = src.read();

if (c2 == '-') {
int c3 = src.read();

if (c3 == RubyLexer.EOF) return RubyLexer.EOF;

if (Character.isAlphabetic(c3) || c3 == '_') {
src.unread(c3);
src.unread(c2);
src.unread(c);
lexer.setValue("#" + c2);
return Tokens.tSTRING_DVAR;
}
} else if (lexer.isGlobalCharPunct(c2)) {
lexer.setValue("#" + c2);
src.unread(c2);
src.unread(c);
return Tokens.tSTRING_DVAR;
} if (Character.isAlphabetic(c2) || c2 == '_') {
src.unread(c2);
src.unread(c);
lexer.setValue("#" + c2);
return Tokens.tSTRING_DVAR;
}
break;
}
case '@': {
int c2 = src.read();

if (c2 == '@') {
int c3 = src.read();

if (c3 == RubyLexer.EOF) return RubyLexer.EOF;

lexer.setValue("#" + c2);
src.unread(c3);
src.unread(c2);
src.unread(c);

return Tokens.tSTRING_DVAR;
}

if (Character.isAlphabetic(c2) || c2 == '_') {
src.unread(c2);
src.unread(c);
lexer.setValue("#" + c2);
return Tokens.tSTRING_DVAR;
}
break;

}
case '{':
lexer.setValue("#" + c);
return Tokens.tSTRING_DBEG;
Expand Down

0 comments on commit c11cb6e

Please sign in to comment.