Skip to content

Commit 3545de8

Browse files
committed
[GR-45043] Integrate YARP parser [Part 3]
PullRequest: truffleruby/3907
2 parents 3875f52 + 71dbf65 commit 3545de8

File tree

109 files changed

+2515
-400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2515
-400
lines changed

CHANGELOG.md

Lines changed: 41 additions & 41 deletions
Large diffs are not rendered by default.

spec/ruby/language/case_spec.rb

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -329,49 +329,6 @@ def bar; @calls << :bar; end
329329
100
330330
end.should == 100
331331
end
332-
end
333-
334-
describe "The 'case'-construct with no target expression" do
335-
it "evaluates the body of the first clause when at least one of its condition expressions is true" do
336-
case
337-
when true, false; 'foo'
338-
end.should == 'foo'
339-
end
340-
341-
it "evaluates the body of the first when clause that is not false/nil" do
342-
case
343-
when false; 'foo'
344-
when 2; 'bar'
345-
when 1 == 1; 'baz'
346-
end.should == 'bar'
347-
348-
case
349-
when false; 'foo'
350-
when nil; 'foo'
351-
when 1 == 1; 'bar'
352-
end.should == 'bar'
353-
end
354-
355-
it "evaluates the body of the else clause if all when clauses are false/nil" do
356-
case
357-
when false; 'foo'
358-
when nil; 'foo'
359-
when 1 == 2; 'bar'
360-
else 'baz'
361-
end.should == 'baz'
362-
end
363-
364-
it "evaluates multiple conditional expressions as a boolean disjunction" do
365-
case
366-
when true, false; 'foo'
367-
else 'bar'
368-
end.should == 'foo'
369-
370-
case
371-
when false, true; 'foo'
372-
else 'bar'
373-
end.should == 'foo'
374-
end
375332

376333
it "evaluates true as only 'true' when true is the first clause" do
377334
case 1
@@ -442,6 +399,49 @@ def ===(o)
442399
:called
443400
end.should == :called
444401
end
402+
end
403+
404+
describe "The 'case'-construct with no target expression" do
405+
it "evaluates the body of the first clause when at least one of its condition expressions is true" do
406+
case
407+
when true, false; 'foo'
408+
end.should == 'foo'
409+
end
410+
411+
it "evaluates the body of the first when clause that is not false/nil" do
412+
case
413+
when false; 'foo'
414+
when 2; 'bar'
415+
when 1 == 1; 'baz'
416+
end.should == 'bar'
417+
418+
case
419+
when false; 'foo'
420+
when nil; 'foo'
421+
when 1 == 1; 'bar'
422+
end.should == 'bar'
423+
end
424+
425+
it "evaluates the body of the else clause if all when clauses are false/nil" do
426+
case
427+
when false; 'foo'
428+
when nil; 'foo'
429+
when 1 == 2; 'bar'
430+
else 'baz'
431+
end.should == 'baz'
432+
end
433+
434+
it "evaluates multiple conditional expressions as a boolean disjunction" do
435+
case
436+
when true, false; 'foo'
437+
else 'bar'
438+
end.should == 'foo'
439+
440+
case
441+
when false, true; 'foo'
442+
else 'bar'
443+
end.should == 'foo'
444+
end
445445

446446
# Homogeneous cases are often optimized to avoid === using a jump table, and should be tested separately.
447447
# See https://github.com/jruby/jruby/issues/6440
@@ -451,4 +451,13 @@ def ===(o)
451451
when 2; 'bar'
452452
end.should == 'foo'
453453
end
454+
455+
it "expands arrays to lists of values" do
456+
case
457+
when *[false]
458+
"foo"
459+
when *[true]
460+
"bar"
461+
end.should == "bar"
462+
end
454463
end

spec/tags/truffle/parsing/parsing_tags.txt

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,7 @@ fails:Parsing a Block (Tail expression / with explicit return inside then branch
4747
fails:Parsing a Block (a block with empty body) case is parsed correctly
4848
fails:Parsing a Block (a block with not empty body) case is parsed correctly
4949
fails:Parsing a Block (a block without parameters) case is parsed correctly
50-
fails:Parsing a Break (break operator within a block) case is parsed correctly
51-
fails:Parsing a case expression (case expression with expression/value to match (case a when ... end)) case is parsed correctly
52-
fails:Parsing a case expression (case expression with expression to match and `else` branch (case a when ... else ... end)) case is parsed correctly
53-
fails:Parsing a case expression (case expression with expression to match and multiple values in a `when` branch (case a when a, b ... end)) case is parsed correctly
54-
fails:Parsing a case expression (case expression without expression to match (case when expr ... end)) case is parsed correctly
55-
fails:Parsing a case expression (case expression without expression to match and with `else` branch (case when expr ... else ... end)) case is parsed correctly
56-
fails:Parsing a case expression (case expression without expression to match and with multiple conditions in a `when` branch (case when a, b ... end)) case is parsed correctly
50+
fails:Parsing a Break (within a block) case is parsed correctly
5751
fails:Parsing a class << (reopen an object singleton class) case is parsed correctly
5852
fails:Parsing a Complex number (Complex literal `bri` (without real part) where b is Float is represented as `Complext.convert(0, Rational.convert(b*100, 100))` where 100 is some power of 10 to convert b to Integer) case is parsed correctly
5953
fails:Parsing a Complex number (Complex literal `bri` (without real part) where b is Integer is represented as `Complext.convert(0, Rational.convert(b, 1))`) case is parsed correctly
@@ -117,39 +111,12 @@ fails:Parsing a Method call (Arguments/with keyword arguments) case is parsed co
117111
fails:Parsing a Method call (Arguments/with positional argument and splat operator (a, *args)) case is parsed correctly
118112
fails:Parsing a Method call (Arguments/with splat operator (*args)) case is parsed correctly
119113
fails:Parsing a Method call (Arguments/with splat operator and positional arguments (*args, a)) case is parsed correctly
120-
fails:Parsing a Method call (Primitive is replaced with a node implementing this method) case is parsed correctly
121-
fails:Parsing a Method call (Special cases/method #!) case is parsed correctly
122-
fails:Parsing a Method call (Special cases/method #%) case is parsed correctly
123-
fails:Parsing a Method call (Special cases/method #&) case is parsed correctly
124-
fails:Parsing a Method call (Special cases/method #*) case is parsed correctly
125-
fails:Parsing a Method call (Special cases/method #+) case is parsed correctly
126-
fails:Parsing a Method call (Special cases/method #-) case is parsed correctly
127-
fails:Parsing a Method call (Special cases/method #-@) case is parsed correctly
128-
fails:Parsing a Method call (Special cases/method #<) case is parsed correctly
129-
fails:Parsing a Method call (Special cases/method #<<) case is parsed correctly
130-
fails:Parsing a Method call (Special cases/method #<=) case is parsed correctly
131-
fails:Parsing a Method call (Special cases/method #==) case is parsed correctly
132-
fails:Parsing a Method call (Special cases/method #===) case is parsed correctly
133-
fails:Parsing a Method call (Special cases/method #>) case is parsed correctly
134-
fails:Parsing a Method call (Special cases/method #>=) case is parsed correctly
135-
fails:Parsing a Method call (Special cases/method #>>) case is parsed correctly
136-
fails:Parsing a Method call (Special cases/method #[]) case is parsed correctly
137-
fails:Parsing a Method call (Special cases/method #[]=) case is parsed correctly
138-
fails:Parsing a Method call (Special cases/method #at (Array#at)) case is parsed correctly
139-
fails:Parsing a Method call (Special cases/method #bytesize) case is parsed correctly
140-
fails:Parsing a Method call (Special cases/method #dedup called on a String literal) case is parsed correctly
141-
fails:Parsing a Method call (Special cases/method #freeze) case is parsed correctly
142-
fails:Parsing a Method call (Special cases/method #is_a?) case is parsed correctly
143-
fails:Parsing a Method call (Special cases/method #kind_of?) case is parsed correctly
144114
fails:Parsing a Method call (Special cases/method #lambda (Kernel#lambda)) case is parsed correctly
145115
fails:Parsing a Method call (Special cases/method #lambda (not Kernel#lambda)) case is parsed correctly
146-
fails:Parsing a Method call (Special cases/method #nil?) case is parsed correctly
147-
fails:Parsing a Method call (Special cases/method #/) case is parsed correctly
148-
fails:Parsing a Method call (Special cases/method #|) case is parsed correctly
149-
fails:Parsing a Method call (Special cases/method #attr= (property assignment)) case is parsed correctly
150-
fails:Parsing a Method call (Method call with implicit receiver (`foo`)) case is parsed correctly
151-
fails:Parsing a Method call (With safe navigation operator (&.)) case is parsed correctly
152-
fails:Parsing a Method call (Without arguments and parentheses) case is parsed correctly
116+
fails:Parsing a Method call (super / in a method body with explicit arguments) case is parsed correctly
117+
fails:Parsing a Method call (super / in a method body without explicit arguments) case is parsed correctly
118+
fails:Parsing a Method call (super / outside a method body with explicit arguments) case is parsed correctly
119+
fails:Parsing a Method call (super / outside a method body without explicit arguments) case is parsed correctly
153120
fails:Parsing a &&= (Assign an attribute local variable (a.b &&= c)) case is parsed correctly
154121
fails:Parsing a &&= (Assign an referenced element (a[b] &&= c)) case is parsed correctly
155122
fails:Parsing a &&= (Assign an element referenced with multiple indexes (a[b, c, d] &&= e)) case is parsed correctly
@@ -160,11 +127,8 @@ fails:Parsing a &&= (Variable assignment/global variable ($a &&= b)) case is par
160127
fails:Parsing a &&= (Variable assignment/instance variable (@a &&= b)) case is parsed correctly
161128
fails:Parsing a &&= (Variable assignment/local variable (a &&= b)) case is parsed correctly
162129
fails:Parsing a Flip-flop operator (in a block) case is parsed correctly
163-
fails:Parsing a Flip-flop operator (in a class body) case is parsed correctly
164130
fails:Parsing a Flip-flop operator (in a lambda) case is parsed correctly
165131
fails:Parsing a Flip-flop operator (in a method) case is parsed correctly
166-
fails:Parsing a Flip-flop operator (in a module body) case is parsed correctly
167-
fails:Parsing a Flip-flop operator (Flop-flop operator - a range literal in boolean context) case is parsed correctly
168132
fails:Parsing a Match (=~ operator) case is parsed correctly
169133
fails:Parsing a Match (=~ operator/with Regexp literal as a RHS) case is parsed correctly
170134
fails:Parsing a Match (=~ operator/with Regexp literal as a LHS (without named capture groups)) case is parsed correctly

spec/truffle/parsing/fixtures/END.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ ast: |
4242
methodName = "at_exit"
4343
notEmptyKeywordsProfile = false
4444
notRuby2KeywordsHashProfile = false
45-
ruby2KeywordsHashProfile = false
4645
children:
4746
arguments = [
4847
BooleanLiteralNode

spec/truffle/parsing/fixtures/block/name/in_block.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ ast: |
8484
methodName = "proc"
8585
notEmptyKeywordsProfile = false
8686
notRuby2KeywordsHashProfile = false
87-
ruby2KeywordsHashProfile = false
8887
children:
8988
block =
9089
BlockDefinitionNode

spec/truffle/parsing/fixtures/block/name/in_method.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ ast: |
8888
methodName = "proc"
8989
notEmptyKeywordsProfile = false
9090
notRuby2KeywordsHashProfile = false
91-
ruby2KeywordsHashProfile = false
9291
children:
9392
block =
9493
BlockDefinitionNode

spec/truffle/parsing/fixtures/break/with_multiple_arguments.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
subject: "Break"
2-
description: "break operator with multiple arguments"
2+
description: "with multiple arguments"
33
focused_on_node: "org.truffleruby.language.control.BreakNode"
44
ruby: |
55
while true

spec/truffle/parsing/fixtures/break/with_argument.yaml renamed to spec/truffle/parsing/fixtures/break/with_single_argument.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
subject: "Break"
2-
description: "break operator with argument"
2+
description: "with single argument"
33
focused_on_node: "org.truffleruby.language.control.BreakNode"
44
ruby: |
55
while true

spec/truffle/parsing/fixtures/break/with_splat_operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
subject: "Break"
2-
description: "break operator with splat operator (break *a)"
2+
description: "with splat operator (break *a)"
33
focused_on_node: "org.truffleruby.language.control.BreakNode"
44
ruby: |
55
while true
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
subject: "Break"
2+
description: "with splat operator and following argument (break *a, b)"
3+
notes: >
4+
Arguments are represented with combination of:
5+
- ArrayConcatNode
6+
- SplatCastNodeGen
7+
- ArrayLiteralNode$UninitialisedArrayLiteralNode
8+
nodes
9+
yarp_specific: true # Simplified AST and replaced ArrayAppendOneNodeGen by concatenating with array of one element
10+
focused_on_node: "org.truffleruby.language.control.BreakNode"
11+
ruby: |
12+
while true
13+
break *foo, 42
14+
end
15+
ast: |
16+
BreakNode
17+
attributes:
18+
breakID = org.truffleruby.language.control.BreakID@...
19+
flags = 1
20+
ignoreMarker = true
21+
children:
22+
child =
23+
ArrayConcatNode
24+
attributes:
25+
flags = 0
26+
children:
27+
children = [
28+
SplatCastNodeGen
29+
attributes:
30+
conversionMethod = :to_a
31+
copy = true
32+
flags = 0
33+
nilBehavior = CONVERT
34+
children:
35+
childNode_ =
36+
RubyCallNode
37+
attributes:
38+
descriptor = org.truffleruby.language.arguments.EmptyArgumentsDescriptor@...
39+
dispatchConfig = PRIVATE
40+
emptyKeywordsProfile = false
41+
flags = 0
42+
isAttrAssign = false
43+
isSafeNavigation = false
44+
isSplatted = false
45+
isVCall = true
46+
lastArgIsNotHashProfile = false
47+
methodName = "foo"
48+
notEmptyKeywordsProfile = false
49+
notRuby2KeywordsHashProfile = false
50+
children:
51+
receiver =
52+
SelfNode
53+
attributes:
54+
flags = 0
55+
ArrayLiteralNode$UninitialisedArrayLiteralNode
56+
attributes:
57+
flags = 0
58+
language = org.truffleruby.RubyLanguage@...
59+
children:
60+
values = [
61+
IntegerFixnumLiteralNode
62+
attributes:
63+
flags = 0
64+
value = 42
65+
]
66+
]

0 commit comments

Comments
 (0)