Skip to content

Commit 79def69

Browse files
committed
Add support for Ruby 3.1's anonymous block forwarding.
1 parent 327ff20 commit 79def69

File tree

5 files changed

+3836
-3798
lines changed

5 files changed

+3836
-3798
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ New features:
55
* Foreign strings now have all methods of Ruby `String`. They are treated as `#frozen?` UTF-8 Ruby Strings.
66
* Add `Java.add_to_classpath` method to add jar paths at runtime (#2693, @bjfish).
77
* Add support for Ruby 3.1's Hash shorthand/punning syntax (@nirvdrum).
8+
* Add support for Ruby 3.1's anonymous block forwarding syntax (@nirvdrum).
89

910
Bug fixes:
1011

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ public class ParserSupport {
158158
.usAsciiString(FORWARD_ARGS_KWREST_VAR);
159159
/** The local variable to store the block from ... in */
160160
public static final String FORWARD_ARGS_BLOCK_VAR = Layouts.TEMP_PREFIX + "forward_block";
161+
public static final TruffleString FORWARD_ARGS_BLOCK_VAR_TSTRING = TStringUtils
162+
.usAsciiString(FORWARD_ARGS_BLOCK_VAR);
161163

162164
// Parser states:
163165
protected StaticScope currentScope;
@@ -1536,6 +1538,11 @@ public void warning(SourceIndexLength position, String message) {
15361538
warnings.warning(file, position.toSourceSection(lexer.getSource()).getStartLine(), message);
15371539
}
15381540

1541+
public boolean local_id(String value) {
1542+
// FIXME: local_id_ref is more complicated and we just blanket look for a scope var of the same name.
1543+
return currentScope.isDefined(value) >= 0;
1544+
}
1545+
15391546
// ENEBO: Totally weird naming (in MRI is not allocated and is a local var name) [1.9]
15401547
public boolean is_local_id(TruffleString name) {
15411548
return lexer.isIdentifierChar(name.readByteUncached(0, lexer.tencoding));

0 commit comments

Comments
 (0)