Commit graph

766 commits

Author SHA1 Message Date
Stan Lo
cbc40bb130 Sync rdoc 2024-08-05 08:27:45 +08:00
tomoya ishida
16b0242808 [ruby/rdoc] Add new ruby parser that uses Prism
(https://github.com/ruby/rdoc/pull/1144)

* Add a new ruby parser RDoc::Parser::PrismRuby

* Add a new ruby parser testcase independent from parser's internal implementation

* unknown meta method

* Use MethodSignatureVisitor only to scan params, block_params and calls_super

* Add calls_super test

* Drop ruby 2.6. Prism requires ruby >= 2.7

* Remove duplicated documentation comment from prism_ruby.rb

* Add test for wrong argument passed to metaprogramming method

* Rename visit_call_[DSL_METHOD_NAME] to make it distinguishable from visit_[NODE_TYPE]_node

* Method receiver switch of true/false/nil to a case statement

* Extract common part of add_method(by def keyword) and add meta_comment method

* Reuse consecutive comments array when collecting comments

* Simplify DSL call_node handling

* Refactor extracting method visibility arguments

fde99f1be6
2024-07-31 20:50:00 +00:00
Stan Lo
27c22f822a [ruby/rdoc] Drop unnecessary file_name parameter from Parser.for
method.
(https://github.com/ruby/rdoc/pull/1135)

* Unify top_level creation in tests

* Remove unnecessary file_name param from Parser.for

It should be always the same as the top_level's absolute_name, so there's
no point of taking it as a separate parameter.

97c497dfbb
2024-07-31 14:36:41 +00:00
Burdette Lamar
63bdf2d725 [ruby/rdoc] [DOC] Mods about markup formats
(https://github.com/ruby/rdoc/pull/1143)

011de3f2fd
2024-07-29 13:16:18 +00:00
Hartley McGuire
d0c17cbd09
Require space between hash/content in ATX heading (#1140)
While writing some Markdown documentation for Rails, I came across an
interesting case where trying to link to an instance method at the start
of a line would instead parse as an H1 heading:

```markdown
#response_body=
```

Expected:

```html
<a href=""><code>#response_body=</code></a>
```

Actual:

```html
<h1>response_body=</h1>
```

According to the CommonMark spec:

> At least one space or tab is required between the # characters and the
> heading’s contents, unless the heading is empty. Note that many
> implementations currently do not require the space. However, the space
> was required by the original ATX implementation, and it helps prevent
> things like the following from being parsed as headings:
>
> Example 64

So while some implementations do not follow this requirement, I believe
RDoc should because it makes it easy to write text similar to Example 64
(which was used in the new test) and it also enables automatically
linking to instance methods at the start of a line.
2024-07-18 09:40:01 +09:00
Stan Lo
239d54dfbc [ruby/rdoc] Improve rubocop setup
(https://github.com/ruby/rdoc/pull/1139)

* Rename rake rubocop to rake format_generated_files

* Add rubocop rules to ensure spaces are applied consistently

* Improve rubocop related CI workflows

27932d001c
2024-07-17 20:43:08 +00:00
nicholas a. evans
e165d92d37
[ruby/rdoc] Drop reimplementation of Ripper lex state
(https://github.com/ruby/rdoc/pull/1118)

* Drop reimplementation of Ripper lex state

This code was for ruby 2.4 compatibility, but rdoc dropped support for
ruby 2.4 about three years ago, in f480b970c.  This code was almost half
of the lines of code in rdoc/parser/ripper_state_lex.

* Remove unused Ripper constants and const_defined?

This was mostly copied from the diff in @st0012's PR comment.  The
remaining constants have been updated to get their value directly from
Ripper.

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Use Ripper::EXPR_LABEL directly

Since this is only used from outside RipperStateLex, there's no longer
any benefit to using the indirect reference rather than just going
straight to Ripper.

---------

dd8c216263

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-07-16 07:22:11 +09:00
Stan Lo
d7af8afe1b [ruby/rdoc] Group code object files into the same directory
(https://github.com/ruby/rdoc/pull/1114)

It's hard to distinguish code object classes by their file names alone.
And given that we have 18 such classes, it'd make the codebase a lot
easier to understand if we grouped them into a single directory.

Given that these classes are all autoloaded in `lib/rdoc.rb` instead
of required individually, this change should have minimum impact on
projects using RDoc as they generally just require `rdoc`, not individual
files. An example is Rails' `sdoc`:
https://github.com/rails/sdoc/blob/main/lib/sdoc/rdoc_monkey_patches.rb

4211292ffe
2024-07-02 10:15:00 +00:00
Yudai Takada
15ceb95d78 [ruby/rdoc] Fix some typos (https://github.com/ruby/rdoc/pull/1129)
* constist ==> consist

* Tidyness ==> Tidiness

* Currentry ==> Currently

* valus ==> values

8412705721
2024-07-01 11:08:37 +09:00
Hiroshi SHIBATA
f23c96581f
Update generated code from 5c7ea6fa15 2024-05-30 18:00:25 +09:00
Adam Daniels
01aa77faa2 [ruby/rdoc] Abort with error message if --dump argument invalid
When --dump=FILE is passed a path that does not exist or is not
readable, it silently fails.

0536b83c46
2024-05-30 00:09:22 +00:00
Hiroshi SHIBATA
2cc047df9a [ruby/rdoc] Bump up 6.7.0
a667e616e1
2024-05-23 01:17:32 +00:00
Koichi Sasada
9180e33ca3 show warning for unused block
With verbopse mode (-w), the interpreter shows a warning if
a block is passed to a method which does not use the given block.

Warning on:

* the invoked method is written in C
* the invoked method is not `initialize`
* not invoked with `super`
* the first time on the call-site with the invoked method
  (`obj.foo{}` will be warned once if `foo` is same method)

[Feature #15554]

`Primitive.attr! :use_block` is introduced to declare that primitive
functions (written in C) will use passed block.

For minitest, test needs some tweak, so use
ea9caafc07
for `test-bundled-gems`.
2024-04-15 12:08:07 +09:00
Hiroshi SHIBATA
c5ac18bbf4 [ruby/rdoc] Bump up 6.6.3.1
ffbf8ae089
2024-03-21 04:38:21 +00:00
Hiroshi SHIBATA
385c31e770 [ruby/rdoc] Fix NoMethodError for start_with
e21dfccb4a
2024-03-21 04:18:26 +00:00
Hiroshi SHIBATA
ee1ad009f3 [ruby/rdoc] Bump up 6.6.3
d98baf4917
2024-03-21 04:04:40 +00:00
Nobuyoshi Nakada
3d353afeb0 [ruby/rdoc] Filter marshaled objets
da7a0c7553
2024-03-21 04:04:40 +00:00
Adam Daniels
3fcab3cddf [ruby/rdoc] Use readline history when ri is interactive
d0074a23cc
2024-03-15 00:27:01 +00:00
Hartley McGuire
08961ce8e3 [ruby/rdoc] Allow rich definition list labels for Markdown
Previously, any sort of "rich" markup for a definition list's label
would cause the Markdown parser to not recognize a definition list:

```ruby
md = <<~md
`one`
:    This is a definition
md

doc = RDoc::Markdown.parse(md)
doc # => [doc: [para: "<code>one</code>\n: This is a definition"]]
```

This commit tweaks the grammar for Markdown definition lists so that
labels can include "rich" markup such as bold (`**`), code (```), etc:

```ruby
md = <<~md
`one`
:    This is a definition
md

doc = RDoc::Markdown.parse(md)
doc # => [doc: [list: NOTE [item: ["<code>one</code>"]; [para: "This is a definition"]]]]
```

The [PHP Markdown Extra][1] Spec does not seem to specify whether or not
this should be allowed, but it is allowed in the RDoc format:

```ruby
rdoc = <<~rdoc
+code+::
    This is a definition
rdoc

doc = RDoc::Markup.parse(rdoc)
doc # => [doc: [list: NOTE [item: ["+code+"]; [para: "This is a definition"]]]]
```

so accepting this change increases the parity of the two formats.

[1]: https://michelf.ca/projects/php-markdown/extra/#def-list

8f943bbba4
2024-03-11 20:00:51 +09:00
Hartley McGuire
5ac6194c2b [ruby/rdoc] Fix ToRdoc generating incorrect {label,name}-lists
Previously, trying to round-trip label-list and name-lists with the
ToRdoc converter was not possible:

```ruby
doc = <<~RDOC
foo ::
bar ::
  hi
RDOC

markup = RDoc::Markup.parse(doc)
markup # => [doc: [list: NOTE [item: ["foo ", "bar"]; [para: "hi"]]]]

rt = RDoc::Markup::ToRdoc.new.convert(markup)
rt # => "foo\nbar:\n  hi\n\n"

rt_markup = RDoc::Markup.parse(rt)
rt_markup # => [doc: [para: "foo ", "bar:"], [verb: "hi\n"]]
```

This commit addresses the issue by fixing ToRdoc to generate output that
can be properly reparsed by RDoc. ToRdoc tests additionally needed to be
updated for the new output.

The old implementation of `accept_list_item_start` was copied to ToBs
because those tests did not pass with the new changes and I am
unfamiliar with the `backspace` format.

After:

```ruby
doc = <<~RDOC
foo ::
bar ::
  hi
RDOC

markup = RDoc::Markup.parse(doc)
markup # => [doc: [list: NOTE [item: ["foo ", "bar"]; [para: "hi"]]]]

rt = RDoc::Markup::ToRdoc.new.convert(markup)
rt # => "foo::\nbar::\n  hi\n\n"

rt_markup = RDoc::Markup.parse(rt)
rt_markup # => [doc: [list: NOTE [item: ["foo", "bar"]; [para: "hi"], blankline]]]
```

c6c51aa900
2024-03-09 03:50:09 +00:00
Hartley McGuire
4756eaf5aa [ruby/rdoc] Fix ToMarkdown missing newlines for label-lists
Previously, using ToMarkdown on a label-list would generate output that
could not be reparsed by the RDoc::Markdown parser:

```
md = <<~MD
apple
: a red fruit

banana
: a yellow fruit
MD

doc = RDoc::Markdown.parse(md)
doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit"]], [item: ["banana"]; [para: "a yellow fruit"]]]]

new_md = doc.accept(RDoc::Markup::ToMarkdown.new)
new_md # => "apple\n:   a red fruit\nbanana\n:   a yellow fruit\n\n"

new_doc = RDoc::Markdown.parse(new_md)
new_doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit\nbanana\n: a yellow fruit"]]]]
```

The issue is that the [PHP Markdown Extra spec][1] requires a newline
after each definition list item, but ToMarkdown was not putting newlines
between label-list items.

This commit fixes the issue by properly appending a newline after each
label-list item so that the output of ToMarkdown can be reparsed by
RDoc::Markdown:

```
md = <<~MD
apple
: a red fruit

banana
: a yellow fruit
MD

doc = RDoc::Markdown.parse(mdoc)
doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit"]], [item: ["banana"]; [para: "a yellow fruit"]]]]

new_md = doc.accept(RDoc::Markup::ToMarkdown.new)
new_md # => "apple\n:   a red fruit\n\nbanana\n:   a yellow fruit\n\n"

new_doc = RDoc::Markdown.parse(new_md)
new_doc # => [doc: [list: NOTE [item: ["apple"]; [para: "a red fruit"]], [item: ["banana"]; [para: "a yellow fruit"]]]]
```

[1]: https://michelf.ca/projects/php-markdown/extra/#def-list

c65266437c
2024-03-08 10:13:04 +00:00
Petrik
2a57e6e6ed [ruby/rdoc] Don't document aliases with trailing :nodoc directive
Attribute readers and writers can be marked as `:nodoc` to keep them
undocumented:

```ruby
attr_reader :name # :nodoc:
```

For aliases this behaviour should be the same:

```ruby
alias_method :old :new # :nodoc:
```

30f14e8271
2024-02-09 01:07:17 +00:00
Nobuyoshi Nakada
7558625be1 [ruby/rdoc] Respect modeline to detect parser
485468f06f
2024-01-11 06:55:39 +00:00
Nobuyoshi Nakada
7fcc6f04ac [ruby/rdoc] Visibility should begin from public for each scope
Even for singleton class definition such as `class << self` that
shares the same container with the outer scope, its visibility is
separated and set to `public` by default.

baf26363b9
2024-01-07 11:39:46 +00:00
Nobuyoshi Nakada
2325b72cf3 [ruby/rdoc] Singleton method visibility should be isolated
Each singleton method definition of the form `def recv.method` has
visibility separate from the outer scope and is set to `public` by
default.

810913a7ea
2024-01-07 11:39:45 +00:00
Nobuyoshi Nakada
f6847e9456 [ruby/rdoc] Ignore locale at write_options
`@locale` is set from `@locale_name` and loaded from `@locale_dir`
after `write_options`, and `RDoc::I18n::Locale` does not seem to
expected to be loaded.

fd610f7023
2024-01-06 10:17:49 +00:00
Nobuyoshi Nakada
569a06aa2f [ruby/rdoc] Allow empty name rdoc-ref as a local link
914a6af137
2023-12-31 15:19:50 +00:00
Nobuyoshi Nakada
e324953090 [ruby/rdoc] Fix support for rb_file_const and rb_curses_define_const
Constant definitions using these functions have been supported, but
since RDoc::Parser::C#gen_const_table did not consider other than
`rb_define_const` the documents for them have not been found, without
`Document-const` direvtive.

Fixes https://github.com/ruby/rdoc/issues/1067

cdad51a60b
2023-12-25 21:12:49 +09:00
Hiroshi SHIBATA
6c7c4ac407 [ruby/rdoc] Bump up v6.6.2
895f1affc0
2023-12-16 11:42:30 +08:00
Nobuyoshi Nakada
20f4f00764 [ruby/rdoc] [DOC] nodoc for probably internal methods
f7dd147a8c
2023-12-16 00:26:39 +09:00
Nobuyoshi Nakada
e15d690db1 [ruby/rdoc] [DOC] Add missing documents
e4c90340d0
2023-12-16 00:26:37 +09:00
Nobuyoshi Nakada
b257181ccc [ruby/rdoc] Remove unused method RDoc::Encoding.remove_frozen_string_literal
7a8e9a97fa
2023-12-16 00:25:51 +09:00
Nobuyoshi Nakada
e03e872eea [ruby/rdoc] Only word-ending colon separates new definition
When followed by non-space characters, rather it looks like a URL or a
path name on Windows.

72c6560773
2023-12-06 09:35:44 +00:00
Nobuyoshi Nakada
379f06797d [ruby/rdoc] Needs more backslash to match escaping backslashs
1904e9076d
2023-12-06 09:35:43 +00:00
Nobuyoshi Nakada
113f5d7fd7 [ruby/rdoc] Allow any single-word token upto 2 before C method implementation
Previously only unknown word `intern` is allowed between a single-word
token before a C method.  Now any single-word token, such as `inline`
which is used for `ArithmeticSequence` in enumerator.c, is allowed
instead.

3a214c1dd1
2023-12-05 08:48:19 +00:00
Nobuyoshi Nakada
c0baa3783f [ruby/rdoc] Reduce matched substring allocations
aaed688a97
2023-12-05 08:48:18 +00:00
Hiroshi SHIBATA
d691b1a141 [ruby/rdoc] Bump up 6.6.1
7cf353a696
2023-12-05 07:37:08 +00:00
Toshimaru
56ccad060d [ruby/rdoc] Early return when token_stream is nil
04f75d8516

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2023-12-05 06:21:52 +00:00
toshimaru
cda431f538 [ruby/rdoc] fix: fix NoMethodError when token_stream is nil
The change in #1055 might be a breaking change.
So, just simply wrap `token_stream` with `Array`

d8c19d7fa1

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-12-05 06:21:51 +00:00
Nobuyoshi Nakada
c9c1670f7e [ruby/rdoc] Markup punctuations need to be separated with a space
83f0149fc1
2023-12-02 12:40:12 +00:00
Nobuyoshi Nakada
7973eb7c3f [ruby/rdoc] [DOC] Slightly decorate em and strong
2161157205
2023-11-27 16:07:03 +00:00
Nobuyoshi Nakada
196c4aeb76 [ruby/rdoc] Place a space between certain character class letters only
1f568e049d
2023-11-27 15:58:31 +00:00
Nobuyoshi Nakada
e374512682 [ruby/rdoc] Revert "chore: Remove unnecessary argument for join method"
This reverts commit 4a1c74bc0a.

Since RDoc still supports ruby 2.6 which has not deprecated `$,`, the
argument of `Array#join` is not unnecessary yet.

72897d32ed
2023-11-16 02:22:08 +00:00
toshimaru
8d160b9350 [ruby/rdoc] chore: Remove unnecessary argument for join method
4a1c74bc0a
2023-11-16 01:43:12 +00:00
toshimaru
72242e69aa [ruby/rdoc] fix: Fix NoMethodError for tokens_to_s method
Calling `tokens_to_s` gets an error if `token_stream` is nil:

```
undefined method `compact' for nil:NilClass (NoMethodError)
```

So, fall back to an empty array if `@token_stream` is nil.

452e4a2600
2023-11-16 01:43:12 +00:00
Nobuyoshi Nakada
9935512275 [ruby/rdoc] Fix TIDYLINK after braces
(https://github.com/ruby/rdoc/pull/1015)

TIDYLINK multi-word label should not include braces.

41ad3191e9
2023-11-14 07:59:56 +00:00
Hiroshi SHIBATA
7a6c72e03d
Update rdoc parsers generated by racc-1.7.3 2023-11-06 17:53:00 +09:00
Hiroshi SHIBATA
ee13da3e2a [ruby/rdoc] Bump up 6.6.0
9c14229876
2023-11-06 17:40:34 +09:00
tompng
2a8ac8ead5 [ruby/rdoc] Delay DidYouMean until NotFoundError#message is called
b59ca2f981
2023-10-17 11:07:57 +00:00
BurdetteLamar
b4ab013b27
[DOC] Link fixes 2023-10-03 16:31:34 +09:00