102 Commits

Author SHA1 Message Date
Benoit Daloze
5c15f9380f [ruby/prism] Use the terminology "column in bytes/characters/code units"
* Consistent and clear.
* Avoids the confusion that "column number" might be understood
  as a column in an editor starting at 1 (they all start at 0).

https://github.com/ruby/prism/commit/91f1c4b9d5
2026-01-27 20:49:02 +00:00
Kevin Newton
af4a1ca021 Use slices instead of locations
In the C API, we want to use slices instead of locations in the
AST. In this case a "slice" is effectively the same thing as the
location, expect it is represented using a 32-bit offset and a
32-bit length. This will cut down on half of the space of all of
the locations in the AST.

Note that from the Ruby/Java/JavaScript side, this is effectively
an invisible change. This only impacts the C/Rust side.
2026-01-27 15:30:45 -05:00
Kevin Newton
786f673938 [ruby/prism] Correct constant pool bucket type logic
When replacing an owned constant by a different type (constant or
shared) replace with the correct type instead of defaulting to
shared.

https://github.com/ruby/prism/commit/fbe9b131a1
2025-12-05 20:35:31 +00:00
Nobuyoshi Nakada
b082d67253 [ruby/prism] Fix dangling pointers on Windows as well
Share the empty source string in `pm_string_mapped_init` and
`pm_string_file_init`.

https://github.com/ruby/prism/commit/f7a9a03a92
2025-09-19 14:27:00 +00:00
Nobuyoshi Nakada
234f4c0bb6
Fix dangling pointers 2025-09-13 17:10:44 +09:00
Alexander Momchilov
869c63bcc3 [ruby/prism] Add \memberof annotations
https://github.com/ruby/prism/commit/d1d2161219
2025-09-12 19:07:20 +00:00
Alexander Momchilov
120d3b12a9 [ruby/prism] Add links to code refs in docs
https://github.com/ruby/prism/commit/d2d9a1f1a7
2025-09-12 18:40:43 +00:00
Jean Boussier
025832c385 [ruby/prism] Use a locale-insensitive version of tolower
[Bug #21161]

The `tolower` function provided by the libc is locale dependent
and can behave in ways you wouldn't expect for some value
of `LC_CTYPE`.

https://github.com/ruby/prism/commit/e3488256b4

Co-Authored-By: Nobuyoshi Nakada <nobu@ruby-lang.org>
2025-02-28 00:28:24 +00:00
HASUMI Hitoshi
31162bf426 [ruby/prism] Handle zero-sized allocation in pm_constant_id_list_init_capacity
According to the calloc(3) man page, when nmemb or size is 0, `calloc()` can either return NULL or a unique pointer that can be passed to `free()`.
While gcc and clang typically return a unique pointer, mruby's `mrb_calloc()` returns NULL in this case.

Since `pm_constant_pool_init()` is commonly called with capacity=0 during normal operation of Prism, explicitly handle this case by setting `list->ids` to NULL when capacity is 0.
This approach is portable across different calloc implementations and avoids potential issues with mruby's allocation behavior.

This maintains compatibility with `free()` and `realloc()`, as passing NULL pointers to these functions is explicitly allowed by their specifications.

https://github.com/ruby/prism/commit/1c32252df7
2025-02-13 20:12:43 +00:00
Kevin Newton
c4534c9fe8 [ruby/prism] Handle escapes in named capture names
https://github.com/ruby/prism/commit/b4b7a69ce7
2025-01-08 20:36:06 +00:00
Yusuke Endoh
29e90a598a [ruby/prism] Fix a possible leak of a file descriptor
When mmap fails for any reason, the fd must be closed.

Coverity Scan found this issue.

https://github.com/ruby/prism/commit/c06e9c400f
2024-11-28 02:15:25 +00:00
Aaron Patterson
3c9be02af1 [ruby/prism] Only read from buffer if size is greater than 0
It looks like we can possibly do an out of bounds read if size is equal
to 0.  This commit adds a conditional to ensure size is actually greater
than 0 before looking backwards in the buffer

https://github.com/ruby/prism/commit/2031b626e6
2024-10-28 20:38:20 +00:00
Kevin Newton
ddbd644001 [ruby/prism] Stat file first to check directory
https://github.com/ruby/prism/commit/4ed7de537b
2024-09-13 19:30:57 +00:00
Kevin Newton
38ba15beed [ruby/prism] Check errno for parsing directory
https://github.com/ruby/prism/commit/d68ea29d04
2024-09-12 13:43:04 -04:00
Kevin Newton
d4d6f1de83 [ruby/prism] UTF-8 characters in file name
https://github.com/ruby/prism/commit/487f0ffe78
2024-09-11 19:17:12 +00:00
Kevin Newton
886fc69b1c [ruby/prism] Parse tempfile
https://github.com/ruby/prism/commit/31154a389a
2024-09-11 15:39:22 +00:00
Alexander Momchilov
2b0b68fa46 Shrink pm_integer_t (32 bytes → 24) 2024-08-26 12:38:58 +00:00
Yuta Saito
a65c205a1b [ruby/prism] Add explicit check for PRISM_HAS_NO_FILESYSTEM
https://github.com/ruby/prism/commit/89c22f0e6c
2024-07-26 17:07:50 +00:00
Yuta Saito
1992bd31a5 [ruby/prism] Fallback to pm_string_file_init on platforms without memory-mapped files
> ..., and on other POSIX systems we'll use `read`.

As `pm_string_mapped_init`'s doc comment says, it should fall back to
`read(2)`-based implementation on platforms without memory-mapped files
like WASI, but it didn't. This commit fixes it by calling `pm_string_file_init`
in the fallback case.
Also `defined(_POSIX_MAPPED_FILES)` check for `read(2)`-based path is
unnecessary, and it prevents the fallback from being executed, so this
change removes it.

https://github.com/ruby/prism/commit/b3d9064b71
2024-07-26 17:07:50 +00:00
Kevin Newton
8e5ac5a87d [PRISM] Ensure not opening directories 2024-07-18 13:03:25 -04:00
Kevin Newton
c1df15c3e6 [PRISM] Use node ids for error highlight 2024-07-11 14:25:54 -04:00
Kevin Newton
ac70dd07e6 [ruby/prism] Remove unused string list struct
https://github.com/ruby/prism/commit/36c6851c85
2024-06-05 14:40:03 -04:00
Herwin
61e2916d1c [ruby/prism] Typo fix: poitive => positive
https://github.com/ruby/prism/commit/d13a05252d
2024-05-28 15:28:02 +00:00
Kevin Newton
b04c959621 [ruby/prism] Remove various unused memsize infra
https://github.com/ruby/prism/commit/283938ed1f
2024-05-24 17:19:34 +00:00
Kevin Newton
b8681c2e37 [ruby/prism] Remove Debug::integer_parse
https://github.com/ruby/prism/commit/14e397598b
2024-05-24 17:19:33 +00:00
Kevin Newton
870350253e [ruby/prism] Remove Debug::static_inspect
https://github.com/ruby/prism/commit/486c71c426
2024-05-24 17:19:33 +00:00
Kevin Newton
89efb94fec [ruby/prism] Reconfigure rationals
This eliminates the subnode on RationalNode and replaces it with two
integer fields, which represent the ratio for the rational. It also
reduces those two integers if they both fit into 32 bits.

Importantly, this PR does not implement bignum reduction. That's something
I'd like to consider for the future, but it's simple enough for now to
leave them unreduced, which makes it more useful than it used to be.

https://github.com/ruby/prism/commit/86e06c7068
2024-05-21 14:27:46 -04:00
Kevin Newton
286d3032a7 [ruby/prism] More mixed encoding errors
https://github.com/ruby/prism/commit/2a43b4f55c
2024-05-16 17:22:14 +00:00
Kevin Newton
0defbc11a5 [ruby/prism] Fix recursive multiply when values are switched in karatsuba_multiply
https://github.com/ruby/prism/commit/4dc6ea960d
2024-04-23 18:17:29 +00:00
Kevin Newton
f72436f835 [ruby/prism] Inline pm_state_stack 2024-04-17 10:36:52 -04:00
Kevin Newton
f34409bf87 [ruby/prism] Fix up more clang-analyzer failures
https://github.com/ruby/prism/commit/f9a1abbc64
2024-04-17 01:15:21 +00:00
Kevin Newton
646a00892e [ruby/prism] Fix up clang-analyzer violations
https://github.com/ruby/prism/commit/259aef2acd
2024-04-16 14:30:34 +00:00
Kevin Newton
540cc886b9 [ruby/prism] Make the locals set switch from list to hash dynamically
https://github.com/ruby/prism/commit/c977c4c98a
2024-04-05 19:23:57 +00:00
Kevin Newton
358aeb103b [ruby/prism] Switch locals to use a hash
https://github.com/ruby/prism/commit/f38946021e
2024-04-05 19:23:57 +00:00
Kevin Newton
35ff302893 [ruby/prism] Various cleanup with new -x option
https://github.com/ruby/prism/commit/020756fb11
2024-03-28 12:04:35 -04:00
Kevin Newton
fcc06fa82a [ruby/prism] CLI -x flag
https://github.com/ruby/prism/commit/2068e3c30a
2024-03-28 12:04:35 -04:00
Koichi ITO
56a2fad2a4 [ruby/prism] Fix incorrect paring when using invalid regexp options
Fixes https://github.com/ruby/prism/pull/2617.

There was an issue with the lexer as follows.
The following are valid regexp options:

```console
$ bundle exec ruby -Ilib -rprism -ve 'p Prism.lex("/x/io").value.map {|token| token[0].type }'
ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22]
[:REGEXP_BEGIN, :STRING_CONTENT, :REGEXP_END, :EOF]
```

The following are invalid regexp options. Unnecessary the `IDENTIFIER` token is appearing:

```console
$ bundle exec ruby -Ilib -rprism -ve 'p Prism.lex("/x/az").value.map {|token| token[0].type }'
ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22]
[:REGEXP_BEGIN, :STRING_CONTENT, :REGEXP_END, :IDENTIFIER, :EOF]
```

As a behavior of Ruby, when given `A` to `Z` and `a` to `z`, they act as invalid regexp options. e.g.,

```console
$ ruby -e '/regexp/az'
-e:1: unknown regexp options - az
/regexp/az
-e: compile error (SyntaxError)
```

Thus, it should probably not be construed as `IDENTIFIER` token.

Therefore, `pm_byte_table` has been adapted to accept those invalid regexp option values.
Whether it is a valid regexp option or not is checked by `pm_regular_expression_flags_create`.
For invalid regexp options, `PM_ERR_REGEXP_UNKNOWN_OPTIONS` is added to diagnostics.

https://github.com/ruby/prism/commit/d2a6096fcf
2024-03-25 12:16:32 +00:00
Kevin Newton
a05dfbd405
[PRISM] Remove ssize_t definition from prism 2024-03-13 12:06:48 -04:00
Kevin Newton
4dd9602c6f [ruby/prism] Remove ssize_t usage
https://github.com/ruby/prism/commit/64c4f1268b
2024-03-13 16:06:13 +00:00
Nobuyoshi Nakada
f42164e037
Define ssize_t on mswin build 2024-03-12 14:49:25 +09:00
Kevin Newton
21ea290b34 [ruby/prism] Static literals inspect
https://github.com/ruby/prism/commit/4913d112da
2024-03-12 03:30:50 +00:00
Kevin Newton
6242a82c8f [ruby/prism] Provide more documentation for pm_integer_parse_digit_values
https://github.com/ruby/prism/commit/c3fcb5031f
2024-03-11 15:12:14 +00:00
Kevin Newton
2dfa95a272 [ruby/prism] Stop crashing on invalid integers
https://github.com/ruby/prism/commit/afac2d6646
2024-03-11 15:11:42 +00:00
Kevin Newton
f5294ebbdb [ruby/prism] Shared integer parsing logic
https://github.com/ruby/prism/commit/a2594a23c1
2024-03-07 18:02:33 -05:00
Kevin Newton
c1462250b8 [ruby/prism] Style and allocation functions
https://github.com/ruby/prism/commit/97f838c323
2024-03-07 18:02:33 -05:00
tompng
81f02eb6ba [ruby/prism] Change pm_integer_t structure
https://github.com/ruby/prism/commit/588acf823f
2024-03-07 18:02:33 -05:00
tompng
5113d6b059 [ruby/prism] Faster pm_integer_parse pm_integer_string using karatsuba algorithm
https://github.com/ruby/prism/commit/ae4fb6b988
2024-03-07 18:02:33 -05:00
Kevin Newton
b88973165a [ruby/prism] Parse files from Ruby API using fread, not mmap
https://github.com/ruby/prism/commit/62d4376a53
2024-03-06 17:45:56 +00:00
cui fliter
226a889dc7
[DOC] fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 18:50:47 +09:00
HASUMI Hitoshi
b95e2cdca7 [ruby/prism] Additional fix of adding x prefix after rebase with main branch
https://github.com/ruby/prism/commit/08733438bd
2024-03-04 16:40:24 +00:00