Class: Rubycc::Front::Token
- Inherits:
-
Object
- Object
- Rubycc::Front::Token
- Defined in:
- lib/rubycc/front/token.rb
Overview
A single lexical token. type is one of :num, :float, :ident, :keyword,
:punct, :string, :eof. value is an Integer for :num, a Ruby Float for
:float (a floating constant), an ASCII-8BIT String of the escape-resolved
bytes for :string, a String for :ident/:keyword/:punct, and nil for :eof.
base (10/8/16) and suffix accompany a numeric constant so the parser
can fix its type: an integer :num carries a base and a normalized u/l
suffix run ("", "u", "ul") per 6.4.4.1, while a :float carries no base but
a normalized floating suffix ("" for double, "f" for float, "l" for long
double, itself treated as double). Both are nil on every other token (a
character constant is a :num with base 10 and no suffix). The remaining
fields locate the token in the source for diagnostics.
Constant Summary collapse
- TYPES =
%i[num float ident keyword punct string eof].freeze
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#source_line ⇒ Object
readonly
Returns the value of attribute source_line.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #eof? ⇒ Boolean
-
#initialize(type:, value:, filename:, line:, column:, source_line:, base: nil, suffix: nil) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ Object
- #keyword?(str) ⇒ Boolean
- #punct?(str) ⇒ Boolean
Constructor Details
#initialize(type:, value:, filename:, line:, column:, source_line:, base: nil, suffix: nil) ⇒ Token
Returns a new instance of Token.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rubycc/front/token.rb', line 21 def initialize(type:, value:, filename:, line:, column:, source_line:, base: nil, suffix: nil) @type = type @value = value @filename = filename @line = line @column = column @source_line = source_line @base = base @suffix = suffix end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
19 20 21 |
# File 'lib/rubycc/front/token.rb', line 19 def base @base end |
#column ⇒ Object (readonly)
Returns the value of attribute column.
19 20 21 |
# File 'lib/rubycc/front/token.rb', line 19 def column @column end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
19 20 21 |
# File 'lib/rubycc/front/token.rb', line 19 def filename @filename end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
19 20 21 |
# File 'lib/rubycc/front/token.rb', line 19 def line @line end |
#source_line ⇒ Object (readonly)
Returns the value of attribute source_line.
19 20 21 |
# File 'lib/rubycc/front/token.rb', line 19 def source_line @source_line end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
19 20 21 |
# File 'lib/rubycc/front/token.rb', line 19 def suffix @suffix end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
19 20 21 |
# File 'lib/rubycc/front/token.rb', line 19 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
19 20 21 |
# File 'lib/rubycc/front/token.rb', line 19 def value @value end |
Instance Method Details
#eof? ⇒ Boolean
40 41 42 |
# File 'lib/rubycc/front/token.rb', line 40 def eof? type == :eof end |
#inspect ⇒ Object
44 45 46 |
# File 'lib/rubycc/front/token.rb', line 44 def inspect "#<Token #{type} #{value.inspect} @#{line}:#{column}>" end |
#keyword?(str) ⇒ Boolean
36 37 38 |
# File 'lib/rubycc/front/token.rb', line 36 def keyword?(str) type == :keyword && value == str end |
#punct?(str) ⇒ Boolean
32 33 34 |
# File 'lib/rubycc/front/token.rb', line 32 def punct?(str) type == :punct && value == str end |