Skip to content

Commit

Permalink
Showing 6 changed files with 3,954 additions and 3,858 deletions.
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Original file line number Diff line number Diff line change
@@ -1941,13 +1941,12 @@ private int identifier(int c, boolean commandState) throws IOException {
String tempVal = createTokenString();

if (isLabelPossible(commandState)) {
int c2 = nextc();
if (c2 == ':' && !peek(':')) {
if (isLabelSuffix()) {
setState(LexState.EXPR_LABELARG);
nextc();
yaccValue = tempVal.intern();
return Tokens.tLABEL;
}
pushback(c2);
}

if (lex_state != LexState.EXPR_DOT) {
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/lexer/yacc/StackState.java
Original file line number Diff line number Diff line change
@@ -43,6 +43,10 @@ public void reset(long backup) {
stack = backup;
}

public long getStack() {
return stack;
}

// PUSH(1)
public long begin() {
long old = stack;
1,460 changes: 745 additions & 715 deletions core/src/main/java/org/jruby/parser/RubyParser.java

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Original file line number Diff line number Diff line change
@@ -1331,21 +1331,29 @@ primary : literal
| tFID {
$$ = support.new_fcall($1);
}
| kBEGIN bodystmt kEND {
$$ = new BeginNode($1, $2 == null ? NilImplicitNode.NIL : $2);
| kBEGIN {
$$ = lexer.getCmdArgumentState().getStack();
lexer.getCmdArgumentState().reset();
} bodystmt kEND {
lexer.getCmdArgumentState().reset($<Long>2.longValue());
$$ = new BeginNode($1, $3 == null ? NilImplicitNode.NIL : $3);
}
| tLPAREN_ARG {
lexer.setState(LexState.EXPR_ENDARG);
} rparen {
$$ = null; //FIXME: Should be implicit nil?
}
| tLPAREN_ARG expr {
| tLPAREN_ARG {
$$ = lexer.getCmdArgumentState().getStack();
lexer.getCmdArgumentState().reset();
} expr {
lexer.setState(LexState.EXPR_ENDARG);
} rparen {
lexer.getCmdArgumentState().reset($<Long>2.longValue());
if (Options.PARSER_WARN_GROUPED_EXPRESSIONS.load()) {
support.warning(ID.GROUPED_EXPRESSION, $1, "(...) interpreted as grouped expression");
}
$$ = $2;
$$ = $3;
}
| tLPAREN compstmt tRPAREN {
if ($2 != null) {
@@ -2011,7 +2019,9 @@ string_content : tSTRING_CONTENT {
$$ = lexer.getStrTerm();
lexer.setStrTerm(null);
lexer.getConditionState().stop();
lexer.getCmdArgumentState().stop();
} {
$$ = lexer.getCmdArgumentState().getStack();
lexer.getCmdArgumentState().reset();
} {
$$ = lexer.getState();
lexer.setState(LexState.EXPR_BEG);
@@ -2020,12 +2030,12 @@ string_content : tSTRING_CONTENT {
lexer.setBraceNest(0);
} compstmt tSTRING_DEND {
lexer.getConditionState().restart();
lexer.getCmdArgumentState().restart();
lexer.setStrTerm($<StrTerm>2);
lexer.setState($<LexState>3);
lexer.setBraceNest($<Integer>4);
lexer.getCmdArgumentState().reset($<Long>3.longValue());
lexer.setState($<LexState>4);
lexer.setBraceNest($<Integer>5);

$$ = support.newEvStrNode(support.getPosition($5), $5);
$$ = support.newEvStrNode(support.getPosition($6), $6);
}

string_dvar : tGVAR {
6,278 changes: 3,147 additions & 3,131 deletions core/src/main/java/org/jruby/parser/YyTables.java

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions spec/regression/parser_regressions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'rspec'

describe "The Parsing experience" do
it "parses a cond which used to get confused as a tLABEL" do
cond = true
x = '('
a = cond ? x + ')': ''
a.should eq('()')
end

it "parse the stabby lambda even if args params separated by space" do
a = -> () { 1 }
a.call.should eq(1)
end

it "parses a jumbled mess of nestng" do
self.class.send(:define_method, :foo) { |a| a[:key].call[:key] }
var = 1
res = foo key: (proc do
{
key: "#{var}#{var}",
other_key: proc do
end
}
end)

res.should eq("11")
end

it "parsers a block do inside of a call arg list" do
self.class.send(:define_method, :foo) { |a| a }
res = foo (10.times.to_a.map do |i|
7 + i
end)
res.should eq([7,8,9,10,11,12,13,14,15,16])
end
end

1 comment on commit 8f4ec6b

@olleolleolle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/ YAY! Great job.

Please sign in to comment.