aantron / lambdasoup

Functional HTML scraping and rewriting with CSS in OCaml
https://aantron.github.io/lambdasoup
MIT License
380 stars 31 forks source link

usage from js_of_ocaml #36

Closed joprice closed 3 years ago

joprice commented 3 years ago

I get the error below when I call Soup.fold.

bigarray.ml:0 Uncaught RangeError: Maximum call stack size exceeded
    at adding (bigarray.ml:0)
    at add (bigarray.ml:0)
    at add_character (bigarray.ml:0)
    at bigarray.ml:0
    at caml_call1 (bigarray.ml:0)
    at reopen (bigarray.ml:0)
    at reconstruct_active_formatting_ (bigarray.ml:0)
    at in_body_mode_rules$0 (bigarray.ml:0)
    at in_body_mode_rules (bigarray.ml:0)
    at bigarray.ml:0

Is the library usable from js_of_ocaml 3.7, or maybe I'm doing something wrong?

aantron commented 3 years ago

This is probably because the underlying HTML parser, Markup.ml, makes very heavy use of tail calls, and js_of_ocaml and/or JS engines don't have tail-call optimization. This is "tracked" in https://github.com/aantron/markup.ml/issues/26. The reason for the quotes is that I'm not sure what can reasonably be done about it. Perhaps it has been addressed in newer versions of js_of_ocaml?

dmbaturin commented 3 years ago

3.7.0 is the latest version, from August 05, so I assume its TCO support hasn't improved yet. It definitely should do something about it, I don't think any library ought to limits its use of TCO because one certain backend can't do it.

joprice commented 3 years ago

Thanks for the info. The same code is working great when targeting native, I was trying to see if I could reuse it in a web context. Luckily, it's not too much to rewrite using dom apis.

aantron commented 3 years ago

Closing in favor of https://github.com/aantron/markup.ml/issues/26.