mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[DOC] Fix AST documents
- Fix indents of `tokens`, to make the contents of Token a list - Move the example of `tokens` to separate from the above list - Markup keyword argument and method name
This commit is contained in:
parent
fb7598fb3e
commit
e9d6d2a579
1 changed files with 11 additions and 10 deletions
21
ast.rb
21
ast.rb
|
@ -139,18 +139,19 @@ module RubyVM::AbstractSyntaxTree
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# node.tokens -> array
|
# node.tokens -> array
|
||||||
#
|
#
|
||||||
# Returns tokens corresponding to the location of the node.
|
# Returns tokens corresponding to the location of the node.
|
||||||
# Returns nil if keep_tokens is not enabled when parse method is called.
|
# Returns +nil+ if +keep_tokens+ is not enabled when #parse method is called.
|
||||||
# Token is an array of:
|
|
||||||
#
|
|
||||||
# - id
|
|
||||||
# - token type
|
|
||||||
# - source code text
|
|
||||||
# - location [first_lineno, first_column, last_lineno, last_column]
|
|
||||||
#
|
#
|
||||||
# root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2", keep_tokens: true)
|
# root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2", keep_tokens: true)
|
||||||
# root.tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...]
|
# root.tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...]
|
||||||
# root.tokens.map{_1[2]}.join # => "x = 1 + 2"
|
# root.tokens.map{_1[2]}.join # => "x = 1 + 2"
|
||||||
|
#
|
||||||
|
# Token is an array of:
|
||||||
|
#
|
||||||
|
# - id
|
||||||
|
# - token type
|
||||||
|
# - source code text
|
||||||
|
# - location [ first_lineno, first_column, last_lineno, last_column ]
|
||||||
def tokens
|
def tokens
|
||||||
return nil unless all_tokens
|
return nil unless all_tokens
|
||||||
|
|
||||||
|
@ -166,8 +167,8 @@ module RubyVM::AbstractSyntaxTree
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# node.all_tokens -> array
|
# node.all_tokens -> array
|
||||||
#
|
#
|
||||||
# Returns all tokens for the input script regardless the receiver node.
|
# Returns all tokens for the input script regardless the receiver node.
|
||||||
# Returns nil if keep_tokens is not enabled when parse method is called.
|
# Returns +nil+ if +keep_tokens+ is not enabled when #parse method is called.
|
||||||
#
|
#
|
||||||
# root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2", keep_tokens: true)
|
# root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2", keep_tokens: true)
|
||||||
# root.all_tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...]
|
# root.all_tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue