Skip to content

Commit

Permalink
Fixes #4315. 2.3 Syntax Failure: %s does not work in alias or undef
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Nov 17, 2016
1 parent f755629 commit c49d1f4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/ext/ripper/RipperLexer.java
Expand Up @@ -172,7 +172,7 @@ public enum Keyword {
IF ("if", Tokens.kIF, Tokens.kIF_MOD, EXPR_BEG),
DEFINED_P ("defined?", Tokens.kDEFINED, Tokens.kDEFINED, EXPR_ARG),
SUPER ("super", Tokens.kSUPER, Tokens.kSUPER, EXPR_ARG),
UNDEF ("undef", Tokens.kUNDEF, Tokens.kUNDEF, EXPR_FNAME),
UNDEF ("undef", Tokens.kUNDEF, Tokens.kUNDEF, EXPR_FNAME|EXPR_FITEM),
BREAK ("break", Tokens.kBREAK, Tokens.kBREAK, EXPR_MID),
IN ("in", Tokens.kIN, Tokens.kIN, EXPR_BEG),
DO ("do", Tokens.kDO, Tokens.kDO, EXPR_BEG),
Expand All @@ -191,7 +191,7 @@ public enum Keyword {
LEND ("END", Tokens.klEND, Tokens.klEND, EXPR_END),
LBEGIN ("BEGIN", Tokens.klBEGIN, Tokens.klBEGIN, EXPR_END),
WHILE ("while", Tokens.kWHILE, Tokens.kWHILE_MOD, EXPR_BEG),
ALIAS ("alias", Tokens.kALIAS, Tokens.kALIAS, EXPR_FNAME),
ALIAS ("alias", Tokens.kALIAS, Tokens.kALIAS, EXPR_FNAME|EXPR_FITEM),
__ENCODING__("__ENCODING__", Tokens.k__ENCODING__, Tokens.k__ENCODING__, EXPR_END);

public final String name;
Expand Down Expand Up @@ -524,7 +524,7 @@ private int parseQuote(int c) throws IOException {

case 's':
lex_strterm = new StringTerm(str_ssym, begin, end);
setState(EXPR_FNAME);
setState(EXPR_FNAME|EXPR_FITEM);
return Tokens.tSYMBEG;

case 'I':
Expand Down Expand Up @@ -1850,8 +1850,8 @@ private int percent(boolean spaceSeen) throws IOException {
setState(EXPR_BEG);
return Tokens.tOP_ASGN;
}
if (isSpaceArg(c, spaceSeen)) return parseQuote(c);

if (isSpaceArg(c, spaceSeen) || isLexState(lex_state, EXPR_FITEM)) return parseQuote(c);

setState(isAfterOperator() ? EXPR_ARG : EXPR_BEG);

Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/org/jruby/ext/ripper/RipperParser.java
Expand Up @@ -36,6 +36,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import static org.jruby.lexer.LexingCommon.EXPR_BEG;
import static org.jruby.lexer.LexingCommon.EXPR_FITEM;
import static org.jruby.lexer.LexingCommon.EXPR_FNAME;
import static org.jruby.lexer.LexingCommon.EXPR_ENDFN;
import static org.jruby.lexer.LexingCommon.EXPR_ENDARG;
Expand All @@ -46,7 +47,7 @@ public class RipperParser extends RipperParserBase {
public RipperParser(ThreadContext context, IRubyObject ripper, LexerSource source) {
super(context, ripper, source);
}
// line 50 "-"
// line 51 "-"
// %token constants
public static final int kCLASS = 257;
public static final int kMODULE = 258;
Expand Down Expand Up @@ -1720,7 +1721,7 @@ public Object yyparse (RipperLexer yyLex) throws java.io.IOException {
};
states[20] = new RipperParserState() {
@Override public Object execute(RipperParser p, Object yyVal, Object[] yyVals, int yyTop) {
p.setState(EXPR_FNAME);
p.setState(EXPR_FNAME|EXPR_FITEM);
return yyVal;
}
};
Expand Down Expand Up @@ -2447,7 +2448,7 @@ public Object yyparse (RipperLexer yyLex) throws java.io.IOException {
};
states[144] = new RipperParserState() {
@Override public Object execute(RipperParser p, Object yyVal, Object[] yyVals, int yyTop) {
p.setState(EXPR_FNAME);
p.setState(EXPR_FNAME|EXPR_FITEM);
return yyVal;
}
};
Expand Down Expand Up @@ -4736,6 +4737,6 @@ public Object yyparse (RipperLexer yyLex) throws java.io.IOException {
}
};
}
// line 2115 "RipperParser.y"
// line 2116 "RipperParser.y"
}
// line 9497 "-"
// line 9498 "-"
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/ext/ripper/RipperParser.y
Expand Up @@ -33,6 +33,7 @@ import org.jruby.lexer.LexerSource;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import static org.jruby.lexer.LexingCommon.EXPR_BEG;
import static org.jruby.lexer.LexingCommon.EXPR_FITEM;
import static org.jruby.lexer.LexingCommon.EXPR_FNAME;
import static org.jruby.lexer.LexingCommon.EXPR_ENDFN;
import static org.jruby.lexer.LexingCommon.EXPR_ENDARG;
Expand Down Expand Up @@ -279,7 +280,7 @@ stmt_or_begin : stmt {
}

stmt : kALIAS fitem {
p.setState(EXPR_FNAME);
p.setState(EXPR_FNAME|EXPR_FITEM);
} fitem {
$$ = p.dispatch("on_alias", $2, $4);
}
Expand Down Expand Up @@ -728,7 +729,7 @@ undef_list : fitem {
$$ = p.new_array($1);
}
| undef_list ',' {
p.setState(EXPR_FNAME);
p.setState(EXPR_FNAME|EXPR_FITEM);
} fitem {
$$ = $1.append($4);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/lexer/LexingCommon.java
Expand Up @@ -35,6 +35,7 @@ public abstract class LexingCommon {
public static final int EXPR_CLASS = 1<<9;
public static final int EXPR_LABEL = 1<<10;
public static final int EXPR_LABELED = 1<<11;
public static final int EXPR_FITEM = 1<<12;
public static final int EXPR_VALUE = EXPR_BEG;
public static final int EXPR_BEG_ANY = EXPR_BEG | EXPR_MID | EXPR_CLASS;
public static final int EXPR_ARG_ANY = EXPR_ARG | EXPR_CMDARG;
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Expand Up @@ -159,7 +159,7 @@ public enum Keyword {
IF ("if", Tokens.kIF, Tokens.kIF_MOD, EXPR_BEG),
DEFINED_P ("defined?", Tokens.kDEFINED, Tokens.kDEFINED, EXPR_ARG),
SUPER ("super", Tokens.kSUPER, Tokens.kSUPER, EXPR_ARG),
UNDEF ("undef", Tokens.kUNDEF, Tokens.kUNDEF, EXPR_FNAME),
UNDEF ("undef", Tokens.kUNDEF, Tokens.kUNDEF, EXPR_FNAME|EXPR_FITEM),
BREAK ("break", Tokens.kBREAK, Tokens.kBREAK, EXPR_MID),
IN ("in", Tokens.kIN, Tokens.kIN, EXPR_BEG),
DO ("do", Tokens.kDO, Tokens.kDO, EXPR_BEG),
Expand All @@ -178,7 +178,7 @@ public enum Keyword {
LEND ("END", Tokens.klEND, Tokens.klEND, EXPR_END),
LBEGIN ("BEGIN", Tokens.klBEGIN, Tokens.klBEGIN, EXPR_END),
WHILE ("while", Tokens.kWHILE, Tokens.kWHILE_MOD, EXPR_BEG),
ALIAS ("alias", Tokens.kALIAS, Tokens.kALIAS, EXPR_FNAME),
ALIAS ("alias", Tokens.kALIAS, Tokens.kALIAS, EXPR_FNAME|EXPR_FITEM),
__ENCODING__("__ENCODING__", Tokens.k__ENCODING__, Tokens.k__ENCODING__, EXPR_END);

public final String name;
Expand Down Expand Up @@ -560,7 +560,7 @@ private int parseQuote(int c) throws IOException {

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

Expand Down Expand Up @@ -1718,7 +1718,7 @@ private int percent(boolean spaceSeen) throws IOException {
return Tokens.tOP_ASGN;
}

if (isSpaceArg(c, spaceSeen)) return parseQuote(c);
if (isSpaceArg(c, spaceSeen) || isLexState(lex_state, EXPR_FITEM)) return parseQuote(c);

setState(isAfterOperator() ? EXPR_ARG : EXPR_BEG);

Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/org/jruby/parser/RubyParser.java
Expand Up @@ -126,6 +126,7 @@
import org.jruby.util.cli.Options;
import org.jruby.util.StringSupport;
import static org.jruby.lexer.LexingCommon.EXPR_BEG;
import static org.jruby.lexer.LexingCommon.EXPR_FITEM;
import static org.jruby.lexer.LexingCommon.EXPR_FNAME;
import static org.jruby.lexer.LexingCommon.EXPR_ENDFN;
import static org.jruby.lexer.LexingCommon.EXPR_ENDARG;
Expand Down Expand Up @@ -159,7 +160,7 @@ public void setWarnings(IRubyWarnings warnings) {
support.setWarnings(warnings);
lexer.setWarnings(warnings);
}
// line 163 "-"
// line 164 "-"
// %token constants
public static final int kCLASS = 257;
public static final int kMODULE = 258;
Expand Down Expand Up @@ -1842,7 +1843,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[20] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
lexer.setState(EXPR_FNAME);
lexer.setState(EXPR_FNAME|EXPR_FITEM);
return yyVal;
}
};
Expand Down Expand Up @@ -2590,7 +2591,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[144] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
lexer.setState(EXPR_FNAME);
lexer.setState(EXPR_FNAME|EXPR_FITEM);
return yyVal;
}
};
Expand Down Expand Up @@ -5346,7 +5347,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
}
};
}
// line 2574 "RubyParser.y"
// line 2575 "RubyParser.y"

/** The parse method use an lexer stream and parse it to an AST node
* structure
Expand All @@ -5361,4 +5362,4 @@ public RubyParserResult parse(ParserConfiguration configuration) throws IOExcept
return support.getResult();
}
}
// line 10130 "-"
// line 10131 "-"
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Expand Up @@ -123,6 +123,7 @@ import org.jruby.util.KeyValuePair;
import org.jruby.util.cli.Options;
import org.jruby.util.StringSupport;
import static org.jruby.lexer.LexingCommon.EXPR_BEG;
import static org.jruby.lexer.LexingCommon.EXPR_FITEM;
import static org.jruby.lexer.LexingCommon.EXPR_FNAME;
import static org.jruby.lexer.LexingCommon.EXPR_ENDFN;
import static org.jruby.lexer.LexingCommon.EXPR_ENDARG;
Expand Down Expand Up @@ -411,7 +412,7 @@ stmt_or_begin : stmt {
}

stmt : kALIAS fitem {
lexer.setState(EXPR_FNAME);
lexer.setState(EXPR_FNAME|EXPR_FITEM);
} fitem {
$$ = support.newAlias($1, $2, $4);
}
Expand Down Expand Up @@ -871,7 +872,7 @@ undef_list : fitem {
$$ = support.newUndef($1.getPosition(), $1);
}
| undef_list ',' {
lexer.setState(EXPR_FNAME);
lexer.setState(EXPR_FNAME|EXPR_FITEM);
} fitem {
$$ = support.appendToBlock($1, support.newUndef($1.getPosition(), $4));
}
Expand Down
3 changes: 1 addition & 2 deletions test/mri/excludes/TestSyntax.rb
@@ -1,5 +1,4 @@
exclude :test__END___cr, "needs investigation"
exclude :test_alias_symbol, "needs investigation #4308"
exclude :test_constant_reassignment_nested, "needs investigation"
exclude :test_constant_reassignment_toplevel, "needs investigation"
exclude :test_dedented_heredoc_with_blank_more_indented_line, "needs investigation #4308"
Expand All @@ -17,4 +16,4 @@
exclude :test_syntax_lib, "needs investigation #4308"
exclude :test_syntax_sample, "needs investigation #4308"
exclude :test_syntax_test, "needs investigation #4308"
exclude :test_undef_symbol, "needs investigation #4308"

0 comments on commit c49d1f4

Please sign in to comment.