robertkrimen / otto

A JavaScript interpreter in Go (golang)
http://godoc.org/github.com/robertkrimen/otto
MIT License
8.04k stars 584 forks source link

Switching to another Regex library #215

Open liclac opened 8 years ago

liclac commented 8 years ago

Otto currently uses the builtin regexp package for regular expressions, which lacks support for backreferences. The reasoning behind this is rather well explained (the godoc page for the regexp module links to this elaborate blog post) - in short, implementing lookbacks is impossible while still guaranteeing O(n) execution time.

Unfortunately, as long as Otto uses it, it cannot conform to the ECMA 5 specification, and a large amount of existing JS code out there will simply fail to compile on Otto - notably, both BabelJS and Traceur, the two major ways available to provide ES6 features to ES5-compatible environments, are currently incompatible with Otto.

I propose the move to a different regular expression library - this one, for example, looks rather promising, and doesn't add a cgo dependency.

paulocoutinhox commented 8 years ago

+1

deoxxa commented 8 years ago

This sounds good, but we'd need to make sure there were no performance regressions. Basically the same problem as #205 right now. I'd happily merge a patch if it made otto better support JS's RegExp object without serious performance degradation.

dszczyt commented 6 years ago

what about a build tag to allow to choose regexp compatibility over performance ?

stevenh commented 1 year ago

Would consider that, if someone wants to put in a PR 👍

stevenh commented 1 year ago

Would love some feedback on this PR which implements pluggable RegExp.