class Prism::Token
表示来自 Ruby 源代码的标记 (token)。
属性
代表此标记 (token) 来自的源代码的 Source
对象。
此标记 (token) 的类型。
此标记 (token) 所代表的源代码的字节切片。
公共类方法
来源
# File lib/prism/parse_result.rb, line 811 def initialize(source, type, value, location) @source = source @type = type @value = value @location = location end
使用给定的类型、值和位置创建一个新的标记 (token) 对象。
公共实例方法
来源
# File lib/prism/parse_result.rb, line 846 def ==(other) Token === other && other.type == type && other.value == value end
如果给定的其他标记 (token) 等于此标记 (token),则返回 true。
来源
# File lib/prism/parse_result.rb, line 819 def deconstruct_keys(keys) { type: type, value: value, location: location } end
为 Token
实现哈希模式匹配接口。
来源
# File lib/prism/parse_result.rb, line 853 def inspect location super end
返回此标记 (token) 的字符串表示形式。
调用父类方法
Object#inspect
来源
# File lib/prism/parse_result.rb, line 824 def location location = @location return location if location.is_a?(Location) @location = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
代表此标记 (token) 在源代码中的位置的 Location
对象。
来源
# File lib/prism/parse_result.rb, line 831 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
实现美化打印接口。