Skip to content

Commit 130c37d

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/prism] More docs improvements
(ruby/prism#3910) * Update C call seqs * Prefixing them with self is unusual * Also use `.` instead of `::` to refer to class methods * Capitalize location in docs It allows it to be linked to in docs * Miscelanous other doc tweaks * Format code as code * Nodoc some missed methods * Fix method reference * Really try to nodoc ffi module The previous approach was wrong, to nodoc the class methods it must be specified at the module itself. As a result, the private methods like `dump_options` are also removed. * Remove some def-style comments They are mostly redundant with the method signature and don't look great when rendered. Still remaining on nodes. I will improve docs for them in a separate PR ruby/prism@94e5525521
1 parent 545db49 commit 130c37d

9 files changed

Lines changed: 172 additions & 179 deletions

File tree

lib/prism.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ def initialize(version)
5656
end
5757

5858
# :call-seq:
59-
# Prism::lex_compat(source, **options) -> LexCompat::Result
59+
# lex_compat(source, **options) -> LexCompat::Result
6060
#
6161
# Returns a parse result whose value is an array of tokens that closely
62-
# resembles the return value of Ripper::lex.
62+
# resembles the return value of Ripper.lex.
6363
#
64-
# For supported options, see Prism::parse.
64+
# For supported options, see Prism.parse.
6565
def self.lex_compat(source, **options)
6666
LexCompat.new(source, **options).result # steep:ignore
6767
end
6868

6969
# :call-seq:
70-
# Prism::load(source, serialized, freeze) -> ParseResult
70+
# load(source, serialized, freeze) -> ParseResult
7171
#
7272
# Load the serialized AST using the source as a reference into a tree.
7373
def self.load(source, serialized, freeze = false)

lib/prism/desugar_compiler.rb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -254,137 +254,137 @@ def desugar # :nodoc:
254254
# DesugarCompiler is a compiler that desugars Ruby code into a more primitive
255255
# form. This is useful for consumers that want to deal with fewer node types.
256256
class DesugarCompiler < MutationCompiler
257-
# @@foo &&= bar
257+
# `@@foo &&= bar`
258258
#
259259
# becomes
260260
#
261-
# @@foo && @@foo = bar
261+
# `@@foo && @@foo = bar`
262262
def visit_class_variable_and_write_node(node)
263263
node.desugar
264264
end
265265

266-
# @@foo ||= bar
266+
# `@@foo ||= bar`
267267
#
268268
# becomes
269269
#
270-
# defined?(@@foo) ? @@foo : @@foo = bar
270+
# `defined?(@@foo) ? @@foo : @@foo = bar`
271271
def visit_class_variable_or_write_node(node)
272272
node.desugar
273273
end
274274

275-
# @@foo += bar
275+
# `@@foo += bar`
276276
#
277277
# becomes
278278
#
279-
# @@foo = @@foo + bar
279+
# `@@foo = @@foo + bar`
280280
def visit_class_variable_operator_write_node(node)
281281
node.desugar
282282
end
283283

284-
# Foo &&= bar
284+
# `Foo &&= bar`
285285
#
286286
# becomes
287287
#
288-
# Foo && Foo = bar
288+
# `Foo && Foo = bar`
289289
def visit_constant_and_write_node(node)
290290
node.desugar
291291
end
292292

293-
# Foo ||= bar
293+
# `Foo ||= bar`
294294
#
295295
# becomes
296296
#
297-
# defined?(Foo) ? Foo : Foo = bar
297+
# `defined?(Foo) ? Foo : Foo = bar`
298298
def visit_constant_or_write_node(node)
299299
node.desugar
300300
end
301301

302-
# Foo += bar
302+
# `Foo += bar`
303303
#
304304
# becomes
305305
#
306-
# Foo = Foo + bar
306+
# `Foo = Foo + bar`
307307
def visit_constant_operator_write_node(node)
308308
node.desugar
309309
end
310310

311-
# $foo &&= bar
311+
# `$foo &&= bar`
312312
#
313313
# becomes
314314
#
315-
# $foo && $foo = bar
315+
# `$foo && $foo = bar`
316316
def visit_global_variable_and_write_node(node)
317317
node.desugar
318318
end
319319

320-
# $foo ||= bar
320+
# `$foo ||= bar`
321321
#
322322
# becomes
323323
#
324-
# defined?($foo) ? $foo : $foo = bar
324+
# `defined?($foo) ? $foo : $foo = bar`
325325
def visit_global_variable_or_write_node(node)
326326
node.desugar
327327
end
328328

329-
# $foo += bar
329+
# `$foo += bar`
330330
#
331331
# becomes
332332
#
333-
# $foo = $foo + bar
333+
# `$foo = $foo + bar`
334334
def visit_global_variable_operator_write_node(node)
335335
node.desugar
336336
end
337337

338-
# @foo &&= bar
338+
# `@foo &&= bar`
339339
#
340340
# becomes
341341
#
342-
# @foo && @foo = bar
342+
# `@foo && @foo = bar`
343343
def visit_instance_variable_and_write_node(node)
344344
node.desugar
345345
end
346346

347-
# @foo ||= bar
347+
# `@foo ||= bar`
348348
#
349349
# becomes
350350
#
351-
# @foo || @foo = bar
351+
# `@foo || @foo = bar`
352352
def visit_instance_variable_or_write_node(node)
353353
node.desugar
354354
end
355355

356-
# @foo += bar
356+
# `@foo += bar`
357357
#
358358
# becomes
359359
#
360-
# @foo = @foo + bar
360+
# `@foo = @foo + bar`
361361
def visit_instance_variable_operator_write_node(node)
362362
node.desugar
363363
end
364364

365-
# foo &&= bar
365+
# `foo &&= bar`
366366
#
367367
# becomes
368368
#
369-
# foo && foo = bar
369+
# `foo && foo = bar`
370370
def visit_local_variable_and_write_node(node)
371371
node.desugar
372372
end
373373

374-
# foo ||= bar
374+
# `foo ||= bar`
375375
#
376376
# becomes
377377
#
378-
# foo || foo = bar
378+
# `foo || foo = bar`
379379
def visit_local_variable_or_write_node(node)
380380
node.desugar
381381
end
382382

383-
# foo += bar
383+
# `foo += bar`
384384
#
385385
# becomes
386386
#
387-
# foo = foo + bar
387+
# `foo = foo + bar`
388388
def visit_local_variable_operator_write_node(node)
389389
node.desugar
390390
end

lib/prism/ffi.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# autoloaded from within a non-main Ractor.
1313
require "prism/serialize" if defined?(Ractor)
1414

15-
module Prism
15+
module Prism # :nodoc:
1616
module LibRubyParser # :nodoc:
1717
extend FFI::Library
1818

@@ -233,7 +233,7 @@ def self.with_file(filepath)
233233
# The version constant is set by reading the result of calling pm_version.
234234
VERSION = LibRubyParser.pm_version.read_string.freeze
235235

236-
class << self # :nodoc:
236+
class << self
237237
# Mirror the Prism.dump API by using the serialization API.
238238
def dump(source, **options)
239239
LibRubyParser::PrismString.with_string(source) { |string| dump_common(string, options) }

lib/prism/parse_result.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def adjoin(string)
519519
# This represents a comment that was encountered during parsing. It is the
520520
# base class for all comment types.
521521
class Comment
522-
# The location of this comment in the source.
522+
# The Location of this comment in the source.
523523
attr_reader :location
524524

525525
# Create a new comment object with the given location.
@@ -556,7 +556,7 @@ def inspect # :nodoc:
556556
# EmbDocComment objects correspond to comments that are surrounded by =begin
557557
# and =end.
558558
class EmbDocComment < Comment
559-
# This can only be true for inline comments.
559+
# Returns false. This can only be true for inline comments.
560560
def trailing?
561561
false
562562
end
@@ -670,9 +670,9 @@ def inspect # :nodoc:
670670
end
671671
end
672672

673-
# This represents the result of a call to ::parse or ::parse_file. It contains
674-
# the requested structure, any comments that were encounters, and any errors
675-
# that were encountered.
673+
# This represents the result of a call to Prism.parse or Prism.parse_file.
674+
# It contains the requested structure, any comments that were encounters,
675+
# and any errors that were encountered.
676676
class Result
677677
# The list of comments that were encountered during parsing.
678678
attr_reader :comments

lib/prism/pattern.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Pattern
4141
class CompilationError < StandardError
4242
# Create a new CompilationError with the given representation of the node
4343
# that caused the error.
44-
def initialize(repr)
44+
def initialize(repr) # :nodoc:
4545
super(<<~ERROR)
4646
prism was unable to compile the pattern you provided into a usable
4747
expression. It failed on to understand the node represented by:

prism/api_pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pack_encoding_to_ruby(pm_pack_encoding encoding) {
173173

174174
/**
175175
* call-seq:
176-
* Pack::parse(version, variant, source) -> Format
176+
* parse(version, variant, source) -> Format
177177
*
178178
* Parse the given source and return a format object.
179179
*/

0 commit comments

Comments
 (0)