| Class | YARD::Handlers::Ruby::Legacy::Base |
| In: |
lib/yard/handlers/ruby/legacy/base.rb
|
| Parent: | Handlers::Base |
The string value of a token. For example, the return value for the symbol :sym would be :sym. The return value for a string "foo #{bar}" would be the literal "foo #{bar}" without any interpolation. The return value of the identifier ‘test’ would be the same value: ‘test’. Here is a list of common types and their return values:
@example
tokval(TokenList.new('"foo"').first) => "foo"
tokval(TokenList.new(':foo').first) => :foo
tokval(TokenList.new('CONSTANT').first, RubyToken::TkId) => "CONSTANT"
tokval(TokenList.new('identifier').first, RubyToken::TkId) => "identifier"
tokval(TokenList.new('3.25').first) => 3.25
tokval(TokenList.new('/xyz/i').first) => /xyz/i
@param [Token] token The token of the class
@param [Array<Class<Token>>, Symbol] accepted_types
The allowed token types that this token can be. Defaults to [{TkVal}].
A list of types would be, for example, [{TkSTRING}, {TkSYMBOL}], to return
the token's value if it is either of those types. If +TkVal+ is accepted,
+TkNode+ is also accepted.
Certain symbol keys are allowed to specify multiple types in one fell swoop.
These symbols are:
:string => +TkSTRING+, +TkDSTRING+, +TkDXSTRING+ and +TkXSTRING+
:attr => +TkSYMBOL+ and +TkSTRING+
:identifier => +TkIDENTIFIER, +TkFID+ and +TkGVAR+.
:number => +TkFLOAT+, +TkINTEGER+
@return [Object] if the token is one of the accepted types, in its real value form.
It should be noted that identifiers and constants are kept in String form.
@return [nil] if the token is not any of the specified accepted types
Returns a list of symbols or string values from a statement. The list must be a valid comma delimited list, and values will only be returned to the end of the list only.
Example:
attr_accessor :a, 'b', :c, :d => ['a', 'b', 'c', 'd'] attr_accessor 'a', UNACCEPTED_TYPE, 'c' => ['a', 'c']
The tokval list of a {TokenList} of the above code would be the {tokval} value of :a, ‘b’, :c and :d.
It should also be noted that this function stops immediately at any ruby keyword encountered:
"attr_accessor :a, :b, :c if x == 5" => ['a', 'b', 'c']
@param [TokenList] tokenlist The list of tokens to process. @param [Array<Class<Token>>] accepted_types passed to {tokval} @return [Array<String>] the list of tokvalues in the list. @return [Array<EMPTY>] if there are no symbols or Strings in the list @see tokval