Commit graph

43 commits

Author SHA1 Message Date
Aaron Patterson
89d89fa49d When reading from stdin, put a wrapper around the IO object
The purpose of this commit is to fix Bug #21188.  We need to detect when
stdin has run in to an EOF case.  Unfortunately we can't _call_ the eof
function on IO because it will block.

Here is a short script to demonstrate the issue:

```ruby
x = STDIN.gets
puts x
puts x.eof?
```

If you run the script, then type some characters (but _NOT_ a newline),
then hit Ctrl-D twice, it will print the input string.  Unfortunately,
calling `eof?` will try to read from STDIN again causing us to need a
3rd Ctrl-D to exit the program.

Before introducing the EOF callback to Prism, the input loop looked
kind of like this:

```ruby
loop do
  str = STDIN.gets
  process(str)

  if str.nil?
    p :DONE
  end
end
```

Which required 3 Ctrl-D to exit.  If we naively changed it to something
like this:

```ruby
loop do
  str = STDIN.gets
  process(str)

  if STDIN.eof?
    p :DONE
  end
end
```

It would still require 3 Ctrl-D because `eof?` would block.  In this
patch, we're wrapping the IO object, checking the buffer for a newline
and length, and then using that to simulate a non-blocking eof? method.

This commit wraps STDIN and emulates a non-blocking `eof` function.

[Bug #21188]
2025-08-04 12:34:33 -07:00
Kevin Newton
617e8608b2 [ruby/prism] Rename fgets parameter to fix NetBSD
Fixes [Bug #21165]

3f0acf7560
2025-03-02 18:14:36 +00:00
Kevin Newton
5f62522d5b [ruby/prism] Prism::StringQuery
Introduce StringQuery to provide methods to access some metadata
about the Ruby lexer.

d3f55b67b9
2024-10-11 19:34:57 +00:00
Kevin Newton
79001c8b4a [ruby/prism] Remove error formatting, put directly in CRuby
53b2866487
2024-05-24 17:19:36 +00:00
Kevin Newton
b25282e618 [ruby/prism] Replace . with decimal point for strtod
578a4f983e
2024-04-01 19:39:33 +00:00
Kevin Newton
9b816e674a [ruby/prism] Add option for inlining messages for error formatting
af0204a8ab
2024-03-27 13:03:11 -04:00
Kevin Newton
af7bf9e0d8 [ruby/prism] Provide options for reducing size
592128de4d
2024-03-20 17:32:03 -04:00
Kevin Newton
977012bae8 [ruby/prism] Remove restrict to fix windows 2015
f0a2ce1c0e
2024-03-07 21:23:18 +00:00
Kevin Newton
ec159fc8ba [ruby/prism] Support parsing streams
efdc2b7222
2024-03-07 20:40:39 +00:00
Kevin Newton
d1ce989829 [ruby/prism] Duplicated hash keys
3e10c46c14
2024-02-23 13:25:31 -05:00
Kevin Newton
5e0589cf52 [ruby/prism] Parse float values
9137226a52
2024-02-22 22:42:44 -05:00
Kevin Newton
3b3def5db7 [ruby/prism] Regenerate snapshots using integer values 2024-02-22 22:42:44 -05:00
Kevin Newton
ff6ebba9de [ruby/prism] Parse numeric values
a6a552411c
2024-02-22 22:42:44 -05:00
Kevin Newton
b56b8ec797 [ruby/prism] Provide the ability to dump AST to JSON from C
d3a149efc5
2024-02-17 02:05:12 +00:00
Kevin Newton
6f4bb638b0 [ruby/prism] Builtins
851f2571ff
2024-02-16 19:34:38 +00:00
Kevin Newton
ba06a8259a [ruby/prism] Better error messages for unexpected tokens in prefix
a35b8e45ee
2024-01-30 16:10:08 +00:00
Kevin Newton
6ff9f1aa51 [ruby/prism] Provide ability to format errors
27985b0e7e
2024-01-11 18:36:32 +00:00
Kevin Newton
28ec79404a
Sync to latest prism 2024-01-02 11:34:04 -05:00
Alex Koval
36ca99b343 [ruby/prism] fix typo in docs
d7fbc09345
2023-12-13 12:17:57 +00:00
Kevin Newton
82f18baa21 [ruby/prism] Provide flags for changing encodings
e838eaff6f
2023-12-06 14:23:38 -05:00
HParker
b8b319dd1a Revert "allow enabling Prism via flag or env var"
This reverts commit 9b76c7fc89.
2023-12-06 10:21:12 +09:00
HParker
9b76c7fc89 allow enabling Prism via flag or env var
Enable Prism using either --prism

    ruby --prism test.rb

or via env var

    RUBY_PRISM=1 ruby test.rb
2023-12-05 12:17:14 -05:00
Kevin Newton
492c82cb41 [ruby/prism] Prism.parse_success?(source)
A lot of tools use Ripper/RubyVM::AbstractSyntaxTree to determine
if a source is valid. These tools both create an AST instead of
providing an API that will return a boolean only.

This new API only creates the C structs, but doesn't bother
reifying them into Ruby/the serialization API. Instead it only
returns true/false, which is significantly more efficient.

7014740118
2023-12-01 20:53:34 +00:00
Kevin Newton
ea409958b3 [ruby/prism] Remove ability to decode other encodings
98e218d989
2023-11-30 21:37:56 -05:00
Kevin Newton
aab2a6a8a3
[ruby/prism] Fix up lint
4f3a3e3ec1
2023-11-03 10:13:50 -04:00
Kevin Newton
8587d9a8bf
[ruby/prism] Wire up options through the Java parser
13fa262669
2023-11-03 10:13:50 -04:00
Kevin Newton
6496591194
[ruby/prism] Rename serialization APIs for consistency
5a2252e3ac
2023-11-03 10:13:49 -04:00
Kevin Newton
05f5c545d2
[ruby/prism] Wire up options through the FFI API
f0aa8ad93b
2023-11-03 10:13:49 -04:00
Kevin Newton
2a0f2b7763
[ruby/prism] Create an options struct for passing all of the possible options
99e81619de
2023-11-03 10:13:49 -04:00
Kevin Newton
3551abab06 [ruby/prism] Fix up lint
77d4056766
2023-11-01 13:10:29 -04:00
Kevin Newton
690f3bbf5d [ruby/prism] Last remaining missing C comments
e327449db6
2023-11-01 13:10:29 -04:00
Kevin Newton
17923cc876 [ruby/prism] Even more C file documentation
9c648ce615
2023-11-01 13:10:29 -04:00
Kevin Newton
493439c9ce [ruby/prism] Documentation for pm_strncasecmp
26934263b7
2023-11-01 13:10:29 -04:00
Kevin Newton
7bf3d9343f [ruby/prism] parse_inline_comments -> parse_comments
bd4d248fd6
2023-10-30 15:53:37 +00:00
Kevin Newton
c201dbc0ad [ruby/prism] Prism.parse_inline_comments
5b72f84480
2023-10-27 18:09:14 +00:00
Kevin Newton
d1bb858d47 [ruby/prism] Match existing Ruby prettyprint
6d8358c083
2023-10-26 15:19:43 -04:00
Jemma Issroff
0abf2d86b9 [PRISM] Move pm_scope_node_init to prism_compile.c
pm_scope_node_init is only used for CRuby, so should not live in the
ruby/prism repo. We will merge the changes here first so they're
not breaking, and will then remove from ruby/prism
2023-10-25 18:18:35 -03:00
Jemma Issroff
a9512e80b0 Revert "Revert "[ruby/prism] Change ScopeNode to point to previous ScopeNode""
This reverts commit fd87372a74.
2023-10-18 17:16:11 -07:00
Jemma Issroff
fd87372a74
Revert "[ruby/prism] Change ScopeNode to point to previous ScopeNode"
This reverts commit 67a987f82b.
2023-10-16 15:20:26 -07:00
Jemma Issroff
67a987f82b [ruby/prism] Change ScopeNode to point to previous ScopeNode
Amend ScopeNode to point to previous ScopeNode, and to have void*
pointers to constants and index_lookup_table

0534324312
2023-10-16 21:53:11 +00:00
Kevin Newton
37d958eaf4 Remove old unescaping code 2023-10-13 15:31:30 -04:00
Kevin Newton
4f73a7c2f7 Sync to prism rename commits 2023-09-27 13:57:38 -04:00
Kevin Newton
8ab56869a6 Rename YARP filepaths to prism filepaths 2023-09-27 13:57:38 -04:00
Renamed from yarp/yarp.h (Browse further)