class Prism::Token
此对象代表 Ruby 源代码中的一个标记。
属性
代表此标记来源的 Source 对象。
此标记的类型。
此标记代表的源代码的字节切片。
Public Class Methods
Source
# File lib/prism/parse_result.rb, line 816 def initialize(source, type, value, location) @source = source @type = type @value = value @location = location end
使用给定的类型、值和位置创建一个新的标记对象。
Public Instance Methods
Source
# File lib/prism/parse_result.rb, line 851 def ==(other) Token === other && other.type == type && other.value == value end
如果给定的其他标记与此标记相等,则返回 true。
Source
# File lib/prism/parse_result.rb, line 824 def deconstruct_keys(keys) { type: type, value: value, location: location } end
为 Token 实现哈希模式匹配接口。
Source
# File lib/prism/parse_result.rb, line 864 def deep_freeze value.freeze location.freeze freeze end
冻结此对象及其包含的对象。
Source
# File lib/prism/parse_result.rb, line 858 def inspect location super end
返回此标记的字符串表示形式。
调用超类方法
Object#inspectSource
# File lib/prism/parse_result.rb, line 829 def location location = @location return location if location.is_a?(Location) @location = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
代表此标记在源代码中位置的 Location 对象。
Source
# File lib/prism/parse_result.rb, line 836 def pretty_print(q) q.group do q.text(type.to_s) self.location.pretty_print(q) q.text("(") q.nest(2) do q.breakable("") q.pp(value) end q.breakable("") q.text(")") end end
为 Token 实现美观打印接口。