jbdoderlein / BetterOCaml

A small but efficient, intuitive and responsive OCaml IDE right in your browser! Ships OCaml v5.1.1, interpreter by your browser (so it works offline!), compiled with js_of_ocaml.
https://perso.eleves.ens-rennes.fr/people/jean-baptiste.doderlein/betterocaml
Apache License 2.0
37 stars 8 forks source link

Regex not supported for macOS and iOS with Safari #37

Closed jbdoderlein closed 3 years ago

jbdoderlein commented 3 years ago

The actual version of betterocaml don't work on Safari because of the lookbehind regex used in autocompletion

Fix : Disable this feature for these browser (meh) or rewrite regex (oh no)

jbdoderlein commented 3 years ago

Corrected in #38

Naereen commented 3 years ago

I'm just curious, which path did you chose, finally, between "meh" and "oh no" :smile: ?

jbdoderlein commented 3 years ago

I chose the "oh no" solution which turned out to be "nice" solution.

I replaced this regex : /((?<=let rec )|(?<=let )|(?<=and ))(\w+\b(?<!\brec))/g that contains negative lookbehind (not supported in safari) By these two regex : match(/((let rec \w+)|(let \w+)|(and \w+))/g).map(x=>x.replace(/(let )|(rec )|(and )/g, "")

I thought that because of the map, I would increase a lot the complexity and therefore the time of calculation. In the end it's the opposite that happened, and this solution is 5x faster than the previous one

Naereen commented 3 years ago

Nice tweak!