tree-sitter 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (930) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -8
  3. data/Rakefile +19 -4
  4. data/ext/tree-sitter/Makefile +24 -0
  5. data/ext/tree-sitter/document.c +149 -0
  6. data/ext/tree-sitter/document.h +17 -0
  7. data/ext/tree-sitter/extconf.rb +55 -15
  8. data/ext/tree-sitter/node.c +300 -0
  9. data/ext/tree-sitter/node.h +34 -0
  10. data/ext/tree-sitter/out/document.o +0 -0
  11. data/ext/tree-sitter/out/get_changed_ranges.o +0 -0
  12. data/ext/tree-sitter/out/language.o +0 -0
  13. data/ext/tree-sitter/out/lexer.o +0 -0
  14. data/ext/tree-sitter/out/libruntime.a +0 -0
  15. data/ext/tree-sitter/out/node.o +0 -0
  16. data/ext/tree-sitter/out/parser.o +0 -0
  17. data/ext/tree-sitter/out/python/parser.c +65600 -0
  18. data/ext/tree-sitter/out/python/parser.o +0 -0
  19. data/ext/tree-sitter/out/python/scanner.cc +164 -0
  20. data/ext/tree-sitter/out/python/scanner.o +0 -0
  21. data/ext/tree-sitter/out/stack.o +0 -0
  22. data/ext/tree-sitter/out/string_input.o +0 -0
  23. data/ext/tree-sitter/out/tree.o +0 -0
  24. data/ext/tree-sitter/out/utf16.o +0 -0
  25. data/ext/tree-sitter/out/utf8proc.o +0 -0
  26. data/ext/tree-sitter/tree-sitter.c +4 -109
  27. data/ext/tree-sitter/tree-sitter.h +4 -0
  28. data/ext/tree-sitter/tree-sitter/LICENSE +7 -0
  29. data/ext/tree-sitter/tree-sitter/README.md +13 -13
  30. data/ext/tree-sitter/tree-sitter/appveyor.yml +24 -0
  31. data/ext/tree-sitter/tree-sitter/docs/Gemfile +2 -0
  32. data/ext/tree-sitter/tree-sitter/docs/Gemfile.lock +239 -0
  33. data/ext/tree-sitter/tree-sitter/docs/_config.yml +1 -0
  34. data/ext/tree-sitter/tree-sitter/docs/_layouts/table-of-contents.html +74 -0
  35. data/ext/tree-sitter/tree-sitter/docs/creating-parsers.md +360 -0
  36. data/ext/tree-sitter/tree-sitter/docs/css/style.css +13 -0
  37. data/ext/tree-sitter/tree-sitter/docs/index.md +10 -0
  38. data/ext/tree-sitter/tree-sitter/externals/gyp/PRESUBMIT.py +10 -2
  39. data/ext/tree-sitter/tree-sitter/externals/gyp/buildbot/aosp_manifest.xml +466 -0
  40. data/ext/tree-sitter/tree-sitter/externals/gyp/buildbot/buildbot_run.py +91 -30
  41. data/ext/tree-sitter/tree-sitter/externals/gyp/gyp +1 -1
  42. data/ext/tree-sitter/tree-sitter/externals/gyp/gyptest.py +3 -3
  43. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/MSVSNew.py +1 -1
  44. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/MSVSSettings.py +11 -5
  45. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/MSVSSettings_test.py +1 -1
  46. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/MSVSUtil.py +18 -15
  47. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/MSVSVersion.py +53 -20
  48. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/__init__.py +4 -6
  49. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/__init__.pyc +0 -0
  50. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/common.py +69 -2
  51. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/common.pyc +0 -0
  52. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/flock_tool.py +6 -1
  53. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/__init__.pyc +0 -0
  54. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/analyzer.py +569 -0
  55. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/android.py +133 -111
  56. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/cmake.py +3 -3
  57. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/eclipse.py +112 -22
  58. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/gypd.py +3 -0
  59. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/make.py +45 -14
  60. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/make.pyc +0 -0
  61. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/msvs.py +170 -98
  62. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/ninja.py +300 -71
  63. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/ninja_test.py +12 -9
  64. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/xcode.py +46 -12
  65. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/generator/xcode.pyc +0 -0
  66. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/input.py +379 -335
  67. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/input.pyc +0 -0
  68. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/input_test.py +7 -7
  69. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/mac_tool.py +94 -3
  70. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/msvs_emulation.py +131 -40
  71. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/simple_copy.py +46 -0
  72. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/win_tool.py +28 -5
  73. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/xcode_emulation.py +185 -88
  74. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
  75. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/xcode_ninja.py +268 -0
  76. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/xcodeproj_file.py +53 -46
  77. data/ext/tree-sitter/tree-sitter/externals/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
  78. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions-bare/gyptest-bare.py +1 -0
  79. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions-depfile/depfile.gyp +25 -0
  80. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions-depfile/gyptest-all.py +20 -0
  81. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions-depfile/input.txt +1 -0
  82. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions-none/gyptest-none.py +1 -0
  83. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions/gyptest-all.py +1 -1
  84. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions/gyptest-default.py +1 -1
  85. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions/gyptest-generated-header.py +6 -0
  86. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions/src/subdir1/program.c +1 -1
  87. data/ext/tree-sitter/tree-sitter/externals/gyp/test/actions/src/subdir3/generate_main.py +1 -1
  88. data/ext/tree-sitter/tree-sitter/externals/gyp/test/additional-targets/gyptest-additional.py +8 -1
  89. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/common.gypi +6 -0
  90. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/gyptest-analyzer.py +356 -0
  91. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/subdir/subdir.gyp +36 -0
  92. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/subdir/subdir2/subdir2.gyp +15 -0
  93. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/subdir2/subdir.gyp +18 -0
  94. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/subdir2/subdir.includes.gypi +9 -0
  95. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/test.gyp +113 -0
  96. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/test2.gyp +25 -0
  97. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/test2.includes.gypi +13 -0
  98. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/test2.includes.includes.gypi +9 -0
  99. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/test2.toplevel_includes.gypi +15 -0
  100. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/test3.gyp +77 -0
  101. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/test4.gyp +80 -0
  102. data/ext/tree-sitter/tree-sitter/externals/gyp/test/analyzer/test5.gyp +25 -0
  103. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/32or64.c +13 -0
  104. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/file.in +1 -0
  105. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/gyptest-host-multilib.py +32 -0
  106. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/gyptest-make-functions.py +24 -0
  107. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/gyptest-noalias.py +21 -0
  108. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/gyptest-settings-list.py +24 -0
  109. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/gyptest-settings.py +24 -0
  110. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/gyptest-space-filenames.py +19 -0
  111. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/hello.c +12 -0
  112. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/hello.gyp +15 -0
  113. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/host_32or64.gyp +38 -0
  114. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/make_functions.gyp +31 -0
  115. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/settings-list.gyp +18 -0
  116. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/settings.gyp +18 -0
  117. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/space_filenames.gyp +18 -0
  118. data/ext/tree-sitter/tree-sitter/externals/gyp/test/android/writefile.c +18 -0
  119. data/ext/tree-sitter/tree-sitter/externals/gyp/test/assembly/src/program.c +1 -1
  120. data/ext/tree-sitter/tree-sitter/externals/gyp/test/build-option/gyptest-build.py +11 -0
  121. data/ext/tree-sitter/tree-sitter/externals/gyp/test/build-option/hello.c +1 -1
  122. data/ext/tree-sitter/tree-sitter/externals/gyp/test/builddir/src/prog1.c +1 -1
  123. data/ext/tree-sitter/tree-sitter/externals/gyp/test/builddir/src/subdir2/prog2.c +1 -1
  124. data/ext/tree-sitter/tree-sitter/externals/gyp/test/builddir/src/subdir2/subdir3/prog3.c +1 -1
  125. data/ext/tree-sitter/tree-sitter/externals/gyp/test/builddir/src/subdir2/subdir3/subdir4/prog4.c +1 -1
  126. data/ext/tree-sitter/tree-sitter/externals/gyp/test/builddir/src/subdir2/subdir3/subdir4/subdir5/prog5.c +1 -1
  127. data/ext/tree-sitter/tree-sitter/externals/gyp/test/cflags/cflags.c +1 -1
  128. data/ext/tree-sitter/tree-sitter/externals/gyp/test/cflags/gyptest-cflags.py +15 -55
  129. data/ext/tree-sitter/tree-sitter/externals/gyp/test/compilable/src/program.cpp +1 -1
  130. data/ext/tree-sitter/tree-sitter/externals/gyp/test/compiler-override/{compiler.gyp → compiler-exe.gyp} +0 -0
  131. data/ext/tree-sitter/tree-sitter/externals/gyp/test/compiler-override/compiler-shared-lib.gyp +16 -0
  132. data/ext/tree-sitter/tree-sitter/externals/gyp/test/compiler-override/gyptest-compiler-env-toolchain.py +78 -0
  133. data/ext/tree-sitter/tree-sitter/externals/gyp/test/compiler-override/gyptest-compiler-env.py +9 -11
  134. data/ext/tree-sitter/tree-sitter/externals/gyp/test/compiler-override/gyptest-compiler-global-settings.py +5 -0
  135. data/ext/tree-sitter/tree-sitter/externals/gyp/test/compiler-override/my_nm.py +8 -0
  136. data/ext/tree-sitter/tree-sitter/externals/gyp/test/compiler-override/my_readelf.py +8 -0
  137. data/ext/tree-sitter/tree-sitter/externals/gyp/test/conditions/elseif/elseif.gyp +43 -0
  138. data/ext/tree-sitter/tree-sitter/externals/gyp/test/conditions/elseif/elseif_bad1.gyp +20 -0
  139. data/ext/tree-sitter/tree-sitter/externals/gyp/test/conditions/elseif/elseif_bad2.gyp +22 -0
  140. data/ext/tree-sitter/tree-sitter/externals/gyp/test/conditions/elseif/elseif_bad3.gyp +23 -0
  141. data/ext/tree-sitter/tree-sitter/externals/gyp/test/conditions/elseif/elseif_conditions.gypi +15 -0
  142. data/ext/tree-sitter/tree-sitter/externals/gyp/test/conditions/elseif/gyptest_elseif.py +33 -0
  143. data/ext/tree-sitter/tree-sitter/externals/gyp/test/conditions/elseif/program.cc +10 -0
  144. data/ext/tree-sitter/tree-sitter/externals/gyp/test/configurations/basics/configurations.c +1 -1
  145. data/ext/tree-sitter/tree-sitter/externals/gyp/test/configurations/basics/gyptest-configurations.py +6 -0
  146. data/ext/tree-sitter/tree-sitter/externals/gyp/test/configurations/inheritance/configurations.c +1 -1
  147. data/ext/tree-sitter/tree-sitter/externals/gyp/test/configurations/inheritance/duplicates.gyp +27 -0
  148. data/ext/tree-sitter/tree-sitter/externals/gyp/test/configurations/inheritance/duplicates.gypd.golden +12 -0
  149. data/ext/tree-sitter/tree-sitter/externals/gyp/test/configurations/inheritance/gyptest-duplicates.py +34 -0
  150. data/ext/tree-sitter/tree-sitter/externals/gyp/test/configurations/inheritance/gyptest-inheritance.py +6 -0
  151. data/ext/tree-sitter/tree-sitter/externals/gyp/test/configurations/target_platform/front.c +1 -1
  152. data/ext/tree-sitter/tree-sitter/externals/gyp/test/configurations/x64/configurations.c +1 -1
  153. data/ext/tree-sitter/tree-sitter/externals/gyp/test/copies/gyptest-all.py +3 -1
  154. data/ext/tree-sitter/tree-sitter/externals/gyp/test/copies/gyptest-default.py +3 -1
  155. data/ext/tree-sitter/tree-sitter/externals/gyp/test/copies/gyptest-samedir.py +1 -0
  156. data/ext/tree-sitter/tree-sitter/externals/gyp/test/copies/gyptest-slash.py +1 -0
  157. data/ext/tree-sitter/tree-sitter/externals/gyp/test/copies/gyptest-updir.py +1 -0
  158. data/ext/tree-sitter/tree-sitter/externals/gyp/test/cxxflags/cxxflags.cc +4 -4
  159. data/ext/tree-sitter/tree-sitter/externals/gyp/test/cxxflags/cxxflags.gyp +0 -1
  160. data/ext/tree-sitter/tree-sitter/externals/gyp/test/cxxflags/gyptest-cxxflags.py +13 -33
  161. data/ext/tree-sitter/tree-sitter/externals/gyp/test/defines-escaping/defines-escaping.c +1 -1
  162. data/ext/tree-sitter/tree-sitter/externals/gyp/test/defines/defines.c +1 -1
  163. data/ext/tree-sitter/tree-sitter/externals/gyp/test/dependencies/gyptest-extra-targets.py +2 -1
  164. data/ext/tree-sitter/tree-sitter/externals/gyp/test/dependencies/gyptest-lib-only.py +1 -1
  165. data/ext/tree-sitter/tree-sitter/externals/gyp/test/dependency-copy/src/file1.c +1 -1
  166. data/ext/tree-sitter/tree-sitter/externals/gyp/test/dependency-copy/src/file2.c +1 -1
  167. data/ext/tree-sitter/tree-sitter/externals/gyp/test/empty-target/empty-target.gyp +12 -0
  168. data/ext/tree-sitter/tree-sitter/externals/gyp/test/empty-target/gyptest-empty-target.py +18 -0
  169. data/ext/tree-sitter/tree-sitter/externals/gyp/test/errors/dependency_cycle.gyp +23 -0
  170. data/ext/tree-sitter/tree-sitter/externals/gyp/test/errors/file_cycle0.gyp +17 -0
  171. data/ext/tree-sitter/tree-sitter/externals/gyp/test/errors/file_cycle1.gyp +13 -0
  172. data/ext/tree-sitter/tree-sitter/externals/gyp/test/errors/gyptest-errors.py +10 -2
  173. data/ext/tree-sitter/tree-sitter/externals/gyp/test/exclusion/hello.c +1 -1
  174. data/ext/tree-sitter/tree-sitter/externals/gyp/test/external-cross-compile/src/program.cc +1 -1
  175. data/ext/tree-sitter/tree-sitter/externals/gyp/test/generator-output/actions/subdir1/program.c +1 -1
  176. data/ext/tree-sitter/tree-sitter/externals/gyp/test/generator-output/gyptest-copies.py +3 -2
  177. data/ext/tree-sitter/tree-sitter/externals/gyp/test/generator-output/rules/subdir1/program.c +1 -1
  178. data/ext/tree-sitter/tree-sitter/externals/gyp/test/generator-output/src/prog1.c +1 -1
  179. data/ext/tree-sitter/tree-sitter/externals/gyp/test/generator-output/src/subdir2/deeper/deeper.c +1 -1
  180. data/ext/tree-sitter/tree-sitter/externals/gyp/test/generator-output/src/subdir2/prog2.c +1 -1
  181. data/ext/tree-sitter/tree-sitter/externals/gyp/test/generator-output/src/subdir3/prog3.c +1 -1
  182. data/ext/tree-sitter/tree-sitter/externals/gyp/test/gyp-defines/gyptest-multiple-values.py +2 -0
  183. data/ext/tree-sitter/tree-sitter/externals/gyp/test/hello/hello.c +1 -1
  184. data/ext/tree-sitter/tree-sitter/externals/gyp/test/hello/hello2.c +1 -1
  185. data/ext/tree-sitter/tree-sitter/externals/gyp/test/home_dot_gyp/src/printfoo.c +1 -1
  186. data/ext/tree-sitter/tree-sitter/externals/gyp/test/include_dirs/src/includes.c +1 -1
  187. data/ext/tree-sitter/tree-sitter/externals/gyp/test/include_dirs/src/subdir/subdir_includes.c +1 -1
  188. data/ext/tree-sitter/tree-sitter/externals/gyp/test/intermediate_dir/gyptest-intermediate-dir.py +2 -0
  189. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/app-bundle/TestApp/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
  190. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/app-bundle/TestApp/Images.xcassets/image.imageset/Contents.json +23 -0
  191. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/app-bundle/TestApp/Images.xcassets/image.imageset/super_sylvain.png +0 -0
  192. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/app-bundle/TestApp/Images.xcassets/image.imageset/super_sylvain@2x.png +0 -0
  193. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/app-bundle/TestApp/Images.xcassets/image.imageset/super_sylvain@3x.png +0 -0
  194. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/app-bundle/test-assets-catalog.gyp +45 -0
  195. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/app-bundle/test-crosscompile.gyp +47 -0
  196. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/app-bundle/test.gyp +0 -1
  197. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/app-bundle/tool_main.cc +7 -0
  198. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ActionExtension/ActionViewController.h +9 -0
  199. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ActionExtension/ActionViewController.m +31 -0
  200. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ActionExtension/Info.plist +42 -0
  201. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ActionExtension/MainInterface.storyboard +63 -0
  202. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ExtensionContainer/AppDelegate.h +12 -0
  203. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ExtensionContainer/AppDelegate.m +19 -0
  204. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ExtensionContainer/Base.lproj/Main.storyboard +25 -0
  205. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ExtensionContainer/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  206. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ExtensionContainer/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
  207. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ExtensionContainer/Info.plist +32 -0
  208. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ExtensionContainer/ViewController.h +11 -0
  209. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ExtensionContainer/ViewController.m +24 -0
  210. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/ExtensionContainer/main.m +13 -0
  211. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/extension/extension.gyp +85 -0
  212. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/gyptest-app-ios-assets-catalog.py +57 -0
  213. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/gyptest-app-ios.py +7 -7
  214. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/gyptest-archs.py +22 -70
  215. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/gyptest-crosscompile.py +34 -0
  216. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/gyptest-extension.py +28 -0
  217. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/gyptest-watch.py +36 -0
  218. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/gyptest-xcode-ninja.py +25 -0
  219. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchApp/Images.xcassets/AppIcon.appiconset/Contents.json +62 -0
  220. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchApp/Images.xcassets/LaunchImage.launchimage/Contents.json +24 -0
  221. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchApp/Info.plist +35 -0
  222. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchApp/Interface.storyboard +15 -0
  223. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchContainer/AppDelegate.h +12 -0
  224. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchContainer/AppDelegate.m +19 -0
  225. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchContainer/Base.lproj/Main.storyboard +25 -0
  226. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchContainer/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  227. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchContainer/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
  228. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchContainer/Info.plist +32 -0
  229. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchContainer/ViewController.h +11 -0
  230. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchContainer/ViewController.m +24 -0
  231. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchContainer/main.m +13 -0
  232. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchKitExtension/Images.xcassets/MyImage.imageset/Contents.json +20 -0
  233. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchKitExtension/Info.plist +38 -0
  234. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchKitExtension/InterfaceController.h +10 -0
  235. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchKitExtension/InterfaceController.m +25 -0
  236. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/WatchKitExtension/MainInterface.storyboard +63 -0
  237. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ios/watch/watch.gyp +105 -0
  238. data/ext/tree-sitter/tree-sitter/externals/gyp/test/lib/TestGyp.py +349 -46
  239. data/ext/tree-sitter/tree-sitter/externals/gyp/test/lib/TestMac.py +73 -0
  240. data/ext/tree-sitter/tree-sitter/externals/gyp/test/lib/TestWin.py +101 -0
  241. data/ext/tree-sitter/tree-sitter/externals/gyp/test/library/gyptest-shared.py +6 -0
  242. data/ext/tree-sitter/tree-sitter/externals/gyp/test/library/gyptest-static.py +6 -0
  243. data/ext/tree-sitter/tree-sitter/externals/gyp/test/library/src/program.c +1 -1
  244. data/ext/tree-sitter/tree-sitter/externals/gyp/test/link-dependency/gyptest-link-dependency.py +23 -0
  245. data/ext/tree-sitter/tree-sitter/externals/gyp/test/link-dependency/main.c +7 -0
  246. data/ext/tree-sitter/tree-sitter/externals/gyp/test/link-dependency/mymalloc.c +12 -0
  247. data/ext/tree-sitter/tree-sitter/externals/gyp/test/link-dependency/test.gyp +37 -0
  248. data/ext/tree-sitter/tree-sitter/externals/gyp/test/link-objects/base.c +1 -1
  249. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/app-bundle/TestApp/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
  250. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/app-bundle/TestApp/Images.xcassets/image.imageset/Contents.json +23 -0
  251. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/app-bundle/TestApp/Images.xcassets/image.imageset/super_sylvain.png +0 -0
  252. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/app-bundle/TestApp/Images.xcassets/image.imageset/super_sylvain@2x.png +0 -0
  253. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/app-bundle/TestApp/Images.xcassets/image.imageset/super_sylvain@3x.png +0 -0
  254. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/app-bundle/test-assets-catalog.gyp +43 -0
  255. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/archs/file_a.cc +8 -0
  256. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/archs/file_a.h +10 -0
  257. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/archs/file_b.cc +8 -0
  258. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/archs/file_b.h +10 -0
  259. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/archs/file_c.cc +11 -0
  260. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/archs/file_d.cc +11 -0
  261. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/archs/test-archs-multiarch.gyp +20 -0
  262. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/archs/test-dependencies.gyp +92 -0
  263. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/archs/test-valid-archs.gyp +28 -0
  264. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/clang-cxx-library/libc++.cc +2 -2
  265. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/clang-cxx-library/libstdc++.cc +1 -1
  266. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-action-envvars.py +6 -0
  267. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-app-assets-catalog.py +120 -0
  268. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-app-error.py +2 -1
  269. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-app.py +8 -20
  270. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-archs.py +39 -33
  271. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-cflags.py +1 -0
  272. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-clang-cxx-library.py +3 -4
  273. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-global-settings.py +7 -0
  274. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-installname.py +1 -0
  275. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-ldflags-passed-to-libtool.py +1 -0
  276. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-ldflags.py +6 -0
  277. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-libraries.py +6 -0
  278. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-libtool-zero.py +26 -0
  279. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-loadable-module-bundle-product-extension.py +31 -0
  280. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-loadable-module.py +1 -0
  281. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-objc-gc.py +24 -18
  282. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-postbuild-copy-bundle.py +1 -1
  283. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-postbuild-fail.py +1 -0
  284. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-prefixheader.py +1 -0
  285. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-rpath.py +5 -4
  286. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-strip.py +13 -5
  287. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-swift-library.py +62 -0
  288. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-type-envvars.py +3 -1
  289. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-xcode-env-order.py +2 -6
  290. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/gyptest-xcode-support-actions.py +25 -0
  291. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/libtool-zero/mylib.c +7 -0
  292. data/ext/tree-sitter/tree-sitter/externals/gyp/test/{errors/duplicate_basenames.gyp → mac/libtool-zero/test.gyp} +6 -4
  293. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/loadable-module-bundle-product-extension/src.cc +7 -0
  294. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/loadable-module-bundle-product-extension/test.gyp +24 -0
  295. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/swift-library/Info.plist +28 -0
  296. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/swift-library/file.swift +9 -0
  297. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/swift-library/test.gyp +21 -0
  298. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/type_envvars/test_bundle_executable.sh +1 -2
  299. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/type_envvars/test_bundle_loadable_module.sh +1 -2
  300. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/type_envvars/test_bundle_shared_library.sh +1 -2
  301. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/type_envvars/test_check_sdkroot.sh +47 -0
  302. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/type_envvars/test_nonbundle_executable.sh +2 -2
  303. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/type_envvars/test_nonbundle_loadable_module.sh +1 -2
  304. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/type_envvars/test_nonbundle_none.sh +1 -2
  305. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/type_envvars/test_nonbundle_shared_library.sh +1 -2
  306. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/type_envvars/test_nonbundle_static_library.sh +1 -2
  307. data/ext/tree-sitter/tree-sitter/{out/Release/linker.lock → externals/gyp/test/mac/xcode-support-actions/source.c} +0 -0
  308. data/ext/tree-sitter/tree-sitter/externals/gyp/test/mac/xcode-support-actions/test.gyp +26 -0
  309. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make/main.cc +1 -1
  310. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make/noload/main.c +1 -1
  311. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/ar/gyptest-make_global_settings_ar.py +123 -0
  312. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/ar/make_global_settings_ar.gyp +29 -0
  313. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/basics/gyptest-make_global_settings.py +2 -2
  314. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/full-toolchain/bar.cc +1 -0
  315. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/full-toolchain/foo.c +1 -0
  316. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/full-toolchain/gyptest-make_global_settings.py +48 -0
  317. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/full-toolchain/make_global_settings.gyp +22 -0
  318. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/full-toolchain/my_nm.py +8 -0
  319. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/full-toolchain/my_readelf.py +8 -0
  320. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/ld/gyptest-make_global_settings_ld.py +130 -0
  321. data/ext/tree-sitter/tree-sitter/externals/gyp/test/make_global_settings/ld/make_global_settings_ld.gyp +29 -0
  322. data/ext/tree-sitter/tree-sitter/externals/gyp/test/many-actions/gyptest-many-actions-unsorted.py +1 -0
  323. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/buildevents/gyptest-ninja-warnings.py +2 -2
  324. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/config_attrs/hello.c +2 -2
  325. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/external_builder/hello.cpp +1 -1
  326. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/filters/gyptest-filters-2010.py +1 -1
  327. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/list_excluded/hello.cpp +1 -1
  328. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/multiple_actions_error_handling/action_fail.py +7 -0
  329. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/multiple_actions_error_handling/action_succeed.py +7 -0
  330. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/multiple_actions_error_handling/actions.gyp +40 -0
  331. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/multiple_actions_error_handling/gyptest.py +26 -0
  332. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/props/hello.c +1 -1
  333. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/shared_output/hello.c +1 -1
  334. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/shared_output/there/there.c +1 -1
  335. data/ext/tree-sitter/tree-sitter/externals/gyp/test/msvs/uldi2010/hello.c +1 -1
  336. data/ext/tree-sitter/tree-sitter/externals/gyp/test/multiple-targets/gyptest-all.py +0 -3
  337. data/ext/tree-sitter/tree-sitter/externals/gyp/test/multiple-targets/gyptest-default.py +0 -3
  338. data/ext/tree-sitter/tree-sitter/externals/gyp/test/multiple-targets/src/prog1.c +1 -1
  339. data/ext/tree-sitter/tree-sitter/externals/gyp/test/multiple-targets/src/prog2.c +1 -1
  340. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/action-rule-hash/gyptest-action-rule-hash.py +32 -0
  341. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/action-rule-hash/subdir/action-rule-hash.gyp +29 -0
  342. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/action-rule-hash/subdir/emit.py +13 -0
  343. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/action_dependencies/gyptest-action-dependencies.py +3 -0
  344. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/chained-dependency/chained.c +1 -1
  345. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/chained-dependency/gyptest-chained-dependency.py +4 -0
  346. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/empty-and-non-empty-duplicate-name/gyptest-empty-and-non-empty-duplicate-name.py +23 -0
  347. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/empty-and-non-empty-duplicate-name/subdir/included.gyp +19 -0
  348. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/empty-and-non-empty-duplicate-name/test.gyp +19 -0
  349. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/normalize-paths-win/gyptest-normalize-paths.py +4 -0
  350. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/normalize-paths-win/normalize-paths.gyp +12 -0
  351. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/solibs_avoid_relinking/gyptest-solibs-avoid-relinking.py +5 -0
  352. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/use-console/foo.bar +5 -0
  353. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/use-console/gyptest-use-console.py +29 -0
  354. data/ext/tree-sitter/tree-sitter/externals/gyp/test/ninja/use-console/use-console.gyp +60 -0
  355. data/ext/tree-sitter/tree-sitter/externals/gyp/test/no-cpp/gyptest-no-cpp.py +1 -0
  356. data/ext/tree-sitter/tree-sitter/externals/gyp/test/product/hello.c +1 -1
  357. data/ext/tree-sitter/tree-sitter/externals/gyp/test/prune_targets/gyptest-prune-targets.py +3 -0
  358. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules-dirname/gyptest-dirname.py +17 -3
  359. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules-dirname/src/subdir/a/b/c.gencc +2 -5
  360. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules-dirname/src/subdir/foo/bar/baz.gencc +2 -5
  361. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules-dirname/src/subdir/input-rule-dirname.gyp +62 -14
  362. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules-dirname/src/subdir/main.cc +2 -0
  363. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules-dirname/src/subdir/nodir.gencc +8 -0
  364. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules-rebuild/src/main.c +1 -1
  365. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules-use-built-dependencies/gyptest-use-built-dependencies.py +1 -0
  366. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/gyptest-all.py +7 -1
  367. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/gyptest-default.py +7 -1
  368. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/src/actions.gyp +1 -0
  369. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/src/special-variables.gyp +0 -1
  370. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/src/subdir1/program.c +1 -1
  371. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/src/subdir2/both_rule_and_action_input.gyp +50 -0
  372. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/src/subdir2/program.c +12 -0
  373. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/src/subdir3/program.c +1 -1
  374. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/src/subdir4/build-asm.gyp +1 -1
  375. data/ext/tree-sitter/tree-sitter/externals/gyp/test/rules/src/subdir4/program.c +1 -1
  376. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-source-file-name/gyptest-shared.py +27 -0
  377. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-source-file-name/gyptest-static.py +29 -0
  378. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-source-file-name/src/double-shared.gyp +6 -0
  379. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-source-file-name/src/double-static.gyp +1 -0
  380. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-source-file-name/src/prog1.c +1 -1
  381. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-source-file-name/src/prog2.c +1 -1
  382. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-source-file-name/src/prog3.c +1 -1
  383. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-target-name-different-directory/gyptest-all.py +5 -0
  384. data/ext/tree-sitter/tree-sitter/externals/gyp/test/sibling/gyptest-all.py +6 -3
  385. data/ext/tree-sitter/tree-sitter/externals/gyp/test/sibling/gyptest-relocate.py +6 -3
  386. data/ext/tree-sitter/tree-sitter/externals/gyp/test/sibling/src/prog1/prog1.c +1 -1
  387. data/ext/tree-sitter/tree-sitter/externals/gyp/test/sibling/src/prog2/prog2.c +1 -1
  388. data/ext/tree-sitter/tree-sitter/externals/gyp/test/standalone-static-library/prog.c +1 -1
  389. data/ext/tree-sitter/tree-sitter/externals/gyp/test/subdirectory/gyptest-SYMROOT-all.py +1 -1
  390. data/ext/tree-sitter/tree-sitter/externals/gyp/test/subdirectory/gyptest-SYMROOT-default.py +1 -1
  391. data/ext/tree-sitter/tree-sitter/externals/gyp/test/subdirectory/src/prog1.c +1 -1
  392. data/ext/tree-sitter/tree-sitter/externals/gyp/test/subdirectory/src/subdir/prog2.c +1 -1
  393. data/ext/tree-sitter/tree-sitter/externals/gyp/test/subdirectory/src/subdir/subdir2/prog3.c +1 -1
  394. data/ext/tree-sitter/tree-sitter/externals/gyp/test/toolsets/main.cc +1 -1
  395. data/ext/tree-sitter/tree-sitter/externals/gyp/test/toplevel-dir/gyptest-toplevel-dir.py +1 -1
  396. data/ext/tree-sitter/tree-sitter/externals/gyp/test/toplevel-dir/src/sub1/prog1.c +1 -1
  397. data/ext/tree-sitter/tree-sitter/externals/gyp/test/toplevel-dir/src/sub2/prog2.c +1 -1
  398. data/ext/tree-sitter/tree-sitter/externals/gyp/test/variables/commands/gyptest-commands-repeated-multidir.py +23 -0
  399. data/ext/tree-sitter/tree-sitter/externals/gyp/test/variables/commands/repeated_multidir/dir_1/test_1.gyp +13 -0
  400. data/ext/tree-sitter/tree-sitter/externals/gyp/test/variables/commands/repeated_multidir/dir_2/test_2.gyp +13 -0
  401. data/ext/tree-sitter/tree-sitter/externals/gyp/test/variables/commands/repeated_multidir/main.gyp +16 -0
  402. data/ext/tree-sitter/tree-sitter/externals/gyp/test/variables/commands/repeated_multidir/print_cwd_basename.py +10 -0
  403. data/ext/tree-sitter/tree-sitter/externals/gyp/test/variables/commands/repeated_multidir/repeated_command_common.gypi +25 -0
  404. data/ext/tree-sitter/tree-sitter/externals/gyp/test/variables/latelate/src/program.cc +1 -1
  405. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/command-quote/command-quote.gyp +0 -5
  406. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/command-quote/subdir/and/another/in-subdir.gyp +0 -1
  407. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/calling-convention-cdecl.def +6 -0
  408. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/calling-convention-fastcall.def +6 -0
  409. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/calling-convention-stdcall.def +6 -0
  410. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/calling-convention-vectorcall.def +6 -0
  411. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/calling-convention.cc +6 -0
  412. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/calling-convention.gyp +66 -0
  413. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/enable-enhanced-instruction-set.cc +28 -0
  414. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/enable-enhanced-instruction-set.gyp +68 -0
  415. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/floating-point-model-fast.cc +19 -0
  416. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/floating-point-model-precise.cc +19 -0
  417. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/floating-point-model-strict.cc +19 -0
  418. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/compiler-flags/floating-point-model.gyp +43 -0
  419. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/enable-winrt/dllmain.cc +30 -0
  420. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/enable-winrt/enable-winrt.gyp +39 -0
  421. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/generator-output-different-drive/prog.c +1 -1
  422. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-cl-calling-convention.py +22 -0
  423. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-cl-enable-enhanced-instruction-set.py +44 -0
  424. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-cl-floating-point-model.py +22 -0
  425. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-link-base-address.py +1 -1
  426. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-link-enable-winrt.py +35 -0
  427. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-link-pdb-no-output.py +25 -0
  428. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-link-pdb-output.py +0 -1
  429. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-link-profile.py +1 -1
  430. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-link-restat-importlib.py +6 -0
  431. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-link-safeseh.py +40 -0
  432. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-link-shard.py +3 -0
  433. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-macro-targetext.py +26 -0
  434. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-macro-targetfilename.py +32 -0
  435. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-macro-targetpath.py +30 -0
  436. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-midl-excluded.py +22 -0
  437. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-midl-includedirs.py +21 -0
  438. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-midl-rules.py +4 -0
  439. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-ml-safeseh.py +22 -0
  440. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/gyptest-system-include.py +21 -0
  441. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-excluded/bad.idl +6 -0
  442. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-excluded/copy-file.py +11 -0
  443. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-excluded/idl-excluded.gyp +58 -0
  444. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-excluded/program.cc +7 -0
  445. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-includedirs/hello.cc +7 -0
  446. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-includedirs/idl-includedirs.gyp +26 -0
  447. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-includedirs/subdir/bar.idl +13 -0
  448. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-includedirs/subdir/foo.idl +14 -0
  449. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-rules/Window.idl +9 -0
  450. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-rules/basic-idl.gyp +67 -42
  451. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/idl-rules/idl_compiler.py +17 -0
  452. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/large-pdb/main.cc +1 -1
  453. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/linker-flags/pdb-output.gyp +13 -0
  454. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/linker-flags/safeseh.gyp +47 -0
  455. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/linker-flags/safeseh_hello.cc +11 -0
  456. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/linker-flags/safeseh_zero.asm +10 -0
  457. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/linker-flags/update_pgd.py +3 -3
  458. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/ml-safeseh/a.asm +10 -0
  459. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/ml-safeseh/hello.cc +11 -0
  460. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/ml-safeseh/ml-safeseh.gyp +24 -0
  461. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/precompiled/hello.c +1 -1
  462. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/shard/hello.cc +7 -0
  463. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/shard/shard.gyp +11 -0
  464. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/shard/shard_ref.gyp +41 -0
  465. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/system-include/bar/header.h +0 -0
  466. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/system-include/common/commonheader.h +0 -0
  467. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/system-include/foo/header.h +0 -0
  468. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/system-include/main.cc +4 -0
  469. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/system-include/test.gyp +26 -0
  470. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/vs-macros/containing-gyp.gyp +0 -1
  471. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/vs-macros/input-output-macros.gyp +0 -1
  472. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/vs-macros/targetext.gyp +59 -0
  473. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/vs-macros/targetfilename.gyp +59 -0
  474. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/vs-macros/targetpath.gyp +59 -0
  475. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/win-tool/copies_readonly_files.gyp +29 -0
  476. data/ext/tree-sitter/tree-sitter/externals/gyp/test/win/win-tool/gyptest-win-tool-handles-readonly-files.py +55 -0
  477. data/ext/tree-sitter/tree-sitter/externals/gyp/tools/emacs/gyp.el +36 -13
  478. data/ext/tree-sitter/tree-sitter/externals/gyp/tools/pretty_sln.py +4 -3
  479. data/ext/tree-sitter/tree-sitter/externals/utf8proc/CMakeLists.txt +4 -2
  480. data/ext/tree-sitter/tree-sitter/externals/utf8proc/MANIFEST +3 -3
  481. data/ext/tree-sitter/tree-sitter/externals/utf8proc/Makefile +11 -6
  482. data/ext/tree-sitter/tree-sitter/externals/utf8proc/NEWS.md +69 -0
  483. data/ext/tree-sitter/tree-sitter/externals/utf8proc/README.md +4 -2
  484. data/ext/tree-sitter/tree-sitter/externals/utf8proc/bench/bench.c +2 -2
  485. data/ext/tree-sitter/tree-sitter/externals/utf8proc/data/Makefile +12 -9
  486. data/ext/tree-sitter/tree-sitter/externals/utf8proc/data/data_generator.rb +125 -42
  487. data/ext/tree-sitter/tree-sitter/externals/utf8proc/test/custom.c +27 -0
  488. data/ext/tree-sitter/tree-sitter/externals/utf8proc/test/iterate.c +8 -2
  489. data/ext/tree-sitter/tree-sitter/externals/utf8proc/test/printproperty.c +5 -7
  490. data/ext/tree-sitter/tree-sitter/externals/utf8proc/utf8proc.c +209 -98
  491. data/ext/tree-sitter/tree-sitter/externals/utf8proc/utf8proc.h +126 -28
  492. data/ext/tree-sitter/tree-sitter/externals/utf8proc/utf8proc_data.c +12976 -15342
  493. data/ext/tree-sitter/tree-sitter/include/tree_sitter/compiler.h +2 -0
  494. data/ext/tree-sitter/tree-sitter/include/tree_sitter/parser.h +73 -74
  495. data/ext/tree-sitter/tree-sitter/include/tree_sitter/runtime.h +29 -20
  496. data/ext/tree-sitter/tree-sitter/project.gyp +13 -24
  497. data/ext/tree-sitter/tree-sitter/script/benchmark +76 -0
  498. data/ext/tree-sitter/tree-sitter/script/build-fuzzers +66 -0
  499. data/ext/tree-sitter/tree-sitter/script/ci +2 -1
  500. data/ext/tree-sitter/tree-sitter/script/configure.cmd +3 -0
  501. data/ext/tree-sitter/tree-sitter/script/fetch-fixtures +13 -9
  502. data/ext/tree-sitter/tree-sitter/script/fetch-fixtures.cmd +26 -0
  503. data/ext/tree-sitter/tree-sitter/script/reproduce +1 -0
  504. data/ext/tree-sitter/tree-sitter/script/run-fuzzer +57 -0
  505. data/ext/tree-sitter/tree-sitter/script/test +47 -8
  506. data/ext/tree-sitter/tree-sitter/script/test.cmd +2 -0
  507. data/ext/tree-sitter/tree-sitter/script/trim-whitespace +1 -1
  508. data/ext/tree-sitter/tree-sitter/script/util/scan-build.sh +24 -0
  509. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lex_item.cc +60 -41
  510. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lex_item.h +6 -7
  511. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lex_item_transitions.cc +108 -101
  512. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lex_item_transitions.h +1 -4
  513. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lex_table_builder.cc +537 -0
  514. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lex_table_builder.h +57 -0
  515. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lookahead_set.cc +93 -19
  516. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lookahead_set.h +90 -5
  517. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/parse_item.cc +77 -29
  518. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/parse_item.h +4 -9
  519. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/parse_item_set_builder.cc +229 -94
  520. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/parse_item_set_builder.h +9 -3
  521. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/parse_table_builder.cc +893 -0
  522. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/parse_table_builder.h +38 -0
  523. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/rule_can_be_blank.cc +34 -35
  524. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/rule_can_be_blank.h +1 -1
  525. data/ext/tree-sitter/tree-sitter/src/compiler/compile.cc +23 -40
  526. data/ext/tree-sitter/tree-sitter/src/compiler/compile_error.h +6 -0
  527. data/ext/tree-sitter/tree-sitter/src/compiler/generate_code/c_code.cc +301 -124
  528. data/ext/tree-sitter/tree-sitter/src/compiler/generate_code/c_code.h +12 -4
  529. data/ext/tree-sitter/tree-sitter/{doc → src/compiler}/grammar-schema.json +34 -42
  530. data/ext/tree-sitter/tree-sitter/src/compiler/grammar.h +24 -5
  531. data/ext/tree-sitter/tree-sitter/src/compiler/lex_table.cc +2 -31
  532. data/ext/tree-sitter/tree-sitter/src/compiler/lex_table.h +6 -30
  533. data/ext/tree-sitter/tree-sitter/src/compiler/lexical_grammar.h +15 -3
  534. data/ext/tree-sitter/tree-sitter/src/compiler/parse_grammar.cc +143 -105
  535. data/ext/tree-sitter/tree-sitter/src/compiler/parse_grammar.h +2 -1
  536. data/ext/tree-sitter/tree-sitter/src/compiler/parse_table.cc +71 -174
  537. data/ext/tree-sitter/tree-sitter/src/compiler/parse_table.h +23 -41
  538. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/expand_repeats.cc +67 -34
  539. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/expand_repeats.h +0 -2
  540. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/expand_tokens.cc +53 -61
  541. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/expand_tokens.h +9 -3
  542. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/extract_choices.cc +37 -43
  543. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/extract_choices.h +1 -1
  544. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/extract_tokens.cc +248 -125
  545. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/extract_tokens.h +3 -2
  546. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/flatten_grammar.cc +114 -70
  547. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/flatten_grammar.h +2 -2
  548. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/initial_syntax_grammar.h +4 -3
  549. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/intern_symbols.cc +113 -50
  550. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/intern_symbols.h +2 -2
  551. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/interned_grammar.h +7 -6
  552. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/normalize_rules.cc +5 -3
  553. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/parse_regex.cc +95 -76
  554. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/parse_regex.h +1 -1
  555. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/prepare_grammar.cc +9 -7
  556. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/prepare_grammar.h +2 -5
  557. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/token_description.cc +59 -45
  558. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/token_description.h +1 -1
  559. data/ext/tree-sitter/tree-sitter/src/compiler/rule.cc +284 -6
  560. data/ext/tree-sitter/tree-sitter/src/compiler/rule.h +124 -25
  561. data/ext/tree-sitter/tree-sitter/src/compiler/rules/blank.h +5 -14
  562. data/ext/tree-sitter/tree-sitter/src/compiler/rules/character_set.cc +35 -84
  563. data/ext/tree-sitter/tree-sitter/src/compiler/rules/character_set.h +19 -26
  564. data/ext/tree-sitter/tree-sitter/src/compiler/rules/choice.cc +3 -69
  565. data/ext/tree-sitter/tree-sitter/src/compiler/rules/choice.h +6 -13
  566. data/ext/tree-sitter/tree-sitter/src/compiler/rules/metadata.cc +128 -71
  567. data/ext/tree-sitter/tree-sitter/src/compiler/rules/metadata.h +48 -17
  568. data/ext/tree-sitter/tree-sitter/src/compiler/rules/named_symbol.h +6 -12
  569. data/ext/tree-sitter/tree-sitter/src/compiler/rules/pattern.h +6 -12
  570. data/ext/tree-sitter/tree-sitter/src/compiler/rules/repeat.cc +5 -34
  571. data/ext/tree-sitter/tree-sitter/src/compiler/rules/repeat.h +7 -13
  572. data/ext/tree-sitter/tree-sitter/src/compiler/rules/seq.cc +6 -47
  573. data/ext/tree-sitter/tree-sitter/src/compiler/rules/seq.h +8 -14
  574. data/ext/tree-sitter/tree-sitter/src/compiler/rules/string.h +6 -12
  575. data/ext/tree-sitter/tree-sitter/src/compiler/rules/symbol.h +53 -32
  576. data/ext/tree-sitter/tree-sitter/src/compiler/syntax_grammar.cc +24 -22
  577. data/ext/tree-sitter/tree-sitter/src/compiler/syntax_grammar.h +36 -21
  578. data/ext/tree-sitter/tree-sitter/src/compiler/util/make_visitor.h +31 -0
  579. data/ext/tree-sitter/tree-sitter/src/runtime/alloc.h +1 -1
  580. data/ext/tree-sitter/tree-sitter/src/runtime/array.h +25 -36
  581. data/ext/tree-sitter/tree-sitter/src/runtime/document.c +61 -34
  582. data/ext/tree-sitter/tree-sitter/src/runtime/document.h +3 -0
  583. data/ext/tree-sitter/tree-sitter/src/runtime/error_costs.h +5 -19
  584. data/ext/tree-sitter/tree-sitter/src/runtime/get_changed_ranges.c +355 -0
  585. data/ext/tree-sitter/tree-sitter/src/runtime/get_changed_ranges.h +20 -0
  586. data/ext/tree-sitter/tree-sitter/src/runtime/language.c +33 -31
  587. data/ext/tree-sitter/tree-sitter/src/runtime/language.h +27 -3
  588. data/ext/tree-sitter/tree-sitter/src/runtime/length.h +5 -21
  589. data/ext/tree-sitter/tree-sitter/src/runtime/lexer.c +61 -17
  590. data/ext/tree-sitter/tree-sitter/src/runtime/lexer.h +4 -5
  591. data/ext/tree-sitter/tree-sitter/src/runtime/node.c +93 -89
  592. data/ext/tree-sitter/tree-sitter/src/runtime/node.h +1 -1
  593. data/ext/tree-sitter/tree-sitter/src/runtime/parser.c +850 -743
  594. data/ext/tree-sitter/tree-sitter/src/runtime/parser.h +13 -8
  595. data/ext/tree-sitter/tree-sitter/src/runtime/point.h +9 -4
  596. data/ext/tree-sitter/tree-sitter/src/runtime/reduce_action.h +2 -0
  597. data/ext/tree-sitter/tree-sitter/src/runtime/reusable_node.h +14 -18
  598. data/ext/tree-sitter/tree-sitter/src/runtime/stack.c +424 -302
  599. data/ext/tree-sitter/tree-sitter/src/runtime/stack.h +75 -72
  600. data/ext/tree-sitter/tree-sitter/src/runtime/string_input.c +4 -10
  601. data/ext/tree-sitter/tree-sitter/src/runtime/tree.c +401 -252
  602. data/ext/tree-sitter/tree-sitter/src/runtime/tree.h +71 -57
  603. data/ext/tree-sitter/tree-sitter/src/runtime/utf16.c +5 -0
  604. data/ext/tree-sitter/tree-sitter/test/benchmarks.cc +122 -0
  605. data/ext/tree-sitter/tree-sitter/{spec/compiler/build_tables/lex_item_spec.cc → test/compiler/build_tables/lex_item_test.cc} +141 -143
  606. data/ext/tree-sitter/tree-sitter/test/compiler/build_tables/parse_item_set_builder_test.cc +134 -0
  607. data/ext/tree-sitter/tree-sitter/{spec/compiler/build_tables/rule_can_be_blank_spec.cc → test/compiler/build_tables/rule_can_be_blank_test.cc} +16 -19
  608. data/ext/tree-sitter/tree-sitter/test/compiler/prepare_grammar/expand_repeats_test.cc +170 -0
  609. data/ext/tree-sitter/tree-sitter/test/compiler/prepare_grammar/expand_tokens_test.cc +89 -0
  610. data/ext/tree-sitter/tree-sitter/test/compiler/prepare_grammar/extract_choices_test.cc +77 -0
  611. data/ext/tree-sitter/tree-sitter/test/compiler/prepare_grammar/extract_tokens_test.cc +459 -0
  612. data/ext/tree-sitter/tree-sitter/test/compiler/prepare_grammar/flatten_grammar_test.cc +130 -0
  613. data/ext/tree-sitter/tree-sitter/test/compiler/prepare_grammar/intern_symbols_test.cc +101 -0
  614. data/ext/tree-sitter/tree-sitter/test/compiler/prepare_grammar/parse_regex_test.cc +334 -0
  615. data/ext/tree-sitter/tree-sitter/{spec/compiler/rules/character_set_spec.cc → test/compiler/rules/character_set_test.cc} +15 -27
  616. data/ext/tree-sitter/tree-sitter/test/compiler/rules/rule_test.cc +90 -0
  617. data/ext/tree-sitter/tree-sitter/{spec/compiler/util/string_helpers_spec.cc → test/compiler/util/string_helpers_test.cc} +1 -1
  618. data/ext/tree-sitter/tree-sitter/test/fixtures/error_corpus/c_errors.txt +166 -0
  619. data/ext/tree-sitter/tree-sitter/test/fixtures/error_corpus/javascript_errors.txt +179 -0
  620. data/ext/tree-sitter/tree-sitter/{spec → test}/fixtures/error_corpus/json_errors.txt +10 -7
  621. data/ext/tree-sitter/tree-sitter/{spec → test}/fixtures/error_corpus/python_errors.txt +0 -0
  622. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/aliased_inlined_rules/corpus.txt +13 -0
  623. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/aliased_inlined_rules/grammar.json +59 -0
  624. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/aliased_inlined_rules/readme.md +1 -0
  625. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/aliased_rules/corpus.txt +18 -0
  626. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/aliased_rules/grammar.json +71 -0
  627. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/aliased_unit_reductions/corpus.txt +12 -0
  628. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/aliased_unit_reductions/grammar.json +70 -0
  629. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/aliased_unit_reductions/readme.md +5 -0
  630. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/anonymous_tokens_with_escaped_chars/corpus.txt +32 -0
  631. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/anonymous_tokens_with_escaped_chars/grammar.json +14 -0
  632. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/anonymous_tokens_with_escaped_chars/readme.md +1 -0
  633. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/associativity_left/corpus.txt +8 -0
  634. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/associativity_left/grammar.json +31 -0
  635. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/associativity_missing/expected_error.txt +13 -0
  636. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/associativity_missing/grammar.json +27 -0
  637. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/associativity_right/corpus.txt +8 -0
  638. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/associativity_right/grammar.json +31 -0
  639. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/conflict_in_repeat_rule/expected_error.txt +14 -0
  640. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/conflict_in_repeat_rule/grammar.json +76 -0
  641. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/conflict_in_repeat_rule/readme.md +1 -0
  642. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/conflict_in_repeat_rule_after_external_token/expected_error.txt +14 -0
  643. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/conflict_in_repeat_rule_after_external_token/grammar.json +82 -0
  644. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/conflict_in_repeat_rule_after_external_token/readme.md +1 -0
  645. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/conflicting_precedence/expected_error.txt +15 -0
  646. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/conflicting_precedence/grammar.json +58 -0
  647. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/dynamic_precedence/corpus.txt +25 -0
  648. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/dynamic_precedence/grammar.json +73 -0
  649. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/dynamic_precedence/readme.md +1 -0
  650. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/epsilon_rules/expected_error.txt +4 -0
  651. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/epsilon_rules/grammar.json +15 -0
  652. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_and_internal_anonymous_tokens/corpus.txt +41 -0
  653. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_and_internal_anonymous_tokens/grammar.json +35 -0
  654. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_and_internal_anonymous_tokens/readme.md +1 -0
  655. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_and_internal_anonymous_tokens/scanner.c +36 -0
  656. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_and_internal_tokens/corpus.txt +41 -0
  657. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_and_internal_tokens/grammar.json +36 -0
  658. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_and_internal_tokens/readme.md +1 -0
  659. data/ext/tree-sitter/tree-sitter/{spec/fixtures/external_scanners/shared_external_tokens.c → test/fixtures/test_grammars/external_and_internal_tokens/scanner.c} +21 -14
  660. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_extra_tokens/corpus.txt +10 -0
  661. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_extra_tokens/grammar.json +25 -0
  662. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_extra_tokens/scanner.c +49 -0
  663. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_tokens/corpus.txt +22 -0
  664. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/external_tokens/grammar.json +57 -0
  665. data/ext/tree-sitter/tree-sitter/{spec/fixtures/external_scanners/percent_strings.c → test/fixtures/test_grammars/external_tokens/scanner.c} +19 -17
  666. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/inline_rules/corpus.txt +20 -0
  667. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/inline_rules/grammar.json +76 -0
  668. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/inlined_aliased_rules/corpus.txt +18 -0
  669. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/inlined_aliased_rules/grammar.json +75 -0
  670. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/inlined_aliased_rules/readme.md +1 -0
  671. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/inverted_external_token/corpus.txt +32 -0
  672. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/inverted_external_token/grammar.json +55 -0
  673. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/inverted_external_token/readme.md +1 -0
  674. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/inverted_external_token/scanner.c +48 -0
  675. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/invisible_start_rule/expected_error.txt +1 -0
  676. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/invisible_start_rule/grammar.json +23 -0
  677. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/lexical_conflicts_due_to_state_merging/corpus.txt +33 -0
  678. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/lexical_conflicts_due_to_state_merging/grammar.json +65 -0
  679. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/lexical_conflicts_due_to_state_merging/readme.md +20 -0
  680. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/nested_inlined_rules/corpus.txt +12 -0
  681. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/nested_inlined_rules/grammar.json +54 -0
  682. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/nested_inlined_rules/readme.md +1 -0
  683. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/partially_resolved_conflict/expected_error.txt +14 -0
  684. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/partially_resolved_conflict/grammar.json +58 -0
  685. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/partially_resolved_conflict/readme.txt +1 -0
  686. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_single_child_missing/expected_error.txt +15 -0
  687. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_single_child_missing/grammar.json +63 -0
  688. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_single_child_missing/readme.md +15 -0
  689. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_single_child_negative/corpus.txt +12 -0
  690. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_single_child_negative/grammar.json +63 -0
  691. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_single_child_negative/readme.md +1 -0
  692. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_single_child_positive/corpus.txt +13 -0
  693. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_single_child_positive/grammar.json +63 -0
  694. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_single_child_positive/readme.md +1 -0
  695. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_subsequence/corpus.txt +24 -0
  696. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/precedence_on_subsequence/grammar.json +135 -0
  697. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/readme.md +3 -0
  698. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/readme_grammar/corpus.txt +13 -0
  699. data/{test/tree-sitter/fixtures/arithmetic → ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/readme_grammar}/grammar.json +3 -3
  700. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/start_rule_is_blank/corpus.txt +7 -0
  701. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/start_rule_is_blank/grammar.json +6 -0
  702. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/start_rule_is_token/corpus.txt +6 -0
  703. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/start_rule_is_token/grammar.json +6 -0
  704. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/unused_rules/corpus.txt +9 -0
  705. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/unused_rules/grammar.json +73 -0
  706. data/ext/tree-sitter/tree-sitter/test/fixtures/test_grammars/unused_rules/readme.md +1 -0
  707. data/ext/tree-sitter/tree-sitter/test/fuzz/README.md +43 -0
  708. data/ext/tree-sitter/tree-sitter/test/fuzz/fuzzer.cc +27 -0
  709. data/ext/tree-sitter/tree-sitter/test/fuzz/gen-dict.py +31 -0
  710. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/dedent.h +0 -0
  711. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/encoding_helpers.cc +9 -3
  712. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/encoding_helpers.h +0 -0
  713. data/ext/tree-sitter/tree-sitter/test/helpers/file_helpers.cc +100 -0
  714. data/ext/tree-sitter/tree-sitter/test/helpers/file_helpers.h +15 -0
  715. data/ext/tree-sitter/tree-sitter/test/helpers/load_language.cc +239 -0
  716. data/ext/tree-sitter/tree-sitter/test/helpers/load_language.h +14 -0
  717. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/point_helpers.cc +2 -5
  718. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/point_helpers.h +0 -0
  719. data/ext/tree-sitter/tree-sitter/test/helpers/random_helpers.cc +59 -0
  720. data/ext/tree-sitter/tree-sitter/test/helpers/random_helpers.h +14 -0
  721. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/read_test_entries.cc +38 -38
  722. data/ext/tree-sitter/tree-sitter/test/helpers/read_test_entries.h +22 -0
  723. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/record_alloc.cc +7 -13
  724. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/record_alloc.h +2 -2
  725. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/scope_sequence.cc +0 -0
  726. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/scope_sequence.h +0 -0
  727. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/spy_input.cc +39 -15
  728. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/spy_input.h +4 -4
  729. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/spy_logger.cc +0 -0
  730. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/spy_logger.h +0 -0
  731. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/stderr_logger.cc +0 -0
  732. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/stderr_logger.h +0 -0
  733. data/ext/tree-sitter/tree-sitter/test/helpers/stream_methods.cc +224 -0
  734. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/stream_methods.h +32 -15
  735. data/ext/tree-sitter/tree-sitter/test/helpers/tree_helpers.cc +99 -0
  736. data/ext/tree-sitter/tree-sitter/{spec → test}/helpers/tree_helpers.h +3 -1
  737. data/ext/tree-sitter/tree-sitter/test/integration/fuzzing-examples.cc +67 -0
  738. data/ext/tree-sitter/tree-sitter/test/integration/real_grammars.cc +142 -0
  739. data/ext/tree-sitter/tree-sitter/test/integration/test_grammars.cc +79 -0
  740. data/ext/tree-sitter/tree-sitter/{spec/runtime/document_spec.cc → test/runtime/document_test.cc} +150 -32
  741. data/ext/tree-sitter/tree-sitter/test/runtime/language_test.cc +55 -0
  742. data/ext/tree-sitter/tree-sitter/{spec/runtime/node_spec.cc → test/runtime/node_test.cc} +222 -127
  743. data/ext/tree-sitter/tree-sitter/{spec/runtime/parser_spec.cc → test/runtime/parser_test.cc} +126 -85
  744. data/ext/tree-sitter/tree-sitter/{spec/runtime/stack_spec.cc → test/runtime/stack_test.cc} +201 -164
  745. data/ext/tree-sitter/tree-sitter/test/runtime/tree_test.cc +475 -0
  746. data/ext/tree-sitter/tree-sitter/{spec/spec_helper.h → test/test_helper.h} +3 -3
  747. data/ext/tree-sitter/tree-sitter/{spec/specs.cc → test/tests.cc} +4 -3
  748. data/ext/tree-sitter/tree-sitter/tests.gyp +77 -23
  749. data/lib/tree-sitter.rb +4 -0
  750. data/lib/tree-sitter/node.rb +27 -0
  751. data/lib/tree-sitter/version.rb +3 -1
  752. data/test/test_helper.rb +4 -0
  753. data/test/tree-sitter/fixtures/parsers/python/parser.c +65600 -0
  754. data/test/tree-sitter/fixtures/parsers/python/scanner.cc +164 -0
  755. data/test/tree-sitter/test_basic.rb +2 -0
  756. data/test/tree-sitter/test_document.rb +101 -1
  757. data/test/tree-sitter/test_node.rb +73 -0
  758. data/tree-sitter.gemspec +4 -2
  759. metadata +445 -217
  760. data/ext/tree-sitter/tree-sitter/Makefile +0 -360
  761. data/ext/tree-sitter/tree-sitter/compiler.target.mk +0 -238
  762. data/ext/tree-sitter/tree-sitter/externals/gyp/pylintrc +0 -307
  763. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-source-file-name/gyptest-fail-shared.py +0 -18
  764. data/ext/tree-sitter/tree-sitter/externals/gyp/test/same-source-file-name/gyptest-fail-static.py +0 -18
  765. data/ext/tree-sitter/tree-sitter/gyp-mac-tool +0 -511
  766. data/ext/tree-sitter/tree-sitter/out/Release/libcompiler.a +0 -0
  767. data/ext/tree-sitter/tree-sitter/out/Release/libruntime.a +0 -0
  768. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/externals/json-parser/json.o +0 -0
  769. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/externals/utf8proc/utf8proc.o +0 -0
  770. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/build_lex_table.o +0 -0
  771. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/build_parse_table.o +0 -0
  772. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/build_tables.o +0 -0
  773. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/lex_conflict_manager.o +0 -0
  774. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/lex_item.o +0 -0
  775. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/lex_item_transitions.o +0 -0
  776. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/lookahead_set.o +0 -0
  777. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/parse_item.o +0 -0
  778. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/parse_item_set_builder.o +0 -0
  779. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/recovery_tokens.o +0 -0
  780. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/build_tables/rule_can_be_blank.o +0 -0
  781. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/compile.o +0 -0
  782. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/generate_code/c_code.o +0 -0
  783. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/lex_table.o +0 -0
  784. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/parse_grammar.o +0 -0
  785. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/parse_table.o +0 -0
  786. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/precedence_range.o +0 -0
  787. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/expand_repeats.o +0 -0
  788. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/expand_tokens.o +0 -0
  789. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/extract_choices.o +0 -0
  790. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/extract_tokens.o +0 -0
  791. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/flatten_grammar.o +0 -0
  792. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/intern_symbols.o +0 -0
  793. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/is_token.o +0 -0
  794. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/normalize_rules.o +0 -0
  795. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/parse_regex.o +0 -0
  796. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/prepare_grammar.o +0 -0
  797. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/prepare_grammar/token_description.o +0 -0
  798. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rule.o +0 -0
  799. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/blank.o +0 -0
  800. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/built_in_symbols.o +0 -0
  801. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/character_range.o +0 -0
  802. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/character_set.o +0 -0
  803. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/choice.o +0 -0
  804. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/metadata.o +0 -0
  805. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/named_symbol.o +0 -0
  806. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/pattern.o +0 -0
  807. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/repeat.o +0 -0
  808. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/rules.o +0 -0
  809. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/seq.o +0 -0
  810. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/string.o +0 -0
  811. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/symbol.o +0 -0
  812. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/rules/visitor.o +0 -0
  813. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/syntax_grammar.o +0 -0
  814. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/util/string_helpers.o +0 -0
  815. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/compiler/src/compiler/variable.o +0 -0
  816. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/externals/utf8proc/utf8proc.o +0 -0
  817. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/document.o +0 -0
  818. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/error_costs.o +0 -0
  819. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/language.o +0 -0
  820. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/lexer.o +0 -0
  821. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/node.o +0 -0
  822. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/parser.o +0 -0
  823. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/stack.o +0 -0
  824. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/string_input.o +0 -0
  825. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/tree.o +0 -0
  826. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/runtime/src/runtime/utf16.o +0 -0
  827. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/build_tables/distinctive_tokens_spec.o +0 -0
  828. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/build_tables/lex_conflict_manager_spec.o +0 -0
  829. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/build_tables/lex_item_spec.o +0 -0
  830. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/build_tables/parse_item_set_builder_spec.o +0 -0
  831. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/build_tables/rule_can_be_blank_spec.o +0 -0
  832. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/prepare_grammar/expand_repeats_spec.o +0 -0
  833. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/prepare_grammar/expand_tokens_spec.o +0 -0
  834. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/prepare_grammar/extract_choices_spec.o +0 -0
  835. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/prepare_grammar/extract_tokens_spec.o +0 -0
  836. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/prepare_grammar/flatten_grammar_spec.o +0 -0
  837. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/prepare_grammar/intern_symbols_spec.o +0 -0
  838. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/prepare_grammar/parse_regex_spec.o +0 -0
  839. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/rules/character_set_spec.o +0 -0
  840. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/rules/choice_spec.o +0 -0
  841. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/rules/repeat_spec.o +0 -0
  842. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/compiler/util/string_helpers_spec.o +0 -0
  843. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/encoding_helpers.o +0 -0
  844. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/load_language.o +0 -0
  845. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/point_helpers.o +0 -0
  846. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/random_helpers.o +0 -0
  847. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/read_test_entries.o +0 -0
  848. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/record_alloc.o +0 -0
  849. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/rule_helpers.o +0 -0
  850. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/scope_sequence.o +0 -0
  851. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/spy_input.o +0 -0
  852. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/spy_logger.o +0 -0
  853. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/stderr_logger.o +0 -0
  854. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/stream_methods.o +0 -0
  855. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/helpers/tree_helpers.o +0 -0
  856. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/integration/compile_grammar_spec.o +0 -0
  857. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/integration/corpus_specs.o +0 -0
  858. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/runtime/document_spec.o +0 -0
  859. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/runtime/node_spec.o +0 -0
  860. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/runtime/parser_spec.o +0 -0
  861. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/runtime/stack_spec.o +0 -0
  862. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/runtime/tree_spec.o +0 -0
  863. data/ext/tree-sitter/tree-sitter/out/Release/obj.target/tests/spec/specs.o +0 -0
  864. data/ext/tree-sitter/tree-sitter/out/Release/tests +0 -0
  865. data/ext/tree-sitter/tree-sitter/project.Makefile +0 -6
  866. data/ext/tree-sitter/tree-sitter/runtime.target.mk +0 -174
  867. data/ext/tree-sitter/tree-sitter/spec/compiler/build_tables/distinctive_tokens_spec.cc +0 -34
  868. data/ext/tree-sitter/tree-sitter/spec/compiler/build_tables/lex_conflict_manager_spec.cc +0 -88
  869. data/ext/tree-sitter/tree-sitter/spec/compiler/build_tables/parse_item_set_builder_spec.cc +0 -133
  870. data/ext/tree-sitter/tree-sitter/spec/compiler/prepare_grammar/expand_repeats_spec.cc +0 -152
  871. data/ext/tree-sitter/tree-sitter/spec/compiler/prepare_grammar/expand_tokens_spec.cc +0 -109
  872. data/ext/tree-sitter/tree-sitter/spec/compiler/prepare_grammar/extract_choices_spec.cc +0 -106
  873. data/ext/tree-sitter/tree-sitter/spec/compiler/prepare_grammar/extract_tokens_spec.cc +0 -251
  874. data/ext/tree-sitter/tree-sitter/spec/compiler/prepare_grammar/flatten_grammar_spec.cc +0 -89
  875. data/ext/tree-sitter/tree-sitter/spec/compiler/prepare_grammar/intern_symbols_spec.cc +0 -89
  876. data/ext/tree-sitter/tree-sitter/spec/compiler/prepare_grammar/parse_regex_spec.cc +0 -245
  877. data/ext/tree-sitter/tree-sitter/spec/compiler/rules/choice_spec.cc +0 -53
  878. data/ext/tree-sitter/tree-sitter/spec/compiler/rules/repeat_spec.cc +0 -22
  879. data/ext/tree-sitter/tree-sitter/spec/fixtures/error_corpus/c_errors.txt +0 -130
  880. data/ext/tree-sitter/tree-sitter/spec/fixtures/error_corpus/javascript_errors.txt +0 -157
  881. data/ext/tree-sitter/tree-sitter/spec/fixtures/external_scanners/extra_external_tokens.c +0 -42
  882. data/ext/tree-sitter/tree-sitter/spec/helpers/equals_pointer.h +0 -37
  883. data/ext/tree-sitter/tree-sitter/spec/helpers/load_language.cc +0 -206
  884. data/ext/tree-sitter/tree-sitter/spec/helpers/load_language.h +0 -12
  885. data/ext/tree-sitter/tree-sitter/spec/helpers/random_helpers.cc +0 -35
  886. data/ext/tree-sitter/tree-sitter/spec/helpers/random_helpers.h +0 -8
  887. data/ext/tree-sitter/tree-sitter/spec/helpers/read_test_entries.h +0 -15
  888. data/ext/tree-sitter/tree-sitter/spec/helpers/rule_helpers.cc +0 -55
  889. data/ext/tree-sitter/tree-sitter/spec/helpers/rule_helpers.h +0 -21
  890. data/ext/tree-sitter/tree-sitter/spec/helpers/stream_methods.cc +0 -140
  891. data/ext/tree-sitter/tree-sitter/spec/helpers/tree_helpers.cc +0 -50
  892. data/ext/tree-sitter/tree-sitter/spec/integration/compile_grammar_spec.cc +0 -847
  893. data/ext/tree-sitter/tree-sitter/spec/integration/corpus_specs.cc +0 -185
  894. data/ext/tree-sitter/tree-sitter/spec/runtime/tree_spec.cc +0 -439
  895. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/build_lex_table.cc +0 -195
  896. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/build_lex_table.h +0 -18
  897. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/build_parse_table.cc +0 -604
  898. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/build_parse_table.h +0 -22
  899. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/build_tables.cc +0 -27
  900. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/build_tables.h +0 -24
  901. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/conflict_type.h +0 -16
  902. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lex_conflict_manager.cc +0 -55
  903. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/lex_conflict_manager.h +0 -31
  904. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/recovery_tokens.cc +0 -89
  905. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/recovery_tokens.h +0 -19
  906. data/ext/tree-sitter/tree-sitter/src/compiler/build_tables/remove_duplicate_states.h +0 -65
  907. data/ext/tree-sitter/tree-sitter/src/compiler/compile.h +0 -16
  908. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/is_token.cc +0 -30
  909. data/ext/tree-sitter/tree-sitter/src/compiler/prepare_grammar/is_token.h +0 -14
  910. data/ext/tree-sitter/tree-sitter/src/compiler/rules.h +0 -28
  911. data/ext/tree-sitter/tree-sitter/src/compiler/rules/blank.cc +0 -36
  912. data/ext/tree-sitter/tree-sitter/src/compiler/rules/built_in_symbols.cc +0 -19
  913. data/ext/tree-sitter/tree-sitter/src/compiler/rules/built_in_symbols.h +0 -16
  914. data/ext/tree-sitter/tree-sitter/src/compiler/rules/character_range.cc +0 -36
  915. data/ext/tree-sitter/tree-sitter/src/compiler/rules/character_range.h +0 -25
  916. data/ext/tree-sitter/tree-sitter/src/compiler/rules/named_symbol.cc +0 -35
  917. data/ext/tree-sitter/tree-sitter/src/compiler/rules/pattern.cc +0 -36
  918. data/ext/tree-sitter/tree-sitter/src/compiler/rules/rules.cc +0 -108
  919. data/ext/tree-sitter/tree-sitter/src/compiler/rules/string.cc +0 -35
  920. data/ext/tree-sitter/tree-sitter/src/compiler/rules/symbol.cc +0 -82
  921. data/ext/tree-sitter/tree-sitter/src/compiler/rules/visitor.cc +0 -44
  922. data/ext/tree-sitter/tree-sitter/src/compiler/rules/visitor.h +0 -234
  923. data/ext/tree-sitter/tree-sitter/src/compiler/variable.cc +0 -11
  924. data/ext/tree-sitter/tree-sitter/src/compiler/variable.h +0 -27
  925. data/ext/tree-sitter/tree-sitter/src/runtime/error_costs.c +0 -28
  926. data/ext/tree-sitter/tree-sitter/src/runtime/tree_path.h +0 -217
  927. data/ext/tree-sitter/tree-sitter/tests.Makefile +0 -6
  928. data/ext/tree-sitter/tree-sitter/tests.target.mk +0 -176
  929. data/test/tree-sitter/fixtures/ruby/grammar.json +0 -4803
  930. data/test/tree-sitter/test_grammar.rb +0 -34
@@ -3,6 +3,6 @@
3
3
 
4
4
  #include "runtime/tree.h"
5
5
 
6
- TSNode ts_node_make(const Tree *, uint32_t character, uint32_t byte, uint32_t row);
6
+ TSNode ts_node_make(const Tree *, uint32_t byte, uint32_t row);
7
7
 
8
8
  #endif
@@ -13,23 +13,16 @@
13
13
  #include "runtime/reduce_action.h"
14
14
  #include "runtime/error_costs.h"
15
15
 
16
- #define LOG(...) \
17
- if (self->lexer.logger.log) { \
18
- snprintf(self->lexer.debug_buffer, TS_DEBUG_BUFFER_SIZE, __VA_ARGS__); \
19
- self->lexer.logger.log(self->lexer.logger.payload, TSLogTypeParse, \
20
- self->lexer.debug_buffer); \
21
- } \
22
- if (self->print_debugging_graphs) { \
23
- fprintf(stderr, "graph {\nlabel=\""); \
24
- fprintf(stderr, __VA_ARGS__); \
25
- fprintf(stderr, "\"\n}\n\n"); \
16
+ #define LOG(...) \
17
+ if (self->lexer.logger.log || self->print_debugging_graphs) { \
18
+ snprintf(self->lexer.debug_buffer, TREE_SITTER_SERIALIZATION_BUFFER_SIZE, __VA_ARGS__); \
19
+ parser__log(self); \
26
20
  }
27
21
 
28
- #define LOG_STACK() \
29
- if (self->print_debugging_graphs) { \
30
- ts_stack_print_dot_graph(self->stack, self->language->symbol_names, \
31
- stderr); \
32
- fputs("\n\n", stderr); \
22
+ #define LOG_STACK() \
23
+ if (self->print_debugging_graphs) { \
24
+ ts_stack_print_dot_graph(self->stack, self->language, stderr); \
25
+ fputs("\n\n", stderr); \
33
26
  }
34
27
 
35
28
  #define LOG_TREE() \
@@ -40,26 +33,42 @@
40
33
 
41
34
  #define SYM_NAME(symbol) ts_language_symbol_name(self->language, symbol)
42
35
 
43
- typedef struct {
44
- Parser *parser;
45
- TSSymbol lookahead_symbol;
46
- TreeArray *trees_above_error;
47
- uint32_t tree_count_above_error;
48
- bool found_repair;
49
- ReduceAction best_repair;
50
- TSStateId best_repair_next_state;
51
- uint32_t best_repair_skip_count;
52
- } ErrorRepairSession;
36
+ static const unsigned MAX_VERSION_COUNT = 6;
37
+ static const unsigned MAX_SUMMARY_DEPTH = 16;
38
+ static const unsigned MAX_COST_DIFFERENCE = 16 * ERROR_COST_PER_SKIPPED_TREE;
53
39
 
54
40
  typedef struct {
55
- Parser *parser;
56
- TSSymbol lookahead_symbol;
57
- } SkipPrecedingTreesSession;
58
-
59
- static void parser__push(Parser *self, StackVersion version, Tree *tree,
60
- TSStateId state) {
61
- ts_stack_push(self->stack, version, tree, false, state);
62
- ts_tree_release(tree);
41
+ unsigned cost;
42
+ unsigned node_count;
43
+ int dynamic_precedence;
44
+ bool is_in_error;
45
+ } ErrorStatus;
46
+
47
+ typedef enum {
48
+ ErrorComparisonTakeLeft,
49
+ ErrorComparisonPreferLeft,
50
+ ErrorComparisonNone,
51
+ ErrorComparisonPreferRight,
52
+ ErrorComparisonTakeRight,
53
+ } ErrorComparison;
54
+
55
+ static void parser__log(Parser *self) {
56
+ if (self->lexer.logger.log) {
57
+ self->lexer.logger.log(
58
+ self->lexer.logger.payload,
59
+ TSLogTypeParse,
60
+ self->lexer.debug_buffer
61
+ );
62
+ }
63
+
64
+ if (self->print_debugging_graphs) {
65
+ fprintf(stderr, "graph {\nlabel=\"");
66
+ for (char *c = &self->lexer.debug_buffer[0]; *c != 0; c++) {
67
+ if (*c == '"') fputc('\\', stderr);
68
+ fputc(*c, stderr);
69
+ }
70
+ fprintf(stderr, "\"\n}\n\n");
71
+ }
63
72
  }
64
73
 
65
74
  static bool parser__breakdown_top_of_stack(Parser *self, StackVersion version) {
@@ -67,20 +76,19 @@ static bool parser__breakdown_top_of_stack(Parser *self, StackVersion version) {
67
76
  bool pending = false;
68
77
 
69
78
  do {
70
- StackPopResult pop = ts_stack_pop_pending(self->stack, version);
71
- if (!pop.slices.size)
72
- break;
79
+ StackSliceArray pop = ts_stack_pop_pending(self->stack, version);
80
+ if (!pop.size) break;
73
81
 
74
82
  did_break_down = true;
75
83
  pending = false;
76
- for (uint32_t i = 0; i < pop.slices.size; i++) {
77
- StackSlice slice = pop.slices.contents[i];
78
- TSStateId state = ts_stack_top_state(self->stack, slice.version);
84
+ for (uint32_t i = 0; i < pop.size; i++) {
85
+ StackSlice slice = pop.contents[i];
86
+ TSStateId state = ts_stack_state(self->stack, slice.version);
79
87
  Tree *parent = *array_front(&slice.trees);
80
88
 
81
- for (uint32_t j = 0; j < parent->child_count; j++) {
82
- Tree *child = parent->children[j];
83
- pending = child->child_count > 0;
89
+ for (uint32_t j = 0; j < parent->children.size; j++) {
90
+ Tree *child = parent->children.contents[j];
91
+ pending = child->children.size > 0;
84
92
 
85
93
  if (child->symbol == ts_builtin_sym_error) {
86
94
  state = ERROR_STATE;
@@ -88,126 +96,137 @@ static bool parser__breakdown_top_of_stack(Parser *self, StackVersion version) {
88
96
  state = ts_language_next_state(self->language, state, child->symbol);
89
97
  }
90
98
 
99
+ ts_tree_retain(child);
91
100
  ts_stack_push(self->stack, slice.version, child, pending, state);
92
101
  }
93
102
 
94
103
  for (uint32_t j = 1; j < slice.trees.size; j++) {
95
104
  Tree *tree = slice.trees.contents[j];
96
- parser__push(self, slice.version, tree, state);
105
+ ts_stack_push(self->stack, slice.version, tree, false, state);
97
106
  }
98
107
 
108
+ ts_tree_release(&self->tree_pool, parent);
109
+ array_delete(&slice.trees);
110
+
99
111
  LOG("breakdown_top_of_stack tree:%s", SYM_NAME(parent->symbol));
100
112
  LOG_STACK();
101
-
102
- ts_stack_decrease_push_count(self->stack, slice.version,
103
- parent->child_count + 1);
104
- ts_tree_release(parent);
105
- array_delete(&slice.trees);
106
113
  }
107
114
  } while (pending);
108
115
 
109
116
  return did_break_down;
110
117
  }
111
118
 
112
- static bool parser__breakdown_lookahead(Parser *self, Tree **lookahead,
119
+ static void parser__breakdown_lookahead(Parser *self, Tree **lookahead,
113
120
  TSStateId state,
114
121
  ReusableNode *reusable_node) {
115
- bool result = false;
116
- while (reusable_node->tree->child_count > 0 &&
117
- (self->is_split || reusable_node->tree->parse_state != state ||
118
- reusable_node->tree->fragile_left ||
119
- reusable_node->tree->fragile_right)) {
122
+ bool did_break_down = false;
123
+ while (reusable_node->tree->children.size > 0 && reusable_node->tree->parse_state != state) {
120
124
  LOG("state_mismatch sym:%s", SYM_NAME(reusable_node->tree->symbol));
121
125
  reusable_node_breakdown(reusable_node);
122
- result = true;
126
+ did_break_down = true;
123
127
  }
124
128
 
125
- if (result) {
126
- ts_tree_release(*lookahead);
129
+ if (did_break_down) {
130
+ ts_tree_release(&self->tree_pool, *lookahead);
127
131
  ts_tree_retain(*lookahead = reusable_node->tree);
128
132
  }
129
-
130
- return result;
131
133
  }
132
134
 
133
- static inline bool ts_lex_mode_eq(TSLexMode self, TSLexMode other) {
134
- return self.lex_state == other.lex_state &&
135
- self.external_lex_state == other.external_lex_state;
136
- }
135
+ static ErrorComparison parser__compare_versions(Parser *self, ErrorStatus a, ErrorStatus b) {
136
+ if (!a.is_in_error && b.is_in_error) {
137
+ if (a.cost < b.cost) {
138
+ return ErrorComparisonTakeLeft;
139
+ } else {
140
+ return ErrorComparisonPreferLeft;
141
+ }
142
+ }
137
143
 
138
- static bool parser__can_reuse(Parser *self, TSStateId state, Tree *tree,
139
- TableEntry *table_entry) {
140
- TSLexMode current_lex_mode = self->language->lex_modes[state];
141
- if (ts_lex_mode_eq(tree->first_leaf.lex_mode, current_lex_mode))
142
- return true;
143
- if (current_lex_mode.external_lex_state != 0)
144
- return false;
145
- if (tree->size.bytes == 0)
146
- return false;
147
- if (!table_entry->is_reusable)
148
- return false;
149
- if (!table_entry->depends_on_lookahead)
150
- return true;
151
- return tree->child_count > 1 && tree->error_cost == 0;
152
- }
144
+ if (a.is_in_error && !b.is_in_error) {
145
+ if (b.cost < a.cost) {
146
+ return ErrorComparisonTakeRight;
147
+ } else {
148
+ return ErrorComparisonPreferRight;
149
+ }
150
+ }
153
151
 
154
- static bool parser__condense_stack(Parser *self) {
155
- bool result = false;
156
- for (StackVersion i = 0; i < ts_stack_version_count(self->stack); i++) {
157
- if (ts_stack_is_halted(self->stack, i)) {
158
- ts_stack_remove_version(self->stack, i);
159
- result = true;
160
- i--;
161
- continue;
152
+ if (a.cost < b.cost) {
153
+ if ((b.cost - a.cost) * (1 + a.node_count) > MAX_COST_DIFFERENCE) {
154
+ return ErrorComparisonTakeLeft;
155
+ } else {
156
+ return ErrorComparisonPreferLeft;
162
157
  }
158
+ }
163
159
 
164
- ErrorStatus error_status = ts_stack_error_status(self->stack, i);
160
+ if (b.cost < a.cost) {
161
+ if ((a.cost - b.cost) * (1 + b.node_count) > MAX_COST_DIFFERENCE) {
162
+ return ErrorComparisonTakeRight;
163
+ } else {
164
+ return ErrorComparisonPreferRight;
165
+ }
166
+ }
165
167
 
166
- for (StackVersion j = 0; j < i; j++) {
167
- if (ts_stack_merge(self->stack, j, i)) {
168
- result = true;
169
- i--;
170
- break;
171
- }
168
+ if (a.dynamic_precedence > b.dynamic_precedence) return ErrorComparisonPreferLeft;
169
+ if (b.dynamic_precedence > a.dynamic_precedence) return ErrorComparisonPreferRight;
170
+ return ErrorComparisonNone;
171
+ }
172
172
 
173
- switch (error_status_compare(error_status,
174
- ts_stack_error_status(self->stack, j))) {
175
- case -1:
176
- ts_stack_remove_version(self->stack, j);
177
- result = true;
178
- i--;
179
- j--;
180
- break;
181
- case 1:
182
- ts_stack_remove_version(self->stack, i);
183
- result = true;
184
- i--;
185
- break;
186
- }
173
+ static ErrorStatus parser__version_status(Parser *self, StackVersion version) {
174
+ unsigned cost = ts_stack_error_cost(self->stack, version);
175
+ bool is_paused = ts_stack_is_paused(self->stack, version);
176
+ if (is_paused) cost += ERROR_COST_PER_SKIPPED_TREE;
177
+ return (ErrorStatus) {
178
+ .cost = cost,
179
+ .node_count = ts_stack_node_count_since_error(self->stack, version),
180
+ .dynamic_precedence = ts_stack_dynamic_precedence(self->stack, version),
181
+ .is_in_error = is_paused || ts_stack_state(self->stack, version) == ERROR_STATE
182
+ };
183
+ }
184
+
185
+ static bool parser__better_version_exists(Parser *self, StackVersion version,
186
+ bool is_in_error, unsigned cost) {
187
+ if (self->finished_tree && self->finished_tree->error_cost <= cost) return true;
188
+
189
+ Length position = ts_stack_position(self->stack, version);
190
+ ErrorStatus status = {
191
+ .cost = cost,
192
+ .is_in_error = is_in_error,
193
+ .dynamic_precedence = ts_stack_dynamic_precedence(self->stack, version),
194
+ .node_count = ts_stack_node_count_since_error(self->stack, version),
195
+ };
196
+
197
+ for (StackVersion i = 0, n = ts_stack_version_count(self->stack); i < n; i++) {
198
+ if (i == version ||
199
+ !ts_stack_is_active(self->stack, i) ||
200
+ ts_stack_position(self->stack, i).bytes < position.bytes) continue;
201
+ ErrorStatus status_i = parser__version_status(self, i);
202
+ switch (parser__compare_versions(self, status, status_i)) {
203
+ case ErrorComparisonTakeRight:
204
+ return true;
205
+ case ErrorComparisonPreferRight:
206
+ if (ts_stack_can_merge(self->stack, i, version)) return true;
207
+ default:
208
+ break;
187
209
  }
188
210
  }
189
- return result;
211
+
212
+ return false;
190
213
  }
191
214
 
192
- static void parser__restore_external_scanner(Parser *self, StackVersion version) {
193
- const TSExternalTokenState *state = ts_stack_external_token_state(self->stack, version);
194
- if (self->lexer.last_external_token_state != state) {
195
- LOG("restore_external_scanner");
196
- self->lexer.last_external_token_state = state;
197
- if (state) {
198
- self->language->external_scanner.deserialize(
199
- self->external_scanner_payload,
200
- *state
201
- );
202
- } else {
203
- self->language->external_scanner.reset(self->external_scanner_payload);
204
- }
215
+ static void parser__restore_external_scanner(Parser *self, Tree *external_token) {
216
+ if (external_token) {
217
+ self->language->external_scanner.deserialize(
218
+ self->external_scanner_payload,
219
+ ts_external_token_state_data(&external_token->external_token_state),
220
+ external_token->external_token_state.length
221
+ );
222
+ } else {
223
+ self->language->external_scanner.deserialize(self->external_scanner_payload, NULL, 0);
205
224
  }
206
225
  }
207
226
 
208
- static Tree *parser__lex(Parser *self, StackVersion version) {
209
- TSStateId parse_state = ts_stack_top_state(self->stack, version);
210
- Length start_position = ts_stack_top_position(self->stack, version);
227
+ static Tree *parser__lex(Parser *self, StackVersion version, TSStateId parse_state) {
228
+ Length start_position = ts_stack_position(self->stack, version);
229
+ Tree *external_token = ts_stack_last_external_token(self->stack, version);
211
230
  TSLexMode lex_mode = self->language->lex_modes[parse_state];
212
231
  const bool *valid_external_tokens = ts_language_enabled_external_tokens(
213
232
  self->language,
@@ -215,43 +234,68 @@ static Tree *parser__lex(Parser *self, StackVersion version) {
215
234
  );
216
235
 
217
236
  bool found_external_token = false;
218
- bool found_error = false;
237
+ bool error_mode = parse_state == ERROR_STATE;
219
238
  bool skipped_error = false;
220
239
  int32_t first_error_character = 0;
221
- Length error_start_position, error_end_position;
240
+ Length error_start_position = length_zero();
241
+ Length error_end_position = length_zero();
242
+ uint32_t last_byte_scanned = start_position.bytes;
222
243
  ts_lexer_reset(&self->lexer, start_position);
223
244
 
224
245
  for (;;) {
225
246
  Length current_position = self->lexer.current_position;
226
247
 
227
248
  if (valid_external_tokens) {
228
- LOG("lex_external state:%d, row:%u, column:%u", lex_mode.external_lex_state,
229
- current_position.extent.row, current_position.extent.column);
230
- parser__restore_external_scanner(self, version);
249
+ LOG(
250
+ "lex_external state:%d, row:%u, column:%u",
251
+ lex_mode.external_lex_state,
252
+ current_position.extent.row,
253
+ current_position.extent.column
254
+ );
231
255
  ts_lexer_start(&self->lexer);
232
- if (self->language->external_scanner.scan(self->external_scanner_payload,
233
- &self->lexer.data, valid_external_tokens)) {
234
- found_external_token = true;
235
- break;
256
+ parser__restore_external_scanner(self, external_token);
257
+ if (self->language->external_scanner.scan(
258
+ self->external_scanner_payload,
259
+ &self->lexer.data,
260
+ valid_external_tokens
261
+ )) {
262
+ if (length_is_undefined(self->lexer.token_end_position)) {
263
+ self->lexer.token_end_position = self->lexer.current_position;
264
+ }
265
+
266
+ if (!error_mode || self->lexer.token_end_position.bytes > current_position.bytes) {
267
+ found_external_token = true;
268
+ break;
269
+ }
270
+ }
271
+
272
+ if (self->lexer.current_position.bytes > last_byte_scanned) {
273
+ last_byte_scanned = self->lexer.current_position.bytes;
236
274
  }
237
275
  ts_lexer_reset(&self->lexer, current_position);
238
276
  }
239
277
 
240
- LOG("lex_internal state:%d, row:%u, column:%u", lex_mode.lex_state,
241
- current_position.extent.row, current_position.extent.column);
278
+ LOG(
279
+ "lex_internal state:%d, row:%u, column:%u",
280
+ lex_mode.lex_state,
281
+ current_position.extent.row,
282
+ current_position.extent.column
283
+ );
242
284
  ts_lexer_start(&self->lexer);
243
285
  if (self->language->lex_fn(&self->lexer.data, lex_mode.lex_state)) {
244
286
  break;
245
287
  }
246
288
 
247
- if (!found_error) {
248
- LOG("retry_in_error_mode");
249
- found_error = true;
289
+ if (!error_mode) {
290
+ error_mode = true;
250
291
  lex_mode = self->language->lex_modes[ERROR_STATE];
251
292
  valid_external_tokens = ts_language_enabled_external_tokens(
252
293
  self->language,
253
294
  lex_mode.external_lex_state
254
295
  );
296
+ if (self->lexer.current_position.bytes > last_byte_scanned) {
297
+ last_byte_scanned = self->lexer.current_position.bytes;
298
+ }
255
299
  ts_lexer_reset(&self->lexer, start_position);
256
300
  continue;
257
301
  }
@@ -275,32 +319,52 @@ static Tree *parser__lex(Parser *self, StackVersion version) {
275
319
  error_end_position = self->lexer.current_position;
276
320
  }
277
321
 
322
+ if (self->lexer.current_position.bytes > last_byte_scanned) {
323
+ last_byte_scanned = self->lexer.current_position.bytes;
324
+ }
325
+
278
326
  Tree *result;
279
327
  if (skipped_error) {
280
328
  Length padding = length_sub(error_start_position, start_position);
281
329
  Length size = length_sub(error_end_position, error_start_position);
282
- ts_lexer_reset(&self->lexer, error_end_position);
283
- result = ts_tree_make_error(size, padding, first_error_character);
330
+ result = ts_tree_make_error(&self->tree_pool, size, padding, first_error_character, self->language);
284
331
  } else {
332
+ if (self->lexer.token_end_position.bytes < self->lexer.token_start_position.bytes) {
333
+ self->lexer.token_start_position = self->lexer.token_end_position;
334
+ }
335
+
285
336
  TSSymbol symbol = self->lexer.data.result_symbol;
337
+ Length padding = length_sub(self->lexer.token_start_position, start_position);
338
+ Length size = length_sub(self->lexer.token_end_position, self->lexer.token_start_position);
339
+
286
340
  if (found_external_token) {
287
341
  symbol = self->language->external_scanner.symbol_map[symbol];
342
+ } else if (symbol == self->language->keyword_capture_token && symbol != 0) {
343
+ uint32_t end_byte = self->lexer.token_end_position.bytes;
344
+ ts_lexer_reset(&self->lexer, self->lexer.token_start_position);
345
+ ts_lexer_start(&self->lexer);
346
+ if (
347
+ self->language->keyword_lex_fn(&self->lexer.data, 0) &&
348
+ self->lexer.token_end_position.bytes == end_byte &&
349
+ ts_language_has_actions(self->language, parse_state, self->lexer.data.result_symbol)
350
+ ) {
351
+ symbol = self->lexer.data.result_symbol;
352
+ }
288
353
  }
289
354
 
290
- Length padding = length_sub(self->lexer.token_start_position, start_position);
291
- Length size = length_sub(self->lexer.current_position, self->lexer.token_start_position);
292
- TSSymbolMetadata metadata = ts_language_symbol_metadata(self->language, symbol);
293
- result = ts_tree_make_leaf(symbol, padding, size, metadata);
355
+ result = ts_tree_make_leaf(&self->tree_pool, symbol, padding, size, self->language);
294
356
 
295
357
  if (found_external_token) {
296
358
  result->has_external_tokens = true;
297
- result->has_external_token_state = true;
298
- memset(result->external_token_state, 0, sizeof(TSExternalTokenState));
299
- self->language->external_scanner.serialize(self->external_scanner_payload, result->external_token_state);
300
- self->lexer.last_external_token_state = &result->external_token_state;
359
+ unsigned length = self->language->external_scanner.serialize(
360
+ self->external_scanner_payload,
361
+ self->lexer.debug_buffer
362
+ );
363
+ ts_external_token_state_init(&result->external_token_state, self->lexer.debug_buffer, length);
301
364
  }
302
365
  }
303
366
 
367
+ result->bytes_scanned = last_byte_scanned - start_position.bytes + 1;
304
368
  result->parse_state = parse_state;
305
369
  result->first_leaf.lex_mode = lex_mode;
306
370
 
@@ -308,93 +372,158 @@ static Tree *parser__lex(Parser *self, StackVersion version) {
308
372
  return result;
309
373
  }
310
374
 
311
- static void parser__clear_cached_token(Parser *self) {
312
- ts_tree_release(self->cached_token);
313
- self->cached_token = NULL;
375
+ static Tree *parser__get_cached_token(Parser *self, size_t byte_index, Tree *last_external_token) {
376
+ TokenCache *cache = &self->token_cache;
377
+ if (cache->token &&
378
+ cache->byte_index == byte_index &&
379
+ ts_tree_external_token_state_eq(cache->last_external_token, last_external_token)) {
380
+ return cache->token;
381
+ } else {
382
+ return NULL;
383
+ }
384
+ }
385
+
386
+ static void parser__set_cached_token(Parser *self, size_t byte_index, Tree *last_external_token,
387
+ Tree *token) {
388
+ TokenCache *cache = &self->token_cache;
389
+ if (token) ts_tree_retain(token);
390
+ if (last_external_token) ts_tree_retain(last_external_token);
391
+ if (cache->token) ts_tree_release(&self->tree_pool, cache->token);
392
+ if (cache->last_external_token) ts_tree_release(&self->tree_pool, cache->last_external_token);
393
+ cache->token = token;
394
+ cache->byte_index = byte_index;
395
+ cache->last_external_token = last_external_token;
396
+ }
397
+
398
+ static bool parser__can_reuse_first_leaf(Parser *self, TSStateId state, Tree *tree,
399
+ TableEntry *table_entry,
400
+ ReusableNode *next_reusable_node) {
401
+ TSLexMode current_lex_mode = self->language->lex_modes[state];
402
+
403
+ // If the token was created in a state with the same set of lookaheads, it is reusable.
404
+ if (tree->first_leaf.lex_mode.lex_state == current_lex_mode.lex_state &&
405
+ tree->first_leaf.lex_mode.external_lex_state == current_lex_mode.external_lex_state &&
406
+ (tree->first_leaf.symbol != self->language->keyword_capture_token ||
407
+ tree->parse_state == state)) return true;
408
+
409
+ // Empty tokens are not reusable in states with different lookaheads.
410
+ if (tree->size.bytes == 0 && tree->symbol != ts_builtin_sym_end) return false;
411
+
412
+ // If the current state allows external tokens or other tokens that conflict with this
413
+ // token, this token is not reusable.
414
+ return current_lex_mode.external_lex_state == 0 && table_entry->is_reusable;
314
415
  }
315
416
 
316
- static Tree *parser__get_lookahead(Parser *self, StackVersion version,
317
- ReusableNode *reusable_node,
318
- bool *is_fresh) {
319
- Length position = ts_stack_top_position(self->stack, version);
417
+ static Tree *parser__get_lookahead(Parser *self, StackVersion version, TSStateId *state,
418
+ ReusableNode *reusable_node, TableEntry *table_entry) {
419
+ Length position = ts_stack_position(self->stack, version);
420
+ Tree *last_external_token = ts_stack_last_external_token(self->stack, version);
320
421
 
321
- while (reusable_node->tree) {
422
+ Tree *result;
423
+ while ((result = reusable_node->tree)) {
322
424
  if (reusable_node->byte_index > position.bytes) {
323
- LOG("before_reusable_node sym:%s", SYM_NAME(reusable_node->tree->symbol));
425
+ LOG("before_reusable_node symbol:%s", SYM_NAME(result->symbol));
324
426
  break;
325
427
  }
326
428
 
327
429
  if (reusable_node->byte_index < position.bytes) {
328
- LOG("past_reusable sym:%s", SYM_NAME(reusable_node->tree->symbol));
430
+ LOG("past_reusable_node symbol:%s", SYM_NAME(result->symbol));
329
431
  reusable_node_pop(reusable_node);
330
432
  continue;
331
433
  }
332
434
 
333
- if (reusable_node->tree->has_changes) {
334
- LOG("cant_reuse_changed tree:%s, size:%u",
335
- SYM_NAME(reusable_node->tree->symbol),
336
- reusable_node->tree->size.bytes);
337
- if (!reusable_node_breakdown(reusable_node)) {
338
- reusable_node_pop(reusable_node);
339
- parser__breakdown_top_of_stack(self, version);
340
- }
435
+ if (!ts_tree_external_token_state_eq(reusable_node->last_external_token, last_external_token)) {
436
+ LOG("reusable_node_has_different_external_scanner_state symbol:%s", SYM_NAME(result->symbol));
437
+ reusable_node_pop(reusable_node);
341
438
  continue;
342
439
  }
343
440
 
344
- if (reusable_node->tree->symbol == ts_builtin_sym_error) {
345
- LOG("cant_reuse_error tree:%s, size:%u",
346
- SYM_NAME(reusable_node->tree->symbol),
347
- reusable_node->tree->size.bytes);
348
- if (!reusable_node_breakdown(reusable_node)) {
349
- reusable_node_pop(reusable_node);
350
- parser__breakdown_top_of_stack(self, version);
351
- }
352
- continue;
441
+ const char *reason = NULL;
442
+ if (result->has_changes) {
443
+ reason = "has_changes";
444
+ } else if (result->symbol == ts_builtin_sym_error) {
445
+ reason = "is_error";
446
+ } else if (result->is_missing) {
447
+ reason = "is_missing";
448
+ } else if (result->fragile_left || result->fragile_right) {
449
+ reason = "is_fragile";
450
+ } else if (self->in_ambiguity && result->children.size) {
451
+ reason = "in_ambiguity";
353
452
  }
354
453
 
355
- if (!ts_external_token_state_eq(
356
- reusable_node->preceding_external_token_state,
357
- ts_stack_external_token_state(self->stack, version))) {
358
- LOG("cant_reuse_external_tokens tree:%s, size:%u",
359
- SYM_NAME(reusable_node->tree->symbol),
360
- reusable_node->tree->size.bytes);
454
+ if (reason) {
455
+ LOG("cant_reuse_node_%s tree:%s", reason, SYM_NAME(result->symbol));
361
456
  if (!reusable_node_breakdown(reusable_node)) {
362
457
  reusable_node_pop(reusable_node);
363
458
  parser__breakdown_top_of_stack(self, version);
459
+ *state = ts_stack_state(self->stack, version);
364
460
  }
365
461
  continue;
366
462
  }
367
463
 
368
- Tree *result = reusable_node->tree;
464
+ ts_language_table_entry(self->language, *state, result->first_leaf.symbol, table_entry);
465
+ ReusableNode next_reusable_node = reusable_node_after_leaf(reusable_node);
466
+ if (!parser__can_reuse_first_leaf(self, *state, result, table_entry, &next_reusable_node)) {
467
+ LOG(
468
+ "cant_reuse_node symbol:%s, first_leaf_symbol:%s",
469
+ SYM_NAME(result->symbol),
470
+ SYM_NAME(result->first_leaf.symbol)
471
+ );
472
+ *reusable_node = next_reusable_node;
473
+ break;
474
+ }
475
+
476
+ LOG("reuse_node symbol:%s", SYM_NAME(result->symbol));
369
477
  ts_tree_retain(result);
370
478
  return result;
371
479
  }
372
480
 
373
- if (self->cached_token && position.bytes == self->cached_token_byte_index) {
374
- ts_tree_retain(self->cached_token);
375
- return self->cached_token;
481
+ if ((result = parser__get_cached_token(self, position.bytes, last_external_token))) {
482
+ ts_language_table_entry(self->language, *state, result->first_leaf.symbol, table_entry);
483
+ if (parser__can_reuse_first_leaf(self, *state, result, table_entry, NULL)) {
484
+ ts_tree_retain(result);
485
+ return result;
486
+ }
376
487
  }
377
488
 
378
- *is_fresh = true;
379
- return parser__lex(self, version);
489
+ result = parser__lex(self, version, *state);
490
+ parser__set_cached_token(self, position.bytes, last_external_token, result);
491
+ ts_language_table_entry(self->language, *state, result->symbol, table_entry);
492
+ return result;
380
493
  }
381
494
 
382
495
  static bool parser__select_tree(Parser *self, Tree *left, Tree *right) {
383
- if (!left)
384
- return true;
385
- if (!right)
386
- return false;
496
+ if (!left) return true;
497
+ if (!right) return false;
498
+
387
499
  if (right->error_cost < left->error_cost) {
388
500
  LOG("select_smaller_error symbol:%s, over_symbol:%s",
389
501
  SYM_NAME(right->symbol), SYM_NAME(left->symbol));
390
502
  return true;
391
503
  }
504
+
392
505
  if (left->error_cost < right->error_cost) {
393
506
  LOG("select_smaller_error symbol:%s, over_symbol:%s",
394
507
  SYM_NAME(left->symbol), SYM_NAME(right->symbol));
395
508
  return false;
396
509
  }
397
510
 
511
+ if (right->dynamic_precedence > left->dynamic_precedence) {
512
+ LOG("select_higher_precedence symbol:%s, prec:%u, over_symbol:%s, other_prec:%u",
513
+ SYM_NAME(right->symbol), right->dynamic_precedence, SYM_NAME(left->symbol),
514
+ left->dynamic_precedence);
515
+ return true;
516
+ }
517
+
518
+ if (left->dynamic_precedence > right->dynamic_precedence) {
519
+ LOG("select_higher_precedence symbol:%s, prec:%u, over_symbol:%s, other_prec:%u",
520
+ SYM_NAME(left->symbol), left->dynamic_precedence, SYM_NAME(right->symbol),
521
+ right->dynamic_precedence);
522
+ return false;
523
+ }
524
+
525
+ if (left->error_cost > 0) return true;
526
+
398
527
  int comparison = ts_tree_compare(left, right);
399
528
  switch (comparison) {
400
529
  case -1:
@@ -413,37 +542,11 @@ static bool parser__select_tree(Parser *self, Tree *left, Tree *right) {
413
542
  }
414
543
  }
415
544
 
416
- static bool parser__better_version_exists(Parser *self, StackVersion version,
417
- ErrorStatus my_error_status) {
418
- if (self->finished_tree &&
419
- self->finished_tree->error_cost <= my_error_status.cost)
420
- return true;
421
-
422
- for (StackVersion i = 0, n = ts_stack_version_count(self->stack); i < n; i++) {
423
- if (i == version || ts_stack_is_halted(self->stack, i))
424
- continue;
425
-
426
- switch (error_status_compare(my_error_status,
427
- ts_stack_error_status(self->stack, i))) {
428
- case -1:
429
- LOG("halt_other version:%u", i);
430
- ts_stack_halt(self->stack, i);
431
- break;
432
- case 1:
433
- return true;
434
- }
435
- }
436
-
437
- return false;
438
- }
439
-
440
545
  static void parser__shift(Parser *self, StackVersion version, TSStateId state,
441
546
  Tree *lookahead, bool extra) {
442
547
  if (extra != lookahead->extra) {
443
- TSSymbolMetadata metadata =
444
- ts_language_symbol_metadata(self->language, lookahead->symbol);
445
- if (metadata.structural && ts_stack_version_count(self->stack) > 1) {
446
- lookahead = ts_tree_make_copy(lookahead);
548
+ if (ts_stack_version_count(self->stack) > 1) {
549
+ lookahead = ts_tree_make_copy(&self->tree_pool, lookahead);
447
550
  } else {
448
551
  ts_tree_retain(lookahead);
449
552
  }
@@ -452,83 +555,77 @@ static void parser__shift(Parser *self, StackVersion version, TSStateId state,
452
555
  ts_tree_retain(lookahead);
453
556
  }
454
557
 
455
- bool is_pending = lookahead->child_count > 0;
558
+ bool is_pending = lookahead->children.size > 0;
456
559
  ts_stack_push(self->stack, version, lookahead, is_pending, state);
457
- if (lookahead->has_external_token_state) {
458
- ts_stack_set_external_token_state(
459
- self->stack, version, ts_tree_last_external_token_state(lookahead));
560
+ if (lookahead->has_external_tokens) {
561
+ ts_stack_set_last_external_token(
562
+ self->stack, version, ts_tree_last_external_token(lookahead)
563
+ );
460
564
  }
461
- ts_tree_release(lookahead);
462
565
  }
463
566
 
464
- static bool parser__switch_children(Parser *self, Tree *tree,
465
- Tree **children, uint32_t count) {
466
- self->scratch_tree.symbol = tree->symbol;
467
- self->scratch_tree.child_count = 0;
468
- ts_tree_set_children(&self->scratch_tree, count, children);
567
+ static bool parser__replace_children(Parser *self, Tree *tree, TreeArray *children) {
568
+ self->scratch_tree = *tree;
569
+ self->scratch_tree.children.size = 0;
570
+ ts_tree_set_children(&self->scratch_tree, children, self->language);
469
571
  if (parser__select_tree(self, tree, &self->scratch_tree)) {
470
- tree->size = self->scratch_tree.size;
471
- tree->padding = self->scratch_tree.padding;
472
- tree->error_cost = self->scratch_tree.error_cost;
473
- tree->children = self->scratch_tree.children;
474
- tree->child_count = self->scratch_tree.child_count;
475
- tree->named_child_count = self->scratch_tree.named_child_count;
476
- tree->visible_child_count = self->scratch_tree.visible_child_count;
572
+ *tree = self->scratch_tree;
477
573
  return true;
478
574
  } else {
479
575
  return false;
480
576
  }
481
577
  }
482
578
 
483
- static StackPopResult parser__reduce(Parser *self, StackVersion version,
484
- TSSymbol symbol, unsigned count,
485
- bool fragile, bool allow_skipping) {
579
+ static StackSliceArray parser__reduce(Parser *self, StackVersion version, TSSymbol symbol,
580
+ uint32_t count, int dynamic_precedence,
581
+ uint16_t alias_sequence_id, bool fragile) {
486
582
  uint32_t initial_version_count = ts_stack_version_count(self->stack);
487
583
 
488
- StackPopResult pop = ts_stack_pop_count(self->stack, version, count);
489
- if (pop.stopped_at_error)
490
- return pop;
491
-
492
- const TSLanguage *language = self->language;
493
- TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol);
584
+ StackSliceArray pop = ts_stack_pop_count(self->stack, version, count);
494
585
 
495
- for (uint32_t i = 0; i < pop.slices.size; i++) {
496
- StackSlice slice = pop.slices.contents[i];
586
+ for (uint32_t i = 0; i < pop.size; i++) {
587
+ StackSlice slice = pop.contents[i];
497
588
 
498
589
  // Extra tokens on top of the stack should not be included in this new parent
499
590
  // node. They will be re-pushed onto the stack after the parent node is
500
591
  // created and pushed.
501
- uint32_t child_count = slice.trees.size;
502
- while (child_count > 0 && slice.trees.contents[child_count - 1]->extra)
503
- child_count--;
592
+ TreeArray children = slice.trees;
593
+ while (children.size > 0 && children.contents[children.size - 1]->extra) {
594
+ children.size--;
595
+ }
504
596
 
505
- Tree *parent = ts_tree_make_node(symbol, child_count, slice.trees.contents, metadata);
597
+ Tree *parent = ts_tree_make_node(&self->tree_pool,
598
+ symbol, &children, alias_sequence_id, self->language
599
+ );
506
600
 
507
601
  // This pop operation may have caused multiple stack versions to collapse
508
602
  // into one, because they all diverged from a common state. In that case,
509
603
  // choose one of the arrays of trees to be the parent node's children, and
510
604
  // delete the rest of the tree arrays.
511
- while (i + 1 < pop.slices.size) {
512
- StackSlice next_slice = pop.slices.contents[i + 1];
513
- if (next_slice.version != slice.version)
514
- break;
605
+ while (i + 1 < pop.size) {
606
+ StackSlice next_slice = pop.contents[i + 1];
607
+ if (next_slice.version != slice.version) break;
515
608
  i++;
516
609
 
517
- uint32_t child_count = next_slice.trees.size;
518
- while (child_count > 0 && next_slice.trees.contents[child_count - 1]->extra)
519
- child_count--;
610
+ TreeArray children = next_slice.trees;
611
+ while (children.size > 0 && children.contents[children.size - 1]->extra) {
612
+ children.size--;
613
+ }
520
614
 
521
- if (parser__switch_children(self, parent, next_slice.trees.contents, child_count)) {
522
- ts_tree_array_delete(&slice.trees);
615
+ if (parser__replace_children(self, parent, &children)) {
616
+ ts_tree_array_delete(&self->tree_pool, &slice.trees);
523
617
  slice = next_slice;
524
618
  } else {
525
- ts_tree_array_delete(&next_slice.trees);
619
+ ts_tree_array_delete(&self->tree_pool, &next_slice.trees);
526
620
  }
527
621
  }
528
622
 
529
- TSStateId state = ts_stack_top_state(self->stack, slice.version);
530
- TSStateId next_state = ts_language_next_state(language, state, symbol);
531
- if (fragile || self->is_split || pop.slices.size > 1 || initial_version_count > 1) {
623
+ parent->dynamic_precedence += dynamic_precedence;
624
+ parent->alias_sequence_id = alias_sequence_id;
625
+
626
+ TSStateId state = ts_stack_state(self->stack, slice.version);
627
+ TSStateId next_state = ts_language_next_state(self->language, state, symbol);
628
+ if (fragile || self->in_ambiguity || pop.size > 1 || initial_version_count > 1) {
532
629
  parent->fragile_left = true;
533
630
  parent->fragile_right = true;
534
631
  parent->parse_state = TS_TREE_STATE_NONE;
@@ -536,29 +633,25 @@ static StackPopResult parser__reduce(Parser *self, StackVersion version,
536
633
  parent->parse_state = state;
537
634
  }
538
635
 
539
- // If this pop operation terminated at the end of an error region, then
540
- // create two stack versions: one in which the parent node is interpreted
541
- // normally, and one in which the parent node is skipped.
542
- if (state == ERROR_STATE && allow_skipping && child_count > 1) {
543
- StackVersion other_version = ts_stack_copy_version(self->stack, slice.version);
544
-
545
- ts_stack_push(self->stack, other_version, parent, false, ERROR_STATE);
546
- for (uint32_t j = parent->child_count; j < slice.trees.size; j++) {
547
- Tree *tree = slice.trees.contents[j];
548
- ts_stack_push(self->stack, other_version, tree, false, ERROR_STATE);
549
- }
550
-
551
- ErrorStatus error_status = ts_stack_error_status(self->stack, other_version);
552
- if (parser__better_version_exists(self, version, error_status))
553
- ts_stack_remove_version(self->stack, other_version);
554
- }
555
-
556
636
  // Push the parent node onto the stack, along with any extra tokens that
557
637
  // were previously on top of the stack.
558
- parser__push(self, slice.version, parent, next_state);
559
- for (uint32_t j = parent->child_count; j < slice.trees.size; j++) {
560
- Tree *tree = slice.trees.contents[j];
561
- parser__push(self, slice.version, tree, next_state);
638
+ ts_stack_push(self->stack, slice.version, parent, false, next_state);
639
+ for (uint32_t j = parent->children.size; j < slice.trees.size; j++) {
640
+ ts_stack_push(self->stack, slice.version, slice.trees.contents[j], false, next_state);
641
+ }
642
+
643
+ if (ts_stack_version_count(self->stack) > MAX_VERSION_COUNT) {
644
+ i++;
645
+ while (i < pop.size) {
646
+ StackSlice slice = pop.contents[i];
647
+ ts_tree_array_delete(&self->tree_pool, &slice.trees);
648
+ ts_stack_halt(self->stack, slice.version);
649
+ i++;
650
+ }
651
+ while (ts_stack_version_count(self->stack) > slice.version + 1) {
652
+ ts_stack_remove_version(self->stack, slice.version + 1);
653
+ }
654
+ break;
562
655
  }
563
656
  }
564
657
 
@@ -574,205 +667,6 @@ static StackPopResult parser__reduce(Parser *self, StackVersion version,
574
667
  return pop;
575
668
  }
576
669
 
577
- static inline const TSParseAction *parser__reductions_after_sequence(
578
- Parser *self, TSStateId start_state, const TreeArray *trees_below,
579
- uint32_t tree_count_below, const TreeArray *trees_above,
580
- TSSymbol lookahead_symbol, uint32_t *count) {
581
- TSStateId state = start_state;
582
- uint32_t child_count = 0;
583
- *count = 0;
584
-
585
- for (uint32_t i = 0; i < trees_below->size; i++) {
586
- if (child_count == tree_count_below)
587
- break;
588
- Tree *tree = trees_below->contents[trees_below->size - 1 - i];
589
- if (tree->extra) continue;
590
- TSStateId next_state = ts_language_next_state(self->language, state, tree->symbol);
591
- if (next_state == ERROR_STATE)
592
- return NULL;
593
- if (next_state != state) {
594
- child_count++;
595
- state = next_state;
596
- }
597
- }
598
-
599
- for (uint32_t i = 0; i < trees_above->size; i++) {
600
- Tree *tree = trees_above->contents[i];
601
- if (tree->extra) continue;
602
- TSStateId next_state = ts_language_next_state(self->language, state, tree->symbol);
603
- if (next_state == ERROR_STATE)
604
- return NULL;
605
- if (next_state != state) {
606
- child_count++;
607
- state = next_state;
608
- }
609
- }
610
-
611
- const TSParseAction *actions =
612
- ts_language_actions(self->language, state, lookahead_symbol, count);
613
-
614
- if (*count > 0 && actions[*count - 1].type != TSParseActionTypeReduce) {
615
- (*count)--;
616
- }
617
-
618
- while (*count > 0 && actions[0].params.child_count < child_count) {
619
- actions++;
620
- (*count)--;
621
- }
622
-
623
- while (*count > 0 && actions[*count - 1].params.child_count > child_count) {
624
- (*count)--;
625
- }
626
-
627
- return actions;
628
- }
629
-
630
- static StackIterateAction parser__repair_error_callback(
631
- void *payload, TSStateId state, TreeArray *trees, uint32_t tree_count,
632
- bool is_done, bool is_pending) {
633
-
634
- ErrorRepairSession *session = (ErrorRepairSession *)payload;
635
- Parser *self = session->parser;
636
- TSSymbol lookahead_symbol = session->lookahead_symbol;
637
- ReduceActionSet *repairs = &self->reduce_actions;
638
- TreeArray *trees_above_error = session->trees_above_error;
639
- uint32_t tree_count_above_error = session->tree_count_above_error;
640
-
641
- StackIterateAction result = StackIterateNone;
642
-
643
- uint32_t last_repair_count = -1;
644
- uint32_t repair_reduction_count = -1;
645
- const TSParseAction *repair_reductions = NULL;
646
-
647
- for (uint32_t i = 0; i < repairs->size; i++) {
648
- ReduceAction *repair = &repairs->contents[i];
649
- uint32_t count_needed_below_error = repair->count - tree_count_above_error;
650
- if (count_needed_below_error > tree_count)
651
- break;
652
-
653
- uint32_t skip_count = tree_count - count_needed_below_error;
654
- if (session->found_repair && skip_count >= session->best_repair_skip_count) {
655
- array_erase(repairs, i--);
656
- continue;
657
- }
658
-
659
- TSStateId state_after_repair = ts_language_next_state(self->language, state, repair->symbol);
660
- if (state == ERROR_STATE || state_after_repair == ERROR_STATE)
661
- continue;
662
-
663
- uint32_t action_count;
664
- ts_language_actions(self->language, state_after_repair, lookahead_symbol, &action_count);
665
- if (action_count == 0)
666
- continue;
667
-
668
- if (count_needed_below_error != last_repair_count) {
669
- last_repair_count = count_needed_below_error;
670
- repair_reductions = parser__reductions_after_sequence(
671
- self, state, trees, count_needed_below_error, trees_above_error,
672
- lookahead_symbol, &repair_reduction_count);
673
- }
674
-
675
- for (uint32_t j = 0; j < repair_reduction_count; j++) {
676
- if (repair_reductions[j].params.symbol == repair->symbol) {
677
- result |= StackIteratePop;
678
- session->found_repair = true;
679
- session->best_repair = *repair;
680
- session->best_repair_skip_count = skip_count;
681
- session->best_repair_next_state = state_after_repair;
682
- array_erase(repairs, i--);
683
- break;
684
- }
685
- }
686
- }
687
-
688
- if (repairs->size == 0)
689
- result |= StackIterateStop;
690
-
691
- return result;
692
- }
693
-
694
- static bool parser__repair_error(Parser *self, StackSlice slice,
695
- TSSymbol lookahead_symbol, TableEntry entry) {
696
- LOG("repair_error");
697
- ErrorRepairSession session = {
698
- .parser = self,
699
- .lookahead_symbol = lookahead_symbol,
700
- .found_repair = false,
701
- .trees_above_error = &slice.trees,
702
- .tree_count_above_error = ts_tree_array_essential_count(&slice.trees),
703
- };
704
-
705
- array_clear(&self->reduce_actions);
706
- for (uint32_t i = 0; i < entry.action_count; i++) {
707
- if (entry.actions[i].type == TSParseActionTypeReduce) {
708
- TSSymbol symbol = entry.actions[i].params.symbol;
709
- uint32_t child_count = entry.actions[i].params.child_count;
710
- if ((child_count > session.tree_count_above_error) ||
711
- (child_count == session.tree_count_above_error &&
712
- !ts_language_symbol_metadata(self->language, symbol).visible))
713
- array_push(&self->reduce_actions, ((ReduceAction){
714
- .symbol = symbol,
715
- .count = child_count
716
- }));
717
- }
718
- }
719
-
720
- StackPopResult pop = ts_stack_iterate(
721
- self->stack, slice.version, parser__repair_error_callback, &session);
722
-
723
- if (!session.found_repair) {
724
- LOG("no_repair_found");
725
- ts_stack_remove_version(self->stack, slice.version);
726
- ts_tree_array_delete(&slice.trees);
727
- return false;
728
- }
729
-
730
- ReduceAction repair = session.best_repair;
731
- TSStateId next_state = session.best_repair_next_state;
732
- uint32_t skip_count = session.best_repair_skip_count;
733
- TSSymbol symbol = repair.symbol;
734
-
735
- StackSlice new_slice = array_pop(&pop.slices);
736
- TreeArray children = new_slice.trees;
737
- ts_stack_renumber_version(self->stack, new_slice.version, slice.version);
738
-
739
- for (uint32_t i = pop.slices.size - 1; i + 1 > 0; i--) {
740
- StackSlice other_slice = pop.slices.contents[i];
741
- ts_tree_array_delete(&other_slice.trees);
742
- if (other_slice.version != pop.slices.contents[i + 1].version)
743
- ts_stack_remove_version(self->stack, other_slice.version);
744
- }
745
-
746
- TreeArray skipped_children = ts_tree_array_remove_last_n(&children, skip_count);
747
- TreeArray trailing_extras = ts_tree_array_remove_trailing_extras(&skipped_children);
748
- Tree *error = ts_tree_make_error_node(&skipped_children);
749
- array_push(&children, error);
750
- array_push_all(&children, &trailing_extras);
751
- trailing_extras.size = 0;
752
- array_delete(&trailing_extras);
753
-
754
- for (uint32_t i = 0; i < slice.trees.size; i++)
755
- array_push(&children, slice.trees.contents[i]);
756
- array_delete(&slice.trees);
757
-
758
- Tree *parent =
759
- ts_tree_make_node(symbol, children.size, children.contents,
760
- ts_language_symbol_metadata(self->language, symbol));
761
- parser__push(self, slice.version, parent, next_state);
762
- ts_stack_decrease_push_count(self->stack, slice.version, error->child_count);
763
-
764
- ErrorStatus error_status = ts_stack_error_status(self->stack, slice.version);
765
- if (parser__better_version_exists(self, slice.version, error_status)) {
766
- LOG("no_better_repair_found");
767
- ts_stack_halt(self->stack, slice.version);
768
- return false;
769
- } else {
770
- LOG("repair_found sym:%s, child_count:%u, cost:%u", SYM_NAME(symbol),
771
- repair.count, parent->error_cost);
772
- return true;
773
- }
774
- }
775
-
776
670
  static void parser__start(Parser *self, TSInput input, Tree *previous_tree) {
777
671
  if (previous_tree) {
778
672
  LOG("parse_after_edit");
@@ -780,257 +674,413 @@ static void parser__start(Parser *self, TSInput input, Tree *previous_tree) {
780
674
  LOG("new_parse");
781
675
  }
782
676
 
783
- if (self->language->external_scanner.reset) {
784
- self->language->external_scanner.reset(self->external_scanner_payload);
677
+ if (self->language->external_scanner.deserialize) {
678
+ self->language->external_scanner.deserialize(self->external_scanner_payload, NULL, 0);
785
679
  }
786
680
 
787
681
  ts_lexer_set_input(&self->lexer, input);
788
682
  ts_stack_clear(self->stack);
789
683
  self->reusable_node = reusable_node_new(previous_tree);
790
- self->cached_token = NULL;
791
684
  self->finished_tree = NULL;
685
+ self->accept_count = 0;
686
+ self->in_ambiguity = false;
792
687
  }
793
688
 
794
- static void parser__accept(Parser *self, StackVersion version,
795
- Tree *lookahead) {
689
+ static void parser__accept(Parser *self, StackVersion version, Tree *lookahead) {
796
690
  lookahead->extra = true;
797
691
  assert(lookahead->symbol == ts_builtin_sym_end);
692
+ ts_tree_retain(lookahead);
798
693
  ts_stack_push(self->stack, version, lookahead, false, 1);
799
- StackPopResult pop = ts_stack_pop_all(self->stack, version);
800
694
 
801
- for (uint32_t i = 0; i < pop.slices.size; i++) {
802
- StackSlice slice = pop.slices.contents[i];
803
- TreeArray trees = slice.trees;
695
+ StackSliceArray pop = ts_stack_pop_all(self->stack, version);
696
+ for (uint32_t i = 0; i < pop.size; i++) {
697
+ TreeArray trees = pop.contents[i].trees;
804
698
 
805
699
  Tree *root = NULL;
806
- if (trees.size == 1) {
807
- root = trees.contents[0];
808
- array_delete(&trees);
809
- } else {
810
- for (uint32_t j = trees.size - 1; j + 1 > 0; j--) {
811
- Tree *child = trees.contents[j];
812
- if (!child->extra) {
813
- root = ts_tree_make_copy(child);
814
- root->child_count = 0;
815
- for (uint32_t k = 0; k < child->child_count; k++)
816
- ts_tree_retain(child->children[k]);
817
- array_splice(&trees, j, 1, child->child_count, child->children);
818
- ts_tree_set_children(root, trees.size, trees.contents);
819
- ts_tree_release(child);
820
- break;
700
+ for (uint32_t j = trees.size - 1; j + 1 > 0; j--) {
701
+ Tree *child = trees.contents[j];
702
+ if (!child->extra) {
703
+ for (uint32_t k = 0; k < child->children.size; k++) {
704
+ ts_tree_retain(child->children.contents[k]);
821
705
  }
706
+ array_splice(&trees, j, 1, &child->children);
707
+ root = ts_tree_make_node(
708
+ &self->tree_pool, child->symbol, &trees,
709
+ child->alias_sequence_id, self->language
710
+ );
711
+ ts_tree_release(&self->tree_pool, child);
712
+ break;
822
713
  }
823
714
  }
824
715
 
825
- if (parser__select_tree(self, self->finished_tree, root)) {
826
- ts_tree_release(self->finished_tree);
827
- assert(root->ref_count > 0);
828
- self->finished_tree = root;
716
+ assert(root && root->ref_count > 0);
717
+ self->accept_count++;
718
+
719
+ if (self->finished_tree) {
720
+ if (parser__select_tree(self, self->finished_tree, root)) {
721
+ ts_tree_release(&self->tree_pool, self->finished_tree);
722
+ self->finished_tree = root;
723
+ } else {
724
+ ts_tree_release(&self->tree_pool, root);
725
+ }
829
726
  } else {
830
- ts_tree_release(root);
727
+ self->finished_tree = root;
831
728
  }
832
729
  }
833
730
 
834
- ts_stack_remove_version(self->stack, pop.slices.contents[0].version);
731
+ ts_stack_remove_version(self->stack, pop.contents[0].version);
835
732
  ts_stack_halt(self->stack, version);
836
733
  }
837
734
 
838
- static bool parser__do_potential_reductions(Parser *self, StackVersion version) {
839
- bool has_shift_action = false;
840
- TSStateId state = ts_stack_top_state(self->stack, version);
841
- uint32_t previous_version_count = ts_stack_version_count(self->stack);
735
+ static bool parser__do_all_potential_reductions(Parser *self, StackVersion starting_version,
736
+ TSSymbol lookahead_symbol) {
737
+ uint32_t initial_version_count = ts_stack_version_count(self->stack);
842
738
 
843
- array_clear(&self->reduce_actions);
844
- for (TSSymbol symbol = 0; symbol < self->language->token_count; symbol++) {
845
- TableEntry entry;
846
- ts_language_table_entry(self->language, state, symbol, &entry);
847
- for (uint32_t i = 0; i < entry.action_count; i++) {
848
- TSParseAction action = entry.actions[i];
849
- if (action.extra)
850
- continue;
851
- switch (action.type) {
852
- case TSParseActionTypeShift:
853
- case TSParseActionTypeRecover:
854
- has_shift_action = true;
855
- break;
856
- case TSParseActionTypeReduce:
857
- if (action.params.child_count > 0)
858
- ts_reduce_action_set_add(&self->reduce_actions, (ReduceAction){
859
- .symbol = action.params.symbol,
860
- .count = action.params.child_count,
861
- });
862
- default:
863
- break;
739
+ bool can_shift_lookahead_symbol = false;
740
+ StackVersion version = starting_version;
741
+ for (unsigned i = 0; true; i++) {
742
+ uint32_t version_count = ts_stack_version_count(self->stack);
743
+ if (version >= version_count) break;
744
+
745
+ bool merged = false;
746
+ for (StackVersion i = initial_version_count; i < version; i++) {
747
+ if (ts_stack_merge(self->stack, i, version)) {
748
+ merged = true;
749
+ break;
864
750
  }
865
751
  }
866
- }
752
+ if (merged) continue;
867
753
 
868
- bool did_reduce = false;
869
- for (uint32_t i = 0; i < self->reduce_actions.size; i++) {
870
- ReduceAction action = self->reduce_actions.contents[i];
871
- StackPopResult reduction =
872
- parser__reduce(self, version, action.symbol, action.count, true, false);
873
- if (reduction.stopped_at_error) {
874
- ts_tree_array_delete(&reduction.slices.contents[0].trees);
875
- ts_stack_remove_version(self->stack, reduction.slices.contents[0].version);
876
- continue;
754
+ TSStateId state = ts_stack_state(self->stack, version);
755
+ bool has_shift_action = false;
756
+ array_clear(&self->reduce_actions);
757
+
758
+ TSSymbol first_symbol, end_symbol;
759
+ if (lookahead_symbol != 0) {
760
+ first_symbol = lookahead_symbol;
761
+ end_symbol = lookahead_symbol + 1;
877
762
  } else {
878
- did_reduce = true;
763
+ first_symbol = 1;
764
+ end_symbol = self->language->token_count;
765
+ }
766
+
767
+ for (TSSymbol symbol = first_symbol; symbol < end_symbol; symbol++) {
768
+ TableEntry entry;
769
+ ts_language_table_entry(self->language, state, symbol, &entry);
770
+ for (uint32_t i = 0; i < entry.action_count; i++) {
771
+ TSParseAction action = entry.actions[i];
772
+ switch (action.type) {
773
+ case TSParseActionTypeShift:
774
+ case TSParseActionTypeRecover:
775
+ if (!action.params.extra && !action.params.repetition) has_shift_action = true;
776
+ break;
777
+ case TSParseActionTypeReduce:
778
+ if (action.params.child_count > 0)
779
+ ts_reduce_action_set_add(&self->reduce_actions, (ReduceAction){
780
+ .symbol = action.params.symbol,
781
+ .count = action.params.child_count,
782
+ .dynamic_precedence = action.params.dynamic_precedence,
783
+ .alias_sequence_id = action.params.alias_sequence_id,
784
+ });
785
+ default:
786
+ break;
787
+ }
788
+ }
789
+ }
790
+
791
+ for (uint32_t i = 0; i < self->reduce_actions.size; i++) {
792
+ ReduceAction action = self->reduce_actions.contents[i];
793
+
794
+ parser__reduce(
795
+ self, version, action.symbol, action.count,
796
+ action.dynamic_precedence, action.alias_sequence_id,
797
+ true
798
+ );
879
799
  }
880
- }
881
800
 
882
- if (did_reduce) {
883
801
  if (has_shift_action) {
884
- return true;
802
+ can_shift_lookahead_symbol = true;
803
+ } else if (self->reduce_actions.size > 0 && i < MAX_VERSION_COUNT) {
804
+ ts_stack_renumber_version(self->stack, version_count, version);
805
+ continue;
806
+ } else if (lookahead_symbol != 0) {
807
+ ts_stack_remove_version(self->stack, version);
808
+ }
809
+
810
+ if (version == starting_version) {
811
+ version = version_count;
885
812
  } else {
886
- ts_stack_renumber_version(self->stack, previous_version_count, version);
887
- return false;
813
+ version++;
888
814
  }
889
- } else {
890
- return true;
891
815
  }
816
+
817
+ return can_shift_lookahead_symbol;
892
818
  }
893
819
 
894
- static StackIterateAction parser__skip_preceding_trees_callback(
895
- void *payload, TSStateId state, TreeArray *trees, uint32_t tree_count,
896
- bool is_done, bool is_pending) {
897
- if (tree_count > 0 && state != ERROR_STATE) {
898
- SkipPrecedingTreesSession *session = payload;
899
- Parser *self = session->parser;
900
- TSSymbol lookahead_symbol = session->lookahead_symbol;
901
- uint32_t action_count;
902
- const TSParseAction *actions =
903
- ts_language_actions(self->language, state, lookahead_symbol, &action_count);
904
- if (action_count > 0 && actions[0].type == TSParseActionTypeReduce) {
905
- return StackIteratePop | StackIterateStop;
820
+ static void parser__handle_error(Parser *self, StackVersion version, TSSymbol lookahead_symbol) {
821
+ // Perform any reductions that could have happened in this state, regardless of the lookahead.
822
+ uint32_t previous_version_count = ts_stack_version_count(self->stack);
823
+ parser__do_all_potential_reductions(self, version, 0);
824
+ uint32_t version_count = ts_stack_version_count(self->stack);
825
+
826
+ // Push a discontinuity onto the stack. Merge all of the stack versions that
827
+ // were created in the previous step.
828
+ bool did_insert_missing_token = false;
829
+ for (StackVersion v = version; v < version_count;) {
830
+ if (!did_insert_missing_token) {
831
+ TSStateId state = ts_stack_state(self->stack, v);
832
+ for (TSSymbol missing_symbol = 1;
833
+ missing_symbol < self->language->token_count;
834
+ missing_symbol++) {
835
+ TSStateId state_after_missing_symbol = ts_language_next_state(
836
+ self->language, state, missing_symbol
837
+ );
838
+ if (state_after_missing_symbol == 0) continue;
839
+
840
+ if (ts_language_has_reduce_action(
841
+ self->language,
842
+ state_after_missing_symbol,
843
+ lookahead_symbol
844
+ )) {
845
+ StackVersion version_with_missing_tree = ts_stack_copy_version(self->stack, v);
846
+ Tree *missing_tree = ts_tree_make_missing_leaf(&self->tree_pool, missing_symbol, self->language);
847
+ ts_stack_push(
848
+ self->stack, version_with_missing_tree,
849
+ missing_tree, false,
850
+ state_after_missing_symbol
851
+ );
852
+
853
+ if (parser__do_all_potential_reductions(
854
+ self, version_with_missing_tree,
855
+ lookahead_symbol
856
+ )) {
857
+ LOG(
858
+ "recover_with_missing symbol:%s, state:%u",
859
+ SYM_NAME(missing_symbol),
860
+ ts_stack_state(self->stack, version_with_missing_tree)
861
+ );
862
+ did_insert_missing_token = true;
863
+ break;
864
+ }
865
+ }
866
+ }
906
867
  }
868
+
869
+ ts_stack_push(self->stack, v, NULL, false, ERROR_STATE);
870
+ v = (v == version) ? previous_version_count : v + 1;
871
+ }
872
+
873
+ for (unsigned i = previous_version_count; i < version_count; i++) {
874
+ assert(ts_stack_merge(self->stack, version, previous_version_count));
907
875
  }
908
- return StackIterateNone;
876
+
877
+ ts_stack_record_summary(self->stack, version, MAX_SUMMARY_DEPTH);
878
+ LOG_STACK();
909
879
  }
910
880
 
911
- static bool parser__skip_preceding_trees(Parser *self, StackVersion version,
912
- TSSymbol lookahead_symbol) {
913
- SkipPrecedingTreesSession session = { self, lookahead_symbol };
914
- StackPopResult pop = ts_stack_iterate(
915
- self->stack, version, parser__skip_preceding_trees_callback, &session);
881
+ static void parser__halt_parse(Parser *self) {
882
+ LOG("halting_parse");
883
+ LOG_STACK();
884
+
885
+ ts_lexer_advance_to_end(&self->lexer);
886
+ Length remaining_length = length_sub(
887
+ self->lexer.current_position,
888
+ ts_stack_position(self->stack, 0)
889
+ );
890
+
891
+ Tree *filler_node = ts_tree_make_error(&self->tree_pool, remaining_length, length_zero(), 0, self->language);
892
+ filler_node->visible = false;
893
+ ts_stack_push(self->stack, 0, filler_node, false, 0);
894
+
895
+ TreeArray children = array_new();
896
+ Tree *root_error = ts_tree_make_error_node(&self->tree_pool, &children, self->language);
897
+ ts_stack_push(self->stack, 0, root_error, false, 0);
916
898
 
899
+ Tree *eof = ts_tree_make_leaf(&self->tree_pool, ts_builtin_sym_end, length_zero(), length_zero(), self->language);
900
+ parser__accept(self, 0, eof);
901
+ ts_tree_release(&self->tree_pool, eof);
902
+ }
903
+
904
+ static bool parser__recover_to_state(Parser *self, StackVersion version, unsigned depth,
905
+ TSStateId goal_state) {
906
+ StackSliceArray pop = ts_stack_pop_count(self->stack, version, depth);
917
907
  StackVersion previous_version = STACK_VERSION_NONE;
918
- for (uint32_t i = 0; i < pop.slices.size; i++) {
919
- StackSlice slice = pop.slices.contents[i];
908
+
909
+ for (unsigned i = 0; i < pop.size; i++) {
910
+ StackSlice slice = pop.contents[i];
911
+
920
912
  if (slice.version == previous_version) {
921
- ts_tree_array_delete(&slice.trees);
913
+ ts_tree_array_delete(&self->tree_pool, &slice.trees);
914
+ array_erase(&pop, i--);
915
+ continue;
916
+ }
917
+
918
+ if (ts_stack_state(self->stack, slice.version) != goal_state) {
919
+ ts_stack_halt(self->stack, slice.version);
920
+ ts_tree_array_delete(&self->tree_pool, &slice.trees);
921
+ array_erase(&pop, i--);
922
922
  continue;
923
923
  }
924
924
 
925
+ TreeArray error_trees = ts_stack_pop_error(self->stack, slice.version);
926
+ if (error_trees.size > 0) {
927
+ assert(error_trees.size == 1);
928
+ array_splice(&slice.trees, 0, 0, &error_trees.contents[0]->children);
929
+ for (unsigned j = 0; j < error_trees.contents[0]->children.size; j++) {
930
+ ts_tree_retain(slice.trees.contents[j]);
931
+ }
932
+ ts_tree_array_delete(&self->tree_pool, &error_trees);
933
+ }
934
+
935
+ TreeArray trailing_extras = ts_tree_array_remove_trailing_extras(&slice.trees);
936
+
937
+ if (slice.trees.size > 0) {
938
+ Tree *error = ts_tree_make_error_node(&self->tree_pool, &slice.trees, self->language);
939
+ error->extra = true;
940
+ ts_stack_push(self->stack, slice.version, error, false, goal_state);
941
+ } else {
942
+ array_delete(&slice.trees);
943
+ }
944
+
945
+ for (unsigned j = 0; j < trailing_extras.size; j++) {
946
+ Tree *tree = trailing_extras.contents[j];
947
+ ts_stack_push(self->stack, slice.version, tree, false, goal_state);
948
+ }
949
+
925
950
  previous_version = slice.version;
926
- Tree *error = ts_tree_make_error_node(&slice.trees);
927
- error->extra = true;
928
- TSStateId state = ts_stack_top_state(self->stack, slice.version);
929
- parser__push(self, slice.version, error, state);
951
+ array_delete(&trailing_extras);
930
952
  }
931
953
 
932
- return pop.slices.size > 0;
954
+ return previous_version != STACK_VERSION_NONE;
933
955
  }
934
956
 
935
- static void parser__handle_error(Parser *self, StackVersion version,
936
- TSSymbol lookahead_symbol) {
937
- // If there are other stack versions that are clearly better than this one,
938
- // just halt this version.
939
- ErrorStatus error_status = ts_stack_error_status(self->stack, version);
940
- error_status.count++;
941
- if (parser__better_version_exists(self, version, error_status)) {
942
- ts_stack_halt(self->stack, version);
943
- LOG("bail_on_error");
944
- return;
945
- }
957
+ static void parser__recover(Parser *self, StackVersion version, Tree *lookahead) {
958
+ bool did_recover = false;
959
+ unsigned previous_version_count = ts_stack_version_count(self->stack);
960
+ Length position = ts_stack_position(self->stack, version);
961
+ StackSummary *summary = ts_stack_get_summary(self->stack, version);
962
+ unsigned node_count_since_error = ts_stack_node_count_since_error(self->stack, version);
963
+ unsigned current_error_cost = ts_stack_error_cost(self->stack, version);
964
+
965
+ if (summary && lookahead->symbol != ts_builtin_sym_error) {
966
+ for (unsigned i = 0; i < summary->size; i++) {
967
+ StackSummaryEntry entry = summary->contents[i];
968
+
969
+ if (entry.state == ERROR_STATE) continue;
970
+ if (entry.position.bytes == position.bytes) continue;
971
+ unsigned depth = entry.depth;
972
+ if (node_count_since_error > 0) depth++;
973
+
974
+ bool would_merge = false;
975
+ for (unsigned j = 0; j < previous_version_count; j++) {
976
+ if (
977
+ ts_stack_state(self->stack, j) == entry.state &&
978
+ ts_stack_position(self->stack, j).bytes == position.bytes
979
+ ) {
980
+ would_merge = true;
981
+ break;
982
+ }
983
+ }
946
984
 
947
- LOG("handle_error");
985
+ if (would_merge) continue;
948
986
 
949
- // If the current lookahead symbol would have been valid in some previous
950
- // state on the stack, create one stack version that repairs the error
951
- // immediately by simply skipping all of the trees that came after that state.
952
- if (parser__skip_preceding_trees(self, version, lookahead_symbol)) {
953
- LOG("skip_preceding_trees");
954
- LOG_STACK();
955
- }
987
+ unsigned new_cost =
988
+ current_error_cost +
989
+ entry.depth * ERROR_COST_PER_SKIPPED_TREE +
990
+ (position.bytes - entry.position.bytes) * ERROR_COST_PER_SKIPPED_CHAR +
991
+ (position.extent.row - entry.position.extent.row) * ERROR_COST_PER_SKIPPED_LINE;
992
+ if (parser__better_version_exists(self, version, false, new_cost)) break;
956
993
 
957
- // Perform any reductions that could have happened in this state, regardless
958
- // of the lookahead.
959
- uint32_t previous_version_count = ts_stack_version_count(self->stack);
960
- for (StackVersion v = version; v < ts_stack_version_count(self->stack);) {
961
- if (parser__do_potential_reductions(self, v)) {
962
- if (v == version) {
963
- v = previous_version_count;
964
- } else {
965
- v++;
994
+ if (ts_language_has_actions(self->language, entry.state, lookahead->symbol)) {
995
+ if (parser__recover_to_state(self, version, depth, entry.state)) {
996
+ did_recover = true;
997
+ LOG("recover_to_previous state:%u, depth:%u", entry.state, depth);
998
+ LOG_STACK();
999
+ break;
1000
+ }
966
1001
  }
967
1002
  }
968
1003
  }
969
1004
 
970
- // Push a discontinuity onto the stack. Merge all of the stack versions that
971
- // were created in the previous step.
972
- ts_stack_push(self->stack, version, NULL, false, ERROR_STATE);
973
- while (ts_stack_version_count(self->stack) > previous_version_count) {
974
- ts_stack_push(self->stack, previous_version_count, NULL, false, ERROR_STATE);
975
- assert(ts_stack_merge(self->stack, version, previous_version_count));
1005
+ for (unsigned i = previous_version_count; i < ts_stack_version_count(self->stack); i++) {
1006
+ if (!ts_stack_is_active(self->stack, i)) {
1007
+ ts_stack_remove_version(self->stack, i--);
1008
+ }
1009
+ }
1010
+
1011
+ if (did_recover && ts_stack_version_count(self->stack) > MAX_VERSION_COUNT) {
1012
+ ts_stack_halt(self->stack, version);
1013
+ return;
976
1014
  }
977
- }
978
1015
 
979
- static void parser__recover(Parser *self, StackVersion version, TSStateId state,
980
- Tree *lookahead) {
981
1016
  if (lookahead->symbol == ts_builtin_sym_end) {
982
1017
  LOG("recover_eof");
983
1018
  TreeArray children = array_new();
984
- Tree *parent = ts_tree_make_error_node(&children);
985
- parser__push(self, version, parent, 1);
1019
+ Tree *parent = ts_tree_make_error_node(&self->tree_pool, &children, self->language);
1020
+ ts_stack_push(self->stack, version, parent, false, 1);
986
1021
  parser__accept(self, version, lookahead);
1022
+ return;
987
1023
  }
988
1024
 
989
- LOG("recover state:%u", state);
1025
+ unsigned new_cost =
1026
+ current_error_cost + ERROR_COST_PER_SKIPPED_TREE +
1027
+ ts_tree_total_bytes(lookahead) * ERROR_COST_PER_SKIPPED_CHAR +
1028
+ ts_tree_total_size(lookahead).extent.row * ERROR_COST_PER_SKIPPED_LINE;
990
1029
 
991
- StackVersion new_version = ts_stack_copy_version(self->stack, version);
992
-
993
- parser__shift(
994
- self, new_version, ERROR_STATE, lookahead,
995
- ts_language_symbol_metadata(self->language, lookahead->symbol).extra);
996
- ErrorStatus error_status = ts_stack_error_status(self->stack, new_version);
997
- if (parser__better_version_exists(self, version, error_status)) {
998
- ts_stack_remove_version(self->stack, new_version);
999
- LOG("bail_on_recovery");
1030
+ if (parser__better_version_exists(self, version, false, new_cost)) {
1031
+ ts_stack_halt(self->stack, version);
1032
+ return;
1000
1033
  }
1001
1034
 
1002
- parser__shift(self, version, state, lookahead, false);
1003
- }
1004
-
1005
- static void parser__advance(Parser *self, StackVersion version,
1006
- ReusableNode *reusable_node) {
1007
- bool validated_lookahead = false;
1008
- Tree *lookahead = parser__get_lookahead(self, version, reusable_node, &validated_lookahead);
1035
+ unsigned n;
1036
+ const TSParseAction *actions = ts_language_actions(self->language, 1, lookahead->symbol, &n);
1037
+ if (n > 0 && actions[n - 1].type == TSParseActionTypeShift && actions[n - 1].params.extra) {
1038
+ lookahead->extra = true;
1039
+ }
1009
1040
 
1010
- for (;;) {
1011
- TSStateId state = ts_stack_top_state(self->stack, version);
1041
+ LOG("skip_token symbol:%s", SYM_NAME(lookahead->symbol));
1042
+ ts_tree_retain(lookahead);
1043
+ TreeArray children = array_new();
1044
+ array_reserve(&children, 1);
1045
+ array_push(&children, lookahead);
1046
+ Tree *error_repeat = ts_tree_make_node(
1047
+ &self->tree_pool,
1048
+ ts_builtin_sym_error_repeat,
1049
+ &children,
1050
+ 0,
1051
+ self->language
1052
+ );
1012
1053
 
1013
- TableEntry table_entry;
1014
- ts_language_table_entry(self->language, state, lookahead->first_leaf.symbol, &table_entry);
1054
+ if (node_count_since_error > 0) {
1055
+ StackSliceArray pop = ts_stack_pop_count(self->stack, version, 1);
1056
+ assert(pop.size == 1);
1057
+ assert(pop.contents[0].trees.size == 1);
1058
+ ts_stack_renumber_version(self->stack, pop.contents[0].version, version);
1059
+ array_push(&pop.contents[0].trees, error_repeat);
1060
+ error_repeat = ts_tree_make_node(
1061
+ &self->tree_pool,
1062
+ ts_builtin_sym_error_repeat,
1063
+ &pop.contents[0].trees,
1064
+ 0,
1065
+ self->language
1066
+ );
1067
+ }
1015
1068
 
1016
- if (!validated_lookahead) {
1017
- if (!parser__can_reuse(self, state, lookahead, &table_entry)) {
1018
- if (lookahead == reusable_node->tree) {
1019
- reusable_node_pop_leaf(reusable_node);
1020
- } else {
1021
- parser__clear_cached_token(self);
1022
- }
1069
+ ts_stack_push(self->stack, version, error_repeat, false, ERROR_STATE);
1023
1070
 
1024
- ts_tree_release(lookahead);
1025
- lookahead = parser__get_lookahead(self, version, reusable_node, &validated_lookahead);
1026
- continue;
1027
- }
1071
+ if (lookahead->has_external_tokens) {
1072
+ ts_stack_set_last_external_token(
1073
+ self->stack, version, ts_tree_last_external_token(lookahead)
1074
+ );
1075
+ }
1076
+ }
1028
1077
 
1029
- validated_lookahead = true;
1030
- LOG("reused_lookahead sym:%s, size:%u", SYM_NAME(lookahead->symbol), lookahead->size.bytes);
1031
- }
1078
+ static void parser__advance(Parser *self, StackVersion version, ReusableNode *reusable_node) {
1079
+ TSStateId state = ts_stack_state(self->stack, version);
1080
+ TableEntry table_entry;
1081
+ Tree *lookahead = parser__get_lookahead(self, version, &state, reusable_node, &table_entry);
1032
1082
 
1033
- bool reduction_stopped_at_error = false;
1083
+ for (;;) {
1034
1084
  StackVersion last_reduction_version = STACK_VERSION_NONE;
1035
1085
 
1036
1086
  for (uint32_t i = 0; i < table_entry.action_count; i++) {
@@ -1038,84 +1088,58 @@ static void parser__advance(Parser *self, StackVersion version,
1038
1088
 
1039
1089
  switch (action.type) {
1040
1090
  case TSParseActionTypeShift: {
1041
- bool extra = action.extra;
1091
+ if (action.params.repetition) break;
1042
1092
  TSStateId next_state;
1093
+ if (action.params.extra) {
1094
+
1095
+ // TODO remove when TREE_SITTER_LANGUAGE_VERSION 9 is out.
1096
+ if (state == ERROR_STATE) continue;
1043
1097
 
1044
- if (action.extra) {
1045
1098
  next_state = state;
1046
1099
  LOG("shift_extra");
1047
1100
  } else {
1048
- next_state = action.params.to_state;
1101
+ next_state = action.params.state;
1049
1102
  LOG("shift state:%u", next_state);
1050
1103
  }
1051
1104
 
1052
- if (lookahead->child_count > 0) {
1053
- if (parser__breakdown_lookahead(self, &lookahead, state, reusable_node)) {
1054
- if (!parser__can_reuse(self, state, lookahead, &table_entry)) {
1055
- reusable_node_pop(reusable_node);
1056
- ts_tree_release(lookahead);
1057
- lookahead = parser__get_lookahead(self, version, reusable_node, &validated_lookahead);
1058
- }
1059
- }
1060
-
1105
+ if (lookahead->children.size > 0) {
1106
+ parser__breakdown_lookahead(self, &lookahead, state, reusable_node);
1061
1107
  next_state = ts_language_next_state(self->language, state, lookahead->symbol);
1062
1108
  }
1063
1109
 
1064
- parser__shift(self, version, next_state, lookahead, extra);
1065
-
1066
- if (lookahead == reusable_node->tree)
1067
- reusable_node_pop(reusable_node);
1068
-
1069
- ts_tree_release(lookahead);
1110
+ parser__shift(self, version, next_state, lookahead, action.params.extra);
1111
+ if (lookahead == reusable_node->tree) reusable_node_pop(reusable_node);
1112
+ ts_tree_release(&self->tree_pool, lookahead);
1070
1113
  return;
1071
1114
  }
1072
1115
 
1073
1116
  case TSParseActionTypeReduce: {
1074
- if (reduction_stopped_at_error)
1075
- continue;
1076
-
1077
- unsigned child_count = action.params.child_count;
1078
- TSSymbol symbol = action.params.symbol;
1079
- bool fragile = action.fragile;
1080
-
1081
- LOG("reduce sym:%s, child_count:%u", SYM_NAME(symbol), child_count);
1082
-
1083
- StackPopResult reduction =
1084
- parser__reduce(self, version, symbol, child_count, fragile, true);
1085
- StackSlice slice = *array_front(&reduction.slices);
1086
- if (reduction.stopped_at_error) {
1087
- reduction_stopped_at_error = true;
1088
- if (!parser__repair_error(self, slice, lookahead->first_leaf.symbol,
1089
- table_entry))
1090
- break;
1091
- }
1092
-
1117
+ bool is_fragile = table_entry.action_count > 1;
1118
+ LOG("reduce sym:%s, child_count:%u", SYM_NAME(action.params.symbol), action.params.child_count);
1119
+ StackSliceArray reduction = parser__reduce(
1120
+ self, version, action.params.symbol, action.params.child_count,
1121
+ action.params.dynamic_precedence, action.params.alias_sequence_id,
1122
+ is_fragile
1123
+ );
1124
+ StackSlice slice = *array_front(&reduction);
1093
1125
  last_reduction_version = slice.version;
1094
1126
  break;
1095
1127
  }
1096
1128
 
1097
1129
  case TSParseActionTypeAccept: {
1098
- if (ts_stack_error_status(self->stack, version).count > 0)
1099
- continue;
1100
-
1101
1130
  LOG("accept");
1102
1131
  parser__accept(self, version, lookahead);
1103
- ts_tree_release(lookahead);
1132
+ ts_tree_release(&self->tree_pool, lookahead);
1104
1133
  return;
1105
1134
  }
1106
1135
 
1107
1136
  case TSParseActionTypeRecover: {
1108
- while (lookahead->child_count > 0) {
1109
- reusable_node_breakdown(reusable_node);
1110
- ts_tree_release(lookahead);
1111
- lookahead = reusable_node->tree;
1112
- ts_tree_retain(lookahead);
1137
+ while (lookahead->children.size > 0) {
1138
+ parser__breakdown_lookahead(self, &lookahead, state, reusable_node);
1113
1139
  }
1114
-
1115
- parser__recover(self, version, action.params.to_state, lookahead);
1116
- if (lookahead == reusable_node->tree)
1117
- reusable_node_pop(reusable_node);
1118
- ts_tree_release(lookahead);
1140
+ parser__recover(self, version, lookahead);
1141
+ if (lookahead == reusable_node->tree) reusable_node_pop(reusable_node);
1142
+ ts_tree_release(&self->tree_pool, lookahead);
1119
1143
  return;
1120
1144
  }
1121
1145
  }
@@ -1124,35 +1148,116 @@ static void parser__advance(Parser *self, StackVersion version,
1124
1148
  if (last_reduction_version != STACK_VERSION_NONE) {
1125
1149
  ts_stack_renumber_version(self->stack, last_reduction_version, version);
1126
1150
  LOG_STACK();
1127
- continue;
1151
+ } else if (state == ERROR_STATE) {
1152
+ parser__recover(self, version, lookahead);
1153
+ ts_tree_release(&self->tree_pool, lookahead);
1154
+ return;
1155
+ } else if (!parser__breakdown_top_of_stack(self, version)) {
1156
+ LOG("detect_error");
1157
+ ts_stack_pause(self->stack, version, lookahead->first_leaf.symbol);
1158
+ ts_tree_release(&self->tree_pool, lookahead);
1159
+ return;
1128
1160
  }
1129
1161
 
1130
- if (parser__breakdown_top_of_stack(self, version)) {
1162
+ state = ts_stack_state(self->stack, version);
1163
+ ts_language_table_entry(self->language, state, lookahead->first_leaf.symbol, &table_entry);
1164
+ }
1165
+ }
1166
+
1167
+ static unsigned parser__condense_stack(Parser *self) {
1168
+ bool made_changes = false;
1169
+ unsigned min_error_cost = UINT_MAX;
1170
+ for (StackVersion i = 0; i < ts_stack_version_count(self->stack); i++) {
1171
+ if (ts_stack_is_halted(self->stack, i)) {
1172
+ ts_stack_remove_version(self->stack, i);
1173
+ i--;
1131
1174
  continue;
1132
1175
  }
1133
1176
 
1134
- if (state == ERROR_STATE) {
1135
- parser__push(self, version, lookahead, ERROR_STATE);
1136
- return;
1177
+ ErrorStatus status_i = parser__version_status(self, i);
1178
+ if (!status_i.is_in_error && status_i.cost < min_error_cost) {
1179
+ min_error_cost = status_i.cost;
1137
1180
  }
1138
1181
 
1139
- parser__handle_error(self, version, lookahead->first_leaf.symbol);
1182
+ for (StackVersion j = 0; j < i; j++) {
1183
+ ErrorStatus status_j = parser__version_status(self, j);
1140
1184
 
1141
- if (ts_stack_is_halted(self->stack, version)) {
1142
- ts_tree_release(lookahead);
1143
- return;
1185
+ switch (parser__compare_versions(self, status_j, status_i)) {
1186
+ case ErrorComparisonTakeLeft:
1187
+ made_changes = true;
1188
+ ts_stack_remove_version(self->stack, i);
1189
+ i--;
1190
+ j = i;
1191
+ break;
1192
+ case ErrorComparisonPreferLeft:
1193
+ case ErrorComparisonNone:
1194
+ if (ts_stack_merge(self->stack, j, i)) {
1195
+ made_changes = true;
1196
+ i--;
1197
+ j = i;
1198
+ }
1199
+ break;
1200
+ case ErrorComparisonPreferRight:
1201
+ made_changes = true;
1202
+ if (ts_stack_merge(self->stack, j, i)) {
1203
+ i--;
1204
+ j = i;
1205
+ } else {
1206
+ ts_stack_swap_versions(self->stack, i, j);
1207
+ }
1208
+ break;
1209
+ case ErrorComparisonTakeRight:
1210
+ made_changes = true;
1211
+ ts_stack_remove_version(self->stack, j);
1212
+ i--;
1213
+ j--;
1214
+ break;
1215
+ }
1216
+ }
1217
+ }
1218
+
1219
+ while (ts_stack_version_count(self->stack) > MAX_VERSION_COUNT) {
1220
+ ts_stack_remove_version(self->stack, MAX_VERSION_COUNT);
1221
+ made_changes = true;
1222
+ }
1223
+
1224
+ if (ts_stack_version_count(self->stack) > 0) {
1225
+ bool has_unpaused_version = false;
1226
+ for (StackVersion i = 0, n = ts_stack_version_count(self->stack); i < n; i++) {
1227
+ if (ts_stack_is_paused(self->stack, i)) {
1228
+ if (!has_unpaused_version && self->accept_count < MAX_VERSION_COUNT) {
1229
+ LOG("resume version:%u", i);
1230
+ min_error_cost = ts_stack_error_cost(self->stack, i);
1231
+ TSSymbol lookahead_symbol = ts_stack_resume(self->stack, i);
1232
+ parser__handle_error(self, i, lookahead_symbol);
1233
+ has_unpaused_version = true;
1234
+ } else {
1235
+ ts_stack_remove_version(self->stack, i);
1236
+ i--;
1237
+ n--;
1238
+ }
1239
+ } else {
1240
+ has_unpaused_version = true;
1241
+ }
1144
1242
  }
1145
1243
  }
1244
+
1245
+ if (made_changes) {
1246
+ LOG("condense");
1247
+ LOG_STACK();
1248
+ }
1249
+
1250
+ return min_error_cost;
1146
1251
  }
1147
1252
 
1148
1253
  bool parser_init(Parser *self) {
1149
1254
  ts_lexer_init(&self->lexer);
1150
1255
  array_init(&self->reduce_actions);
1151
- array_init(&self->tree_path1);
1152
- array_init(&self->tree_path2);
1153
- array_grow(&self->reduce_actions, 4);
1154
- self->stack = ts_stack_new();
1256
+ array_reserve(&self->reduce_actions, 4);
1257
+ ts_tree_pool_init(&self->tree_pool);
1258
+ self->stack = ts_stack_new(&self->tree_pool);
1155
1259
  self->finished_tree = NULL;
1260
+ parser__set_cached_token(self, 0, NULL, NULL);
1156
1261
  return true;
1157
1262
  }
1158
1263
 
@@ -1173,14 +1278,11 @@ void parser_destroy(Parser *self) {
1173
1278
  ts_stack_delete(self->stack);
1174
1279
  if (self->reduce_actions.contents)
1175
1280
  array_delete(&self->reduce_actions);
1176
- if (self->tree_path1.contents)
1177
- array_delete(&self->tree_path1);
1178
- if (self->tree_path2.contents)
1179
- array_delete(&self->tree_path2);
1281
+ ts_tree_pool_delete(&self->tree_pool);
1180
1282
  parser_set_language(self, NULL);
1181
1283
  }
1182
1284
 
1183
- Tree *parser_parse(Parser *self, TSInput input, Tree *old_tree) {
1285
+ Tree *parser_parse(Parser *self, TSInput input, Tree *old_tree, bool halt_on_error) {
1184
1286
  parser__start(self, input, old_tree);
1185
1287
 
1186
1288
  StackVersion version = STACK_VERSION_NONE;
@@ -1190,38 +1292,43 @@ Tree *parser_parse(Parser *self, TSInput input, Tree *old_tree) {
1190
1292
  do {
1191
1293
  for (version = 0; version < ts_stack_version_count(self->stack); version++) {
1192
1294
  reusable_node = self->reusable_node;
1193
- last_position = position;
1194
-
1195
- while (!ts_stack_is_halted(self->stack, version)) {
1196
- position = ts_stack_top_position(self->stack, version).chars;
1197
- if (position > last_position || (version > 0 && position == last_position))
1198
- break;
1199
1295
 
1296
+ while (ts_stack_is_active(self->stack, version)) {
1200
1297
  LOG("process version:%d, version_count:%u, state:%d, row:%u, col:%u",
1201
1298
  version, ts_stack_version_count(self->stack),
1202
- ts_stack_top_state(self->stack, version),
1203
- ts_stack_top_position(self->stack, version).extent.row,
1204
- ts_stack_top_position(self->stack, version).extent.column);
1299
+ ts_stack_state(self->stack, version),
1300
+ ts_stack_position(self->stack, version).extent.row,
1301
+ ts_stack_position(self->stack, version).extent.column);
1205
1302
 
1206
1303
  parser__advance(self, version, &reusable_node);
1207
1304
  LOG_STACK();
1305
+
1306
+ position = ts_stack_position(self->stack, version).bytes;
1307
+ if (position > last_position || (version > 0 && position == last_position)) {
1308
+ last_position = position;
1309
+ break;
1310
+ }
1208
1311
  }
1209
1312
  }
1210
1313
 
1211
1314
  self->reusable_node = reusable_node;
1212
1315
 
1213
- if (parser__condense_stack(self)) {
1214
- LOG("condense");
1215
- LOG_STACK();
1316
+ unsigned min_error_cost = parser__condense_stack(self);
1317
+ if (self->finished_tree && self->finished_tree->error_cost < min_error_cost) {
1318
+ break;
1319
+ } else if (halt_on_error && min_error_cost > 0) {
1320
+ parser__halt_parse(self);
1321
+ break;
1216
1322
  }
1217
1323
 
1218
- self->is_split = (version > 1);
1324
+ self->in_ambiguity = version > 1;
1219
1325
  } while (version != 0);
1220
1326
 
1327
+ ts_stack_clear(self->stack);
1328
+ parser__set_cached_token(self, 0, NULL, NULL);
1329
+ ts_tree_assign_parents(self->finished_tree, &self->tree_pool, self->language);
1330
+
1221
1331
  LOG("done");
1222
1332
  LOG_TREE();
1223
- ts_stack_clear(self->stack);
1224
- parser__clear_cached_token(self);
1225
- ts_tree_assign_parents(self->finished_tree, &self->tree_path1);
1226
1333
  return self->finished_tree;
1227
1334
  }