Class: Ripper::RubyBuilder::Token
- Includes:
- Comparable
- Defined in:
- lib/ripper/ruby_builder/token.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
Returns the value of attribute position.
-
#prolog ⇒ Object
Returns the value of attribute prolog.
-
#token ⇒ Object
Returns the value of attribute token.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #comment? ⇒ Boolean
- #heredoc? ⇒ Boolean
-
#initialize(type = nil, token = nil, position = nil) ⇒ Token
constructor
A new instance of Token.
- #keyword? ⇒ Boolean
- #known? ⇒ Boolean
- #newline? ⇒ Boolean
- #opener? ⇒ Boolean
- #operator? ⇒ Boolean
- #prolog? ⇒ Boolean
- #separator? ⇒ Boolean
- #to_identifier ⇒ Object
- #to_sexp ⇒ Object
- #whitespace? ⇒ Boolean
Constructor Details
#initialize(type = nil, token = nil, position = nil) ⇒ Token
Returns a new instance of Token.
19 20 21 22 23 |
# File 'lib/ripper/ruby_builder/token.rb', line 19 def initialize(type = nil, token = nil, position = nil) @type = token_type(type, token) @token = token @position = position if position end |
Instance Attribute Details
#position ⇒ Object
Returns the value of attribute position.
17 18 19 |
# File 'lib/ripper/ruby_builder/token.rb', line 17 def position @position end |
#prolog ⇒ Object
Returns the value of attribute prolog.
17 18 19 |
# File 'lib/ripper/ruby_builder/token.rb', line 17 def prolog @prolog end |
#token ⇒ Object
Returns the value of attribute token.
17 18 19 |
# File 'lib/ripper/ruby_builder/token.rb', line 17 def token @token end |
#type ⇒ Object
Returns the value of attribute type.
17 18 19 |
# File 'lib/ripper/ruby_builder/token.rb', line 17 def type @type end |
Instance Method Details
#<=>(other) ⇒ Object
73 74 75 |
# File 'lib/ripper/ruby_builder/token.rb', line 73 def <=>(other) position <=> (other.respond_to?(:position) ? other.position : other) end |
#comment? ⇒ Boolean
57 58 59 |
# File 'lib/ripper/ruby_builder/token.rb', line 57 def comment? type == :@comment end |
#heredoc? ⇒ Boolean
61 62 63 |
# File 'lib/ripper/ruby_builder/token.rb', line 61 def heredoc? type == :@heredoc end |
#keyword? ⇒ Boolean
37 38 39 |
# File 'lib/ripper/ruby_builder/token.rb', line 37 def keyword? KEYWORDS.include?(type) end |
#known? ⇒ Boolean
53 54 55 |
# File 'lib/ripper/ruby_builder/token.rb', line 53 def known? keyword? || operator? || opener? || whitespace? || [:@backtick].include?(type) end |
#newline? ⇒ Boolean
25 26 27 |
# File 'lib/ripper/ruby_builder/token.rb', line 25 def newline? NEWLINE.include?(type) end |
#opener? ⇒ Boolean
33 34 35 |
# File 'lib/ripper/ruby_builder/token.rb', line 33 def opener? OPENERS.include?(type) end |
#operator? ⇒ Boolean
41 42 43 |
# File 'lib/ripper/ruby_builder/token.rb', line 41 def operator? OPERATORS.include?(type) end |
#prolog? ⇒ Boolean
49 50 51 |
# File 'lib/ripper/ruby_builder/token.rb', line 49 def prolog? whitespace? or separator? or heredoc? end |
#separator? ⇒ Boolean
45 46 47 |
# File 'lib/ripper/ruby_builder/token.rb', line 45 def separator? SEPARATORS.include?(type) end |
#to_identifier ⇒ Object
69 70 71 |
# File 'lib/ripper/ruby_builder/token.rb', line 69 def to_identifier Ruby::Identifier.new(token, position, prolog) end |
#to_sexp ⇒ Object
65 66 67 |
# File 'lib/ripper/ruby_builder/token.rb', line 65 def to_sexp [type, token, [row + 1, column]] end |
#whitespace? ⇒ Boolean
29 30 31 |
# File 'lib/ripper/ruby_builder/token.rb', line 29 def whitespace? WHITESPACE.include?(type) end |