Commit graph

26 commits

Author SHA1 Message Date
Kevin Newton
746eede412 [ruby/yarp] Constant on block parameter node
2cd9a67150
2023-09-06 18:18:10 +00:00
Kevin Newton
dee383b262 [ruby/yarp] Constants on classes and modules
(https://github.com/ruby/yarp/pull/1409)

0a11ec579f
2023-09-06 16:19:43 +00:00
Kevin Newton
5537169ef0 [ruby/yarp] Temporarily add name_constant to replace name on ClassNode/ModuleNode
8f87686e9c
2023-09-06 14:20:13 +00:00
Kevin Newton
4c9a036606 [ruby/yarp] Add constants and constants
d7eaa89bc3
2023-09-06 13:00:23 +00:00
Kevin Newton
c666077182 [ruby/yarp] Add global variables to the constant pool
b48067b067
2023-09-01 22:52:14 +00:00
Mike Dalessio
cfe1edddbf [ruby/yarp] fix: report syntax error for invalid hex escape
Closes https://github.com/ruby/yarp/pull/1367

b1ab54f526
2023-09-01 17:04:37 +00:00
Mike Dalessio
512f8217cb [ruby/yarp] fix: double-counting of errors in parsing escaped strings
Essentially, this change updates `yp_unescape_calculate_difference` to
not create syntax errors, and we rely entirely on
`yp_unescape_manipulate_string` to report syntax errors.

To do that, this PR adds another (!) parameter to `unescape`:
`yp_list_t *error_list`. When present, `unescape` reports syntax
errors (and otherwise does not).

However, an edge case that needed to be addressed is reporting syntax
errors in this case:

    ?\u{1234 2345}

In a string context, it's possible to have multiple codepoints by
doing something like `"\u{1234 2345}"`; however, in the character
literal context, this is a syntax error -- only a single codepoint is
allowed.

Unfortunately, when `yp_unescape_manipulate_string` is called, there's
nothing to indicate that we are in a "character literal" context and
that only a single codepoint is valid.

To make this work, this PR:

- introduces a new static utility function in yarp.c,
  `yp_char_literal_node_create_and_unescape`, which is called when
  we're parsing `YP_TOKEN_CHARACTER_LITERAL`
- introduces a new (unexported) function,
  `yp_unescape_manipulate_char_literal` which does the same thing as
  `yp_unescape_manipulate_string` but tells `unescape` that only a
  single codepoint is expected

f6a65840b5
2023-09-01 17:04:37 +00:00
Benoit Daloze
a21b5a943f [ruby/yarp] Move name_loc before value for LocalVariableWriteNode
* Consistent with ClassVariableWriteNode, ConstantWriteNode, InstanceVariableWriteNode, GlobalVariableWriteNode.
* Fixes desugaring of local variable with operators.

9a66737775
2023-09-01 13:18:30 +00:00
Benoit Daloze
f1f6f1b39e [ruby/yarp] Make operator_loc the last field for GlobalVariableWriteNode
* Consistent with ClassVariableWriteNode, ConstantWriteNode, InstanceVariableWriteNode, LocalVariableWriteNode.
* Fixes desugaring of global variable with operators.

fb5a53fc0b
2023-09-01 13:18:30 +00:00
Mike Dalessio
df4c77608e [ruby/yarp] fix: octal, hex, and unicode strings at the end of a
file
(https://github.com/ruby/yarp/pull/1371)

* refactor: move EOF check into yp_unescape_calculate_difference

parser_lex is a bit more readable when we can rely on that behavior

* fix: octal and hex digits at the end of a file

Previously this resulted in invalid memory access.

* fix: unicode strings at the end of a file

Previously this resulted in invalid memory access.

* Unterminated curly-bracket unicode is a syntax error

21cf11acb5
2023-08-31 22:40:35 +00:00
Kevin Newton
c46858fd6a [ruby/yarp] Nest all of the YARP tests under the YARP namespace
440cf93a70
2023-08-30 20:41:59 +00:00
Mike Dalessio
3da139d284 [ruby/yarp] fix: "$" at the end of a file
Previously this resulted in invalid memory access as well as a
cascading failed assertion:

    src/enc/yp_unicode.c:2224: yp_utf_8_codepoint: Assertion `n >= 1' failed.

Found by the fuzzer.

a34c534440
2023-08-30 18:27:47 +00:00
Kevin Newton
439f069b4b [ruby/yarp] Move tests from test/* to test/yarp/* to match CRuby
This should make it easier on the sync to determine what changed
and hopefully result in fewer merge conflicts that have to be
manually resolved.

17d82afbfc
2023-08-25 21:15:49 +00:00
Kevin Newton
a31b069a8a [ruby/yarp] Track block opening and closing locations
7984e4ddc7
2023-08-25 21:10:13 +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.

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.

1d3fe19a94
2023-08-25 12:39:13 +00: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

a00067386d
2023-08-24 13:45:29 +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.

a037d942a8
2023-08-21 19:00:52 +00:00
Mike Dalessio
2800d1fd37 [ruby/yarp] fix: unterminated % in arguments
efb3102369
2023-08-18 12:51:14 +00:00
Takashi Kokubun
3873b1eb39 Resync YARP 2023-08-16 17:47:32 -07:00
Benoit Daloze
3536cad902 [ruby/yarp] Fixes so bundle exec rake can run on JRuby and TruffleRuby
e6cea4fa08
2023-08-16 17:47:32 -07:00
HParker
a8c70ed2b4 [ruby/yarp] add a diagnostic for *rest in order after optional state
908244ba12
2023-08-16 17:47:32 -07:00
Haldun Bayhantopcu
499eb3990f [ruby/yarp] Fix tests
50e745767e
2023-07-26 14:46:20 +00:00
Haldun Bayhantopcu
c680ae2ce1 [ruby/yarp] Added locations to errors tests
108d1221ef
2023-07-26 14:46:19 +00:00
Jemma Issroff
a02f5eb56a
YARP resync (#8059) 2023-07-12 12:46:38 -04:00
Jemma Issroff
cc7f765f2c [Feature #19741] Sync all files in yarp
This commit is the initial sync of all files from ruby/yarp
into ruby/ruby. Notably, it does the following:

* Sync all ruby/yarp/lib/ files to ruby/ruby/lib/yarp
* Sync all ruby/yarp/src/ files to ruby/ruby/yarp/
* Sync all ruby/yarp/test/ files to ruby/ruby/test/yarp
2023-06-21 11:25:39 -07:00