tree-sitter / tree-sitter-ruby

Ruby grammar for tree-sitter
MIT License
176 stars 58 forks source link

Parsing fails with wasm version #231

Closed gushogg-blake closed 4 months ago

gushogg-blake commented 1 year ago

I'm seeing this error when trying to parse using a wasm build:

tree-sitter.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'apply')
    at e.<computed> (tree-sitter.js:1)
    at <anonymous>:wasm-function[23]:0x3245
    at tree-sitter.wasm:0x24f30
    at Object.Module._ts_parser_parse_wasm (tree-sitter.js:1)
    at Parser.parse (tree-sitter.js:1)
    at (index):15

I've set up a basic repo to reproduce: https://github.com/gushogg-blake/ruby-wasm-test, deployed at https://ruby-wasm-test.vercel.app/.

I built the wasm file using the latest tree-sitter-cli with npx tree-sitter-cli build-wasm tree-sitter-ruby. tree-sitter.js and tree-sitter.wasm are from the latest version of tree-sitter. I've also tried it with an earlier version and got the same error. Any idea what could be causing this?

gushogg-blake commented 1 year ago

I seem to remember something about header files with emscripten - like you were restricted in what standard header files you could use or something. Could this be related? (Also to #116). Comparing to e.g. JavaScript which does work for me:

scanner.cc:

#include <tree_sitter/parser.h>

#include <cstring>
#include <cwctype>
#include <string>
#include <vector>

vs JavaScript (https://github.com/tree-sitter/tree-sitter-javascript/blob/e3a5149f8bc3a3bf2fe931f05851428a1197e0e6/src/scanner.c):

#include <tree_sitter/parser.h>
#include <wctype.h>