tree-sitter-grammar.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. require "."
  2. # <- keyword.other.special-method
  3. class A::B < C
  4. # <- keyword.control.class
  5. # ^ entity.name.type.class
  6. # ^ punctuation.separator.namespace
  7. # ^ entity.name.type.class
  8. # ^ punctuation.separator.inheritance
  9. # ^ entity.other.inherited-class
  10. # ^ entity.name.type.class
  11. public
  12. # <- keyword.other.special-method
  13. protected
  14. # <- keyword.other.special-method
  15. private
  16. # <- keyword.other.special-method
  17. public def foo(a)
  18. # <- keyword.other.special-method
  19. # ^ keyword.control.def
  20. # ^ entity.name.function
  21. # ^ variable.parameter.function
  22. self
  23. # <- variable.language.self
  24. @b = a
  25. # <- variable.other.readwrite.instance
  26. # ^ keyword.operator.assignment
  27. # ^ source
  28. d = c
  29. # <- source
  30. end
  31. end
  32. thing&.call
  33. # ^ punctuation.separator.method
  34. # ^ source
  35. VAR1 = 100
  36. # <- variable.other.constant
  37. # ^ keyword.operator.assignment
  38. # ^ constant.numeric
  39. _VAR1 = 100_000
  40. # <- variable.other.constant
  41. # ^ constant.numeric
  42. # This dot will not be tokenized as a separator
  43. 1.23
  44. #^ constant.numeric
  45. # But this will
  46. a.b
  47. #^ punctuation.separator.method
  48. # These are all also numbers:
  49. 1.23e-4
  50. # <- constant.numeric
  51. 0d100_000
  52. # <- constant.numeric
  53. 0xAFFF
  54. # <- constant.numeric
  55. 0XA_FFF
  56. # <- constant.numeric
  57. 01_777
  58. # <- constant.numeric
  59. 0o1_777
  60. # <- constant.numeric
  61. 0b100_000
  62. # <- constant.numeric
  63. 0B00100
  64. # <- constant.numeric
  65. :test
  66. # <- constant.other.symbol
  67. :$symbol
  68. # <- constant.other.symbol
  69. :<=>
  70. # <- constant.other.symbol
  71. %i(foo)
  72. # <- punctuation.section.array.begin
  73. # ^ constant.other.symbol
  74. {foo: 1}
  75. # <- punctuation.section.scope.begin
  76. # ^ constant.other.symbol.hashkey
  77. {:foo => 1}
  78. # ^ constant.other.symbol.hashkey
  79. class << A::B
  80. # <- keyword.control.class
  81. # ^ punctuation.definition.variable
  82. # ^ entity.name.type.class
  83. # ^ punctuation.separator.namespace
  84. end
  85. def a.b(*args)
  86. # <- meta.function.method.with-arguments
  87. # <- keyword.control.def
  88. # ^ entity.name.function
  89. # ^ entity.name.function
  90. # ^ punctuation.separator.method
  91. # ^ meta.function.method.with-arguments
  92. # ^ punctuation.definition.parameters
  93. # ^ storage.type.variable
  94. # ^ variable.parameter.function
  95. # ^ punctuation.definition.parameters
  96. end
  97. # <- keyword.control
  98. # Strings.
  99. "te\ste"
  100. # <- punctuation.definition.string.begin
  101. # ^ string.quoted.other.interpolated
  102. # ^ constant.character.escape
  103. # ^ string.quoted.other.interpolated
  104. %(te(s)t)
  105. # <- punctuation.definition.string.begin
  106. # ^ string.quoted.other.interpolated
  107. # ^ punctuation.section.scope
  108. # ^ string.quoted.other.interpolated
  109. # ^ punctuation.definition.string.end
  110. %[te[s]t]
  111. # <- punctuation.definition.string.begin
  112. # ^ string.quoted.other.interpolated
  113. # ^ punctuation.section.scope
  114. # ^ string.quoted.other.interpolated
  115. # ^ punctuation.definition.string.end
  116. %{te{s}t}
  117. # <- punctuation.definition.string.begin
  118. # ^ string.quoted.other.interpolated
  119. # ^ punctuation.section.scope
  120. # ^ string.quoted.other.interpolated
  121. # ^ punctuation.definition.string.end
  122. %<te<s>t>
  123. # <- punctuation.definition.string.begin
  124. # ^ string.quoted.other.interpolated
  125. # ^ punctuation.section.scope
  126. # ^ string.quoted.other.interpolated
  127. # ^ punctuation.definition.string.end
  128. %~te\~s~
  129. # <- punctuation.definition.string.begin
  130. # ^ string.quoted.other.interpolated
  131. # ^ constant.character.escape
  132. # ^ constant.character.escape
  133. # ^ string.quoted.other.interpolated
  134. %Q(te(s)t)
  135. # <- punctuation.definition.string.begin
  136. # ^ string.quoted.other.interpolated
  137. # ^ punctuation.section.scope
  138. # ^ string.quoted.other.interpolated
  139. # ^ punctuation.definition.string.end
  140. %x!#{"l" + "s"}!
  141. # <- punctuation.definition.string.begin
  142. # ^ punctuation.definition.string.begin
  143. # ^ punctuation.section.embedded.begin
  144. # ^ punctuation.section.embedded.begin
  145. # ^ punctuation.section.embedded.end
  146. # ^ punctuation.definition.string.end
  147. /test/
  148. # <- punctuation.section.regexp
  149. # ^ string.regexp
  150. # ^ punctuation.section.regexp