107 Commits

Author SHA1 Message Date
Nathan Froyd
f726ad9740 [ruby/yarp] use memcmp for block memory comparison
https://github.com/ruby/yarp/commit/3563e5c5d5
2023-08-28 20:00:25 +00:00
Mike Dalessio
9b87518ea0 [ruby/yarp] fix: %I list spanning a heredoc
Similar to the previous %W fix, we accept a symbol node and
concatenate it onto an interpolated symbol.

https://github.com/ruby/yarp/commit/6b5911b95e
2023-08-28 12:37:31 +00:00
Mike Dalessio
29c5b85128 [ruby/yarp] fix: %i list spanning a heredoc
The fix here is similar to what we did in a previous commit for %w, to
accept two consecutive string tokens without a separator.

https://github.com/ruby/yarp/commit/f869fbdbe5
2023-08-28 12:37:30 +00:00
Mike Dalessio
74812df496 [ruby/yarp] fix: %W list spanning a heredoc
Primarily this fix is to accept a string node and concatenate it onto
an interpolated string.

https://github.com/ruby/yarp/commit/6df729fe72
2023-08-28 12:37:30 +00:00
Mike Dalessio
77e971b6ec [ruby/yarp] fix: %w list spanning a heredoc
Two fixes were necessary:

- ensure we are handling newlines correctly
- accept two consecutive string tokens without a separator

https://github.com/ruby/yarp/commit/4e707937cb

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2023-08-28 12:37:29 +00:00
Mike Dalessio
2b9a053740 [ruby/yarp] fix: yp_interpolated_symbol_node_append
Made this function's behavior match the interpolated_string
implementation.

Previously, the start location was not set and left as 0.

https://github.com/ruby/yarp/commit/87f348889f
2023-08-28 12:37:28 +00:00
Benoit Daloze
5937d01f7f [ruby/yarp] Rename constant pool fields to name or operator
* `constant_id` and `operator_id` are confusing.
* See https://github.com/ruby/yarp/issues/1296

https://github.com/ruby/yarp/commit/09d0a144df
2023-08-27 16:18:15 +00:00
Kevin Newton
ca9a44795b Remove version templating in YARP 2023-08-25 18:20:51 -04:00
Kevin Newton
9b8602dd90 [ruby/yarp] Introduce parse_lex instead of asking for a block
https://github.com/ruby/yarp/commit/7e70339fe1
2023-08-25 21:10:19 +00:00
Kevin Newton
4813887694 [ruby/yarp] Accept a block to parse and parse_file to get lexer output as well
https://github.com/ruby/yarp/commit/40fbf61a8d
2023-08-25 21:10:17 +00:00
Kevin Newton
0c1a749eef [ruby/yarp] Fix nested multi assignment locations
https://github.com/ruby/yarp/commit/9a65f002dc
2023-08-25 21:10:16 +00:00
Kevin Newton
a31b069a8a [ruby/yarp] Track block opening and closing locations
https://github.com/ruby/yarp/commit/7984e4ddc7
2023-08-25 21:10:13 +00:00
Kevin Newton
b9a2c96747 [ruby/yarp] Ensure interpolated symbols converted to regular symbols get opening and closing
https://github.com/ruby/yarp/commit/386655d54f
2023-08-25 21:10:13 +00:00
Kevin Newton
b112e89bb1 [ruby/yarp] Add closing_loc to WhileNode
https://github.com/ruby/yarp/commit/b4132b876d
2023-08-25 21:10:12 +00:00
Kevin Newton
df11a08d93 [ruby/yarp] Add closing_loc to UntilNode
https://github.com/ruby/yarp/commit/4362cecc2c
2023-08-25 21:10:11 +00:00
Kevin Newton
74780c3e7f [ruby/yarp] Call shorthand should not result in a message location
https://github.com/ruby/yarp/commit/ad0f9d35e3
2023-08-25 21:10:10 +00:00
Kevin Newton
0df515c095 [ruby/yarp] Mark local variable targets in pattern matching
https://github.com/ruby/yarp/commit/6c6700a001
2023-08-25 19:31:33 +00:00
Kevin Newton
7898b8e1ea [ruby/yarp] Provide target node versions
https://github.com/ruby/yarp/commit/a026564d38
2023-08-25 19:31:31 +00:00
Kevin Newton
aeef709109 [ruby/yarp] Split up parse_target and parse_write
https://github.com/ruby/yarp/commit/75d8bb93ea
2023-08-25 19:31:31 +00:00
Kevin Newton
a38ca45b65 [ruby/yarp] Split up AndWriteNode, OrWriteNode, OperatorWriteNode
https://github.com/ruby/yarp/commit/6d3b3b5776
2023-08-25 19:31:28 +00:00
Kevin Newton
3b9085ad24 [ruby/yarp] Lambda params should not accept blocks
https://github.com/ruby/yarp/commit/706daae0ac
2023-08-25 19:11:24 +00:00
Mike Dalessio
3525c460f9 [ruby/yarp] fix: regexes and strings with escaped newline around a heredoc
Found via the fuzzer.

https://github.com/ruby/yarp/commit/501757135a

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2023-08-25 18:20:49 +00:00
Jemma Issroff
bf3d48e182 [ruby/yarp] Allow whitespace after "(en)coding" before ":", as in "encoding :"
https://github.com/ruby/yarp/commit/d39a998182
2023-08-25 18:19:08 +00:00
Kevin Newton
61c5c2f1c8 [ruby/yarp] Add names to classes and modules
This should hopefully make it easier to compile these nodes, and
also for static analysis tools for having a quick label.

https://github.com/ruby/yarp/commit/f086662144
2023-08-25 17:02:38 +00:00
Mike Dalessio
b8cab92a3f [ruby/yarp] fix: unterminated regular expression with a heredoc
Previously this snippet would track the same newline twice, leading to
a failed assertion in yp_newline_list_append.

https://github.com/ruby/yarp/commit/1d3fe19a94
2023-08-25 12:39:13 +00:00
Kevin Newton
0e3dc5a056 [ruby/yarp] Fix lex compat with BOM
* BOM should not impact looking for the encoding string
* We should re-encode tokens when the encoding changes
* BOM should change the column of comments only

https://github.com/ruby/yarp/commit/119fc2d7b2
2023-08-24 21:30:01 +00:00
Kevin Newton
90048241ca [ruby/yarp] A couple small stylistic updates for yp_scope_node
* Ensure the node gets initialized in case of failure with no assertions
* Include lambda and top-level nodes for scopes
* Small indentation fixes

https://github.com/ruby/yarp/commit/be29e07391
2023-08-24 19:27:22 +00:00
Jemma Issroff
90ff30e51e [ruby/yarp] Requested changes
https://github.com/ruby/yarp/commit/eb01ea17c1
2023-08-24 19:06:02 +00:00
Jemma Issroff
82d84d741e [ruby/yarp] Added BlockNode case to ScopeNode, fixed ScopeNode to have body
https://github.com/ruby/yarp/commit/8bd3f59621
2023-08-24 19:06:01 +00:00
Jemma Issroff
ef82054bb5 [ruby/yarp] Added ModuleNode
https://github.com/ruby/yarp/commit/29754d818b
2023-08-24 19:06:01 +00:00
Jemma Issroff
82e1434ef6 [ruby/yarp] Pulled scope node out of config.yml, added necessary void returns
https://github.com/ruby/yarp/commit/926e6bdd88
2023-08-24 19:06:00 +00:00
Jemma Issroff
d81634d3ef [ruby/yarp] Add a ScopeNode and a way to create scope nodes from existing nodes
This commit creates a scope node, and exposes a method to get
ScopeNodes from other existing nodes. It still has TODOs around
creating ScopeNodes for other types of nodes, which will be
done in future commits.

https://github.com/ruby/yarp/commit/3b9ac5764d
2023-08-24 19:06:00 +00:00
Kevin Newton
791d572ba8 [ruby/yarp] A couple of small stylistic changes
* `le_len` to `eol_length`
* Braces on the same line as switch case
* `peek_addr` -> `peek_at`
* `peek_at` -> `peek_offset`
* `match_line_ending_addr` -> `match_eol_at`
* `match_line_ending_at` -> `match_eol_offset`

https://github.com/ruby/yarp/commit/d7ffa9e64e
2023-08-24 16:05:37 +00:00
Kevin Newton
432702a427 [ruby/yarp] Encoding-dependent escapes
https://github.com/ruby/yarp/commit/36a5b801c4
2023-08-24 11:56:16 -04:00
Mike Dalessio
20927a89c2 [ruby/yarp] Improve handling of line endings
Introduce three new inline helper functions:

- `match_line_ending`
- `match_line_ending_at`
- `match_line_ending_addr`

These functions are similar in signature to the `peek*` functions, but
return the length of the line ending being inspected (or 0 if no line
ending was found).

These functions are then used to simplify how we're detecting line
endings throughout "src/yarp.c".

Also:
- test coverage backfilled for `__END__` comments with CRLF line endings.
- error message for invalid `%` tokens updated to not include
  the potential line endings.
- some small refactorings for readability along the way

https://github.com/ruby/yarp/commit/a00067386d
2023-08-24 13:45:29 +00:00
Kevin Newton
f33c412ebc [ruby/yarp] Constant paths followed by an & should be lexed as a call
https://github.com/ruby/yarp/commit/b0a2ba2c4d
2023-08-23 18:29:25 +00:00
Kevin Newton
c837e1adfb [ruby/yarp] Add LABEL lex state when lexing a keyword params
https://github.com/ruby/yarp/commit/422bcd0ebf
2023-08-23 16:07:37 +00:00
Mike Dalessio
9c43ec621d [ruby/yarp] fix: newline tracking for a comment at EOF
https://github.com/ruby/yarp/commit/62fb0bddf5
2023-08-23 15:42:20 +00:00
Mike Dalessio
8f0a8e579d [ruby/yarp] Remove unnecessary loop
https://github.com/ruby/yarp/commit/86e8741ee3
2023-08-23 15:40:21 +00:00
Mike Dalessio
f902df128d [ruby/yarp] refactor: extract peek_addr()
In many places in the code we use the idiom:

    x < parser->end && *x == 'y'

which is essentially an extension of an existing pattern:

- `peek()` looks at `parser->current.end`
- `peek_at()` looks at `(parser->current.end + offset)`

This commit introduces a new inline function, `peek_addr`, which
accepts a pointer and encapsulates the address value check and
conditional dereferencing. The result is more readable code, and more
ubiquitous safety checks on pointer values, allowing us to rewrite the
above as:

    peek_addr(parser, x) == 'y'

Also:

- change the type of `peek_at()`'s offset argument from `size_t` to
  `ptrdiff_t` so that it can accept negative offsets.
- use `current_token_starts_line` in one place where the equivalent
  code is inline.
- use `peek` or `peek_at` to replace inline code in a few places

These changes simplify the code and make it easier to visually spot
patterns, particularly around line-endings (which will be a subject of
a future pull request).

https://github.com/ruby/yarp/commit/4c608d53ea
2023-08-23 15:08:35 +00:00
Mike Dalessio
95e29b0423 [ruby/yarp] fix: avoid invalid memory read when CR is present without LF
https://github.com/ruby/yarp/commit/2296c037de
2023-08-21 19:00:55 +00:00
Mike Dalessio
461f8eaba7 [ruby/yarp] fix: parsing a '%' expression with a CR but not a newline
Previously this failed an assertion and aborted.

https://github.com/ruby/yarp/commit/a037d942a8
2023-08-21 19:00:52 +00:00
Jemma Issroff
7d26c03267
Manually resync YARP
YARP commits were synced out of order. We are doing this reset
commit to ensure that all files are currently correct and we can
proceed with monitoring syncs so this doesn't happen again.
2023-08-21 10:45:56 -07:00
Mike Dalessio
9ca547b9fe [ruby/yarp] prefactor: extract yp_newline_list_check_append
https://github.com/ruby/yarp/commit/149c74291b
2023-08-21 10:43:24 -07:00
Mike Dalessio
926857eb1e [ruby/yarp] fix: support newline-terminated regular expressions
Previously, parsing a snippet like this:

    %r\nfoo\n

would result in tracking the second newline twice, resulting in a
failed runtime assertion.

Fixing that issue reveals another bug, which is that the _first_
newline was not being tracked at all. So we introduce a call to
yp_newline_list right when we construct the REGEXP_BEGIN token.

https://github.com/ruby/yarp/commit/0d5d759091
2023-08-21 10:43:23 -07:00
Kevin Newton
e63bac3128 [ruby/yarp] Rename statements to body where appropriate
https://github.com/ruby/yarp/commit/0aa7d9d10c
2023-08-21 10:43:21 -07:00
Kevin Newton
a7f40fc2d7 [ruby/yarp] Change AndWriteNode, OrWriteNode, OperatorWriteNode to contain write nodes
It makes it more difficult to find all locations where a variable
is written to if they're just read nodes. To keep things consistent
we should make them write nodes.

https://github.com/ruby/yarp/commit/840e094045
2023-08-21 10:43:18 -07:00
Kevin Newton
988b0108fb [ruby/yarp] Consolidate OperatorAndWrite and OperatorOrWrite nodes
https://github.com/ruby/yarp/commit/9e680a7598
2023-08-21 10:43:16 -07:00
Kevin Newton
4fb2b3b6bf [ruby/yarp] Ensure correct location with if/elsif, allow FOCUS env var, fix newlines on __END__
https://github.com/ruby/yarp/commit/9da0bc4452
2023-08-21 10:43:13 -07:00
Mike Dalessio
05c59995fa [ruby/yarp] fix: newline tracking for nl-terminated % %q %Q
https://github.com/ruby/yarp/commit/1e4940864b
2023-08-21 10:33:45 -07:00