Skip to content

Commit 3068280

Browse files
eregonandrykonchin
authored andcommitted
Implement value in pattern pattern matching
1 parent c8668bf commit 3068280

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/main/java/org/truffleruby/parser/YARPTranslator.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,17 @@ public RubyNode visitMatchLastLineNode(Nodes.MatchLastLineNode node) {
25582558

25592559
@Override
25602560
public RubyNode visitMatchPredicateNode(Nodes.MatchPredicateNode node) {
2561-
return defaultVisit(node);
2561+
var translator = new YARPPatternMatchingTranslator(language, environment, rubySource, this);
2562+
2563+
// Evaluate the expression and store it in a local
2564+
final int tempSlot = environment.declareLocalTemp("value_of_=>");
2565+
final ReadLocalNode readTemp = environment.readNode(tempSlot, node);
2566+
final RubyNode assignTemp = readTemp.makeWriteNode(node.value.accept(this));
2567+
2568+
RubyNode condition = translator.translatePatternNode(node.pattern, readTemp);
2569+
2570+
final RubyNode ret = sequence(Arrays.asList(assignTemp, condition));
2571+
return assignPositionAndFlags(node, ret);
25622572
}
25632573

25642574
@Override

test/mri/excludes/TestPatternMatching.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
exclude :test_alternative_pattern, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:204:in `test_alternative_pattern'."
66
exclude :test_invalid_syntax, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1269:in `test_invalid_syntax'."
77
exclude :test_deconstruct_keys, "Failed assertion, no message given."
8-
exclude :test_pin_operator_expr_pattern, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:468:in `test_pin_operator_expr_pattern'."
98
exclude :test_single_pattern_error_as_pattern, "Expected Exception(NoMatchingPatternError) was raised, but the message doesn't match."
109
exclude :test_single_pattern_error_value_pattern, "Expected Exception(NoMatchingPatternError) was raised, but the message doesn't match."
1110
exclude :test_single_pattern_error_hash_pattern, "Expected Exception(NoMatchingPatternError) was raised, but the message doesn't match."
1211
exclude :test_literal_value_pattern, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:347:in `test_literal_value_pattern'."
1312
exclude :test_find_pattern, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:806: YARPDefNodeTranslator does not know how to translate FindPatternNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:806"
14-
exclude :test_one_line, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1571: YARPDefNodeTranslator does not know how to translate MatchPredicateNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1571"
15-
exclude :test_hash_pattern, "NoMatchingPatternError: #<TestPatternMatching::C:0x6f8 @obj={:a=>0}>"
16-
exclude :test_array_pattern, "NoMatchingPatternError: #<TestPatternMatching::C:0x778 @obj=[0]>"
17-
exclude :test_bug18990, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1581: YARPDefNodeTranslator does not know how to translate MatchPredicateNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1581"
13+
exclude :test_hash_pattern, "NoMatchingPatternError: #<TestPatternMatching::C:0x708 @obj={:a=>0}>"
14+
exclude :test_array_pattern, "NoMatchingPatternError: #<TestPatternMatching::C:0x758 @obj=[0]>"
1815
exclude :test_single_pattern_error_find_pattern, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1623: YARPBlockNodeTranslator does not know how to translate FindPatternNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1623"
1916
exclude :test_deconstruct_cache, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1451: YARPBlockNodeTranslator does not know how to translate FindPatternNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1451"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exclude :test_refinements, "NoMatchingPatternError: #<TestPatternMatching::TestPatternMatchingRefinements::C1:0x9f8>"
1+
exclude :test_refinements, "NoMatchingPatternError: #<TestPatternMatching::TestPatternMatchingRefinements::C1:0x9b8>"

0 commit comments

Comments
 (0)