bcoe / onigurumajs

:japanese_goblin: a pure JavaScript port of the oniguruma regex engine
ISC License
38 stars 3 forks source link

FYI: PR submitted to first-mate to use onigurumajs in the browser #2

Open patrick-steele-idem opened 8 years ago

patrick-steele-idem commented 8 years ago

Hey @bcoe, just wanted to let you know that I was able to use this module with first-mate. I sent a PR to first-mate to use onigurumajs in the browser (instead of oniguruma): https://github.com/atom/first-mate/pull/69

Hopefully they will accept the PR. Also, using the patched first-mate module I was able to successfully create an adapter that allows any Atom grammar file to be used for syntax highlighting in a CodeMirror editor: https://github.com/patrick-steele-idem/codemirror-atom-modes

You can see codemirror-atom-modes in action on the markojs.com website: http://markojs.com/try-online/

Thanks for working on this project! It definitely saved me some time.

bcoe commented 8 years ago

@patrick-steele-idem sorry about the slow reply, buried under the weight of 1,000,000 open-source projects :smile:

This is extremely cool! For one, I haven't used browserify much, and it's really cool to see the overriding approach you're using in action -- I didn't know this was possible.

I've added you as a collaborator on this module, I would happily accept any patches you provide going forward. A few things on my mind:

codemirror-atom-modes is using onigurumajs? such a cool project.

zeke commented 8 years ago

Nice work, @patrick-steele-idem! I'm a heavy user of oniguruma and would love to see this javascript port get more ❤️

patrick-steele-idem commented 8 years ago

Hey @bcoe,

Thanks for adding me as a collaborator!

For testing purposes I had swapped out oniguruma for onigurumajs in first-mate and ran the server-side test suite. There were a ton of failures and I was initially discouraged. However, it seems to be working really well with the three grammar files that I have tested (marko, javascript and css) and that was good enough for me :) But yeah, I also noticed that there is not feature parity. When/if I have time I would definitely like to take a closer look at the failures (I'm also bogged down by lots of open source projects thought :/ )

I recently came across oniguruma-js by @tenbits and he is using his own Atma-Regex library instead of XRegExp. I haven't tried out @tenbits's library but might be interesting to compare and see if it makes sense to join forces.

@tenbits, what are your thoughts on the feature parity of your library with oniguruma? I would also love to hear what was your motivation for creating your JavaScript implementation of oniguruma and any thoughts you might have.

I'm not going to lie, it was really awesome to see syntax highlighting work for a Atom grammar within a CodeMirror editor :) I was very much relieved to not have to write and maintain yet another syntax highlighter plugin. I hope more people will find codemirror-atom-modes helpful.

Thanks all!

tenbits commented 8 years ago

As you may have seen, oniguruma-js is only a tiny wrapper over Atma-Regex to be api-compatible to node-oniguruma. I don't suppose the api and the wrapper itself will change a lot, so here the question is more about the regex engine. Though XRegExp is good, but it is not enough to be Ruby compatible, so it can't replace node-oniguruma internals. For example: There are no begin index for captured groups. And to use indexOf on match to find out the position of the captured group is far away from being reliable on complex regex patterns. There are no anchors and no possessive quantifiers, atomic groups are not handled, and so on.

Initially I was trying to make the TextMate grammar definitions to work in browser, but when I realized Oniguruma Regex syntax can't be easily ported to browser, I started to implement such an engine for browsers, but with the time the library got too huge and complex for production usage. So I decided to wait a bit, until the sticky feature are natively supported by all major browsers, to simplify the engine and to make it more performant.