当我们生成 token 时,我们生成与 Ripper 相同的数组。 然而,我们在它们上添加了一些便利方法,使其更易于使用。 我们将所有其他方法委托给该数组。
Ripper
# File lib/prism/lex_compat.rb, line 213 def event self[1] end
token 的类型。
# File lib/prism/lex_compat.rb, line 208 def location self[0] end
token 在源码中的位置。
# File lib/prism/lex_compat.rb, line 223 def state self[3] end
生成此 token 时词法分析器的状态。
# File lib/prism/lex_compat.rb, line 218 def value self[2] end
此 token 所代表的源码片段。