Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2603d40
Unescape carriage-return delimiters in %s and %q literals
kddnewton Nov 26, 2026
53e9bee
Treat a lone carriage return before CRLF as whitespace
kddnewton Nov 26, 2026
8026fa7
Dedent whitespace-only squiggly heredocs
kddnewton Nov 26, 2026
d5e73af
Recognize modifiers after symbol arguments to undef and alias
kddnewton Nov 26, 2026
b6b7663
Accept word separators split by heredocs in %w and %i lists
kddnewton Nov 26, 2026
6aeec67
Reject quoted labels used as standalone pattern elements
kddnewton Nov 26, 2026
68ad02d
Handle dangling escapes in quoted magic comments
kddnewton Nov 26, 2026
022a5ca
Allow chaining after blocks on ::F! and ::F? calls
kddnewton Nov 26, 2026
be4aa51
Preserve CRLF in braced Unicode escapes in regexps
kddnewton Nov 26, 2026
ef03501
Reject void jump arguments with chained command blocks
kddnewton Nov 26, 2026
b53296d
Allow do blocks in rescue headers inside command arguments
kddnewton Nov 26, 2026
65a11c5
Allow forwarding parameters in methods defined inside parameter defaults
kddnewton Nov 27, 2026
cb375fd
Store parser contexts in a growable array
kddnewton Nov 27, 2026
ab8dc39
Validate bytes after literal backslashes in non-interpolating literals
kddnewton Nov 27, 2026
af3b196
Match parse.y shebang search and encoding comment handling
kddnewton Nov 27, 2026
ad1edaf
Preserve enclosing delimiters when skipping heredocs at the nesting l…
kddnewton Nov 27, 2026
45a25cc
Report unterminated quoted heredoc identifiers at EOF
kddnewton Nov 27, 2026
2a3ddcd
Treat line continuations as whitespace after heredocs
kddnewton Nov 27, 2026
ab3a807
Reject literal \n inside braced Unicode escapes
kddnewton Nov 27, 2026
3e6a94a
Allow anonymous splat forwarding before a comma in rescue lists and a…
kddnewton Nov 27, 2026
1097dc1
Recognize single-byte whitespace after ? in the source encoding
kddnewton Nov 28, 2026
eb0294c
Prevent hash labels from inheriting the encodings of their values
kddnewton Nov 28, 2026
d0c68c7
Skip local assignment for regexp capture names incompatible with the …
kddnewton Nov 28, 2026
ebef0aa
Preserve local variable depth when recovering from unwritable assignm…
kddnewton Nov 28, 2026
f03bd54
Set Ruby 3.4 syntax explicitly in version-sensitive parser tests
kddnewton Nov 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/prism/internal/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ typedef struct {

/* The length of the encoding name in bytes, excluding the terminator. */
uint8_t name_length;

/* The byte above 0x7F that represents whitespace on its own, or zero if none. */
uint8_t space;
} pm_encoding_t;

/* Return a string view of the encoding name. */
Expand Down Expand Up @@ -157,6 +160,9 @@ bool pm_encoding_unicode_digit_p(uint32_t codepoint, pm_options_version_t versio
*/
bool pm_encoding_isupper_char(const pm_encoding_t *encoding, const uint8_t *b, ptrdiff_t n, pm_options_version_t version);

/* Return true if the byte is a complete whitespace character in the encoding. */
bool pm_encoding_space_char(const pm_encoding_t *encoding, uint8_t byte);

/* Return the size of the next character in the UTF-8 encoding. */
size_t pm_encoding_utf_8_char_width(const uint8_t *b, ptrdiff_t n);

Expand Down
2 changes: 1 addition & 1 deletion include/prism/internal/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ struct pm_options_t {
/* The kind of shebang found on a source line. */
typedef enum {
PM_OPTIONS_SHEBANG_NONE,
PM_OPTIONS_SHEBANG_COMMENT, /* Only permits an encoding comment on the next line. */
PM_OPTIONS_SHEBANG_OTHER,
PM_OPTIONS_SHEBANG_RUBY
} pm_options_shebang_type_t;
Expand All @@ -185,6 +184,7 @@ static inline bool
pm_options_shebang_search_p(const pm_options_t *options, pm_options_shebang_type_t shebang) {
return (
(options != NULL) &&
!(options->command_line & PM_OPTIONS_COMMAND_LINE_E) &&
(shebang != PM_OPTIONS_SHEBANG_RUBY) &&
(
(options->command_line & PM_OPTIONS_COMMAND_LINE_X) ||
Expand Down
31 changes: 12 additions & 19 deletions include/prism/internal/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,12 @@ typedef enum {
PM_CONTEXT_MAXIMUM,
} pm_context_t;

/* This is a node in a linked list of contexts. */
typedef struct pm_context_node {
/* The context that this node represents. */
typedef struct {
pm_context_t context;

/* A pointer to the previous context in the linked list. */
struct pm_context_node *prev;

/* One bit set per context in this list, including one for this node. */
uint64_t mask;
} pm_context_node_t;
/* Popping the outermost occurrence clears this context's membership bit. */
bool outermost;
} pm_context_frame_t;

/* The type of shareable constant value that can be set. */
typedef uint8_t pm_shareable_constant_value_t;
Expand Down Expand Up @@ -837,15 +832,13 @@ struct pm_parser_t {
*/
pm_scope_t *free_scopes;

/* The current parsing context. */
pm_context_node_t *current_context;
/* Slot 0 holds PM_CONTEXT_NONE. The depth indexes the current frame. */
pm_context_frame_t *contexts;
uint32_t context_depth;
uint32_t context_capacity;

/*
* Context nodes that have been popped, kept for reuse by the next push.
* Context nodes are allocated from the scratch arena, so they are never
* freed individually.
*/
pm_context_node_t *free_contexts;
/* One bit per context present anywhere on the stack. */
uint64_t context_mask;

/*
* The encoding functions for the current file is attached to the parser as
Expand All @@ -861,8 +854,8 @@ struct pm_parser_t {
pm_encoding_changed_callback_t encoding_changed_callback;

/*
* This pointer indicates where a comment must start if it is to be
* considered an encoding comment. NULL if the shebang has no terminating newline.
* Start of the source line that can contain an encoding comment, or NULL
* if there is no eligible line.
*/
const uint8_t *encoding_comment_start;

Expand Down
2 changes: 1 addition & 1 deletion lib/prism/translation/ripper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ def visit_call_node(node)

private def constant_brace_command?(node)
node.block.is_a?(BlockNode) && node.opening_loc.nil? && node.call_operator == "::" &&
node.block.opening == "{" && node.message&.match?(/\A[[:upper:]]/)
node.block.opening == "{" && StringQuery.constant?(node.name.to_s)
end

# Returns true if the given node is a command node.
Expand Down
128 changes: 64 additions & 64 deletions snapshots/3.4/command_call_do_block_in_arguments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -819,70 +819,70 @@
│ @ StatementsNode (location: (35,2)-(35,33))
│ ├── flags: ∅
│ └── body: (length: 1)
│ └── @ CallNode (location: (35,2)-(35,33))
│ ├── flags: newline, ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
│ ├── name: :foo
│ ├── message_loc: (35,2)-(35,5) = "foo"
│ ├── opening_loc: (35,5)-(35,6) = "("
│ ├── arguments:
│ │ @ ArgumentsNode (location: (35,6)-(35,32))
│ │ ├── flags: ∅
│ │ └── arguments: (length: 1)
│ │ └── @ CallNode (location: (35,6)-(35,32))
│ │ ├── flags: ∅
│ │ ├── receiver:
│ │ │ @ ReturnNode (location: (35,6)-(35,27))
│ │ │ ├── flags: ∅
│ │ │ ├── keyword_loc: (35,6)-(35,12) = "return"
│ │ │ └── arguments:
│ │ │ @ ArgumentsNode (location: (35,13)-(35,27))
│ │ │ ├── flags: ∅
│ │ │ └── arguments: (length: 1)
│ │ │ └── @ CallNode (location: (35,13)-(35,27))
│ │ │ ├── flags: ignore_visibility
│ │ │ ├── receiver: ∅
│ │ │ ├── call_operator_loc: ∅
│ │ │ ├── name: :bar
│ │ │ ├── message_loc: (35,13)-(35,16) = "bar"
│ │ │ ├── opening_loc: ∅
│ │ │ ├── arguments:
│ │ │ │ @ ArgumentsNode (location: (35,17)-(35,20))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── arguments: (length: 1)
│ │ │ │ └── @ CallNode (location: (35,17)-(35,20))
│ │ │ │ ├── flags: variable_call, ignore_visibility
│ │ │ │ ├── receiver: ∅
│ │ │ │ ├── call_operator_loc: ∅
│ │ │ │ ├── name: :baz
│ │ │ │ ├── message_loc: (35,17)-(35,20) = "baz"
│ │ │ │ ├── opening_loc: ∅
│ │ │ │ ├── arguments: ∅
│ │ │ │ ├── closing_loc: ∅
│ │ │ │ ├── equal_loc: ∅
│ │ │ │ └── block: ∅
│ │ │ ├── closing_loc: ∅
│ │ │ ├── equal_loc: ∅
│ │ │ └── block:
│ │ │ @ BlockNode (location: (35,21)-(35,27))
│ │ │ ├── flags: ∅
│ │ │ ├── locals: []
│ │ │ ├── parameters: ∅
│ │ │ ├── body: ∅
│ │ │ ├── opening_loc: (35,21)-(35,23) = "do"
│ │ │ └── closing_loc: (35,24)-(35,27) = "end"
│ │ ├── call_operator_loc: (35,27)-(35,28) = "."
│ │ ├── name: :last
│ │ ├── message_loc: (35,28)-(35,32) = "last"
│ │ ├── opening_loc: ∅
│ │ ├── arguments: ∅
│ │ ├── closing_loc: ∅
│ │ ├── equal_loc: ∅
│ │ └── block: ∅
│ ├── closing_loc: (35,32)-(35,33) = ")"
│ ├── equal_loc: ∅
│ └── block: ∅
│ └── @ ReturnNode (location: (35,2)-(35,33))
│ ├── flags: newline
│ ├── keyword_loc: (35,2)-(35,8) = "return"
│ └── arguments:
│ @ ArgumentsNode (location: (35,9)-(35,33))
│ ├── flags: ∅
│ └── arguments: (length: 1)
│ └── @ CallNode (location: (35,9)-(35,33))
│ ├── flags: ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
│ ├── name: :foo
│ ├── message_loc: (35,9)-(35,12) = "foo"
│ ├── opening_loc: (35,12)-(35,13) = "("
│ ├── arguments:
│ │ @ ArgumentsNode (location: (35,13)-(35,32))
│ │ ├── flags: ∅
│ │ └── arguments: (length: 1)
│ │ └── @ CallNode (location: (35,13)-(35,32))
│ │ ├── flags: ∅
│ │ ├── receiver:
│ │ │ @ CallNode (location: (35,13)-(35,27))
│ │ │ ├── flags: ignore_visibility
│ │ │ ├── receiver: ∅
│ │ │ ├── call_operator_loc: ∅
│ │ │ ├── name: :bar
│ │ │ ├── message_loc: (35,13)-(35,16) = "bar"
│ │ │ ├── opening_loc: ∅
│ │ │ ├── arguments:
│ │ │ │ @ ArgumentsNode (location: (35,17)-(35,20))
│ │ │ │ ├── flags: ∅
│ │ │ │ └── arguments: (length: 1)
│ │ │ │ └── @ CallNode (location: (35,17)-(35,20))
│ │ │ │ ├── flags: variable_call, ignore_visibility
│ │ │ │ ├── receiver: ∅
│ │ │ │ ├── call_operator_loc: ∅
│ │ │ │ ├── name: :baz
│ │ │ │ ├── message_loc: (35,17)-(35,20) = "baz"
│ │ │ │ ├── opening_loc: ∅
│ │ │ │ ├── arguments: ∅
│ │ │ │ ├── closing_loc: ∅
│ │ │ │ ├── equal_loc: ∅
│ │ │ │ └── block: ∅
│ │ │ ├── closing_loc: ∅
│ │ │ ├── equal_loc: ∅
│ │ │ └── block:
│ │ │ @ BlockNode (location: (35,21)-(35,27))
│ │ │ ├── flags: ∅
│ │ │ ├── locals: []
│ │ │ ├── parameters: ∅
│ │ │ ├── body: ∅
│ │ │ ├── opening_loc: (35,21)-(35,23) = "do"
│ │ │ └── closing_loc: (35,24)-(35,27) = "end"
│ │ ├── call_operator_loc: (35,27)-(35,28) = "."
│ │ ├── name: :last
│ │ ├── message_loc: (35,28)-(35,32) = "last"
│ │ ├── opening_loc: ∅
│ │ ├── arguments: ∅
│ │ ├── closing_loc: ∅
│ │ ├── equal_loc: ∅
│ │ └── block: ∅
│ ├── closing_loc: (35,32)-(35,33) = ")"
│ ├── equal_loc: ∅
│ └── block: ∅
├── locals: []
├── def_keyword_loc: (34,0)-(34,3) = "def"
├── operator_loc: ∅
Expand Down
Loading
Loading