Repository navigation
scanner: continue a line that starts with ||, and or or (Ruby 4.0) - #303
Open
clarifydoc wants to merge 1 commit into
Open
clarifydoc wants to merge 1 commit into
clarifydoc wants to merge 1 commit into
Conversation
Ruby 4.0 lets a line starting with a logical operator continue the
previous line, the way a leading `.` or `&.` continues a method chain:
if user.admin?
|| user.owner?
...
A leading `&&` already parses, because the scanner never ends a line
before `&` (that is what keeps `&.` chains together). A leading `||`
was a parse error, and a leading `and`/`or` was silently read as a
call to a method named `and`/`or`.
Before 4.0 all of these were syntax errors, so no older program
parses differently. `android`, `order`, `and?` and `or!` at the start
of a line still end it.
Magikdidi24
pushed a commit
to Magikdidi24/tree-sitter-ruby
that referenced
this pull request
Oct 25, 2026
…previous one (tree-sitter#302) Ruby 4.0 (Feature #20925). From upstream PR tree-sitter#303, with the char test made locale-independent like the rest of this scanner (no <wctype.h>). Trees unchanged on 955 stdlib/gem files. Before: c / || d -> (identifier) (binary left: (identifier) (MISSING identifier) ...) e / and f -> (identifier) (call method: (identifier) arguments: (argument_list (identifier))) After: c / || d -> (binary left: (identifier) right: (identifier)) e / and f -> (binary left: (identifier) right: (identifier))
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #302.
Ruby 4.0 lets a line that starts with
||,&&,andororcontinue the previous line (Feature #20925). A leading&&already parsed, because the scanner never ends a line before&(that is what keeps&.chains together). A leading||was a parse error, and a leadingand/orwas read as a call to a method namedand/or.scan_whitespacenow treats a newline followed by||, or byand/oras a whole word, the way it treats a newline followed by.: no line break is emitted. It uses the same word test as prism:android,order,and?,or!andand:still end the line. A single|(block parameters on the next line) is unchanged.Before 4.0 all of these lines were syntax errors, so no older program parses differently.
Only
src/scanner.cchanges; the grammar andparser.care untouched.Tests
test/corpus/expressions.txt: the four operators, a comment line between the two lines, and identifiers that start withand/or. The first two fail on master and pass here; all 294 corpus tests pass.-Wall -Wextra -Wpedanticwith no new warnings.