6 ms·
Show HN: A JavaScript interpreter written in Ruby
- haileys 15y agoTwostroke is also capable enough to run the CoffeeScript compiler: http://github.com/charliesome/coffee-script-pure http://github.com/charliesome/coffee-script-pure
- sstephenson 15y agoVery cool! If you added a Twostroke adapter to ExecJS (https://github.com/sstephenson/execjs https://github.com/sstephenson/execjs), the ruby-coffee-script gem would work without modification.
- jewel 15y agoI've been thinking of making a pure-ruby javascript interpreter in order to embed it into ExecJS as a fallback for when nothing else is present. I believe this is only the case on Linux, but I've found that it gives my coworkers who are trying out rails for the first time quite a bit of confusion. (For that matter, it would help if execjs appended #readme in its error message instead of just to the github page, since the same coworkers were also unfamiliar with github, and didn't realize they had to look below the fold for the list of runtimes.)
- vidarh 15y agoLooks fun, but it'd be interesting to hear more about your rationale for this vs. embedding V8 etc.
- charliesome 15y agoSomething like Twostroke could be useful if for some reason or other you can't embed V8 (eg. no platform support, no access to compilers, etc.) Twostroke is dog slow compared to a 'real' JavaScript engine, but it will do the job if there's no other options. It's also a fun project that has taught me a lot about parsers, language implementations and JavaScript's object model.
- lloeki 15y agoLoving the pun on the name, as "Twostroke is dog slow compared to [V8]"
- vidarh 15y agoFun is always a good reason... I need to dust off my (horribly incomplete) Ruby compiler project.
- vidarh 15y agoOf course the all-important question is, can it run Hot Ruby (http://hotruby.yukoba.jp/ http://hotruby.yukoba.jp/)?
- Xion 15y agoI'm quite flabbergasted seeing this: https://github.com/charliesome/twostroke/blob/master/lib/twostroke/parser.rb https://github.com/charliesome/twostroke/blob/master/lib/two... That is, a parser which is essentially coded by hand, with all token checking, saving and restoring parser's state, functions corresponding to non-terminating symbols of grammar etc. Are there no good parsing libraries in Ruby (similar to Python's pyparsing or Haskell's Parsec), and could this have forced the author to code his parser from scratch?
- charliesome 15y agoThere's treetop, kpeg and a bunch of other stuff but I prefer writing my parsers by hand. Pretty much all that's missing from mine is semicolon insertion, but that's something I'm working to nut out.
- andrewvc 15y agoSure there are, kpeg, citrus, treetop... Probably more I don't know about.
- jhchabran 15y agoGiven that Ragel (http://www.complang.org/ragel/ http://www.complang.org/ragel/) can output Ruby code, it might be a great choice there.
- charliesome 15y agoRagel just deals with FSMs, it can't generate a parser for a non-regular language.
- jhchabran 15y agoYou're right, thanks for the correction, I did not realize FSMs couldn't do that.
- groovy2shoes 15y agoWriting a parser by hand makes for a good exercise. No need to be flabbergasted!
- kyle_martin1 15y agoThis look pretty neat. Could you share your motivation behind why you build this and some use cases? :)
- jiaaro 15y agoVery cool! I was looking for a python js interpreter just the other day, maybe I'll take a crack at it :)
- georgemcbay 15y agoI'm starting to wonder if the people behind these sorts of projects (eg. old console emulators written in JavaScript, this, etc.) are insane or if this is all some sort of epic trolling for lulz.
- endymi0n 15y agoYou should check out HotRuby, which is a Ruby interpreter, written in Javascript: http://hotruby.yukoba.jp/ http://hotruby.yukoba.jp/ Should be pretty interesting to see Twostroke running on HotRuby running on Twostroke running on HotRuby running...
- sreque 15y agoThe front page for the project hasn't been updated in over 3 years, and a quick search for github activity shows stagnation too. What direction is this project heading and how fast is it getting there?
- jemeshsu 15y agoI see no use case for this. You must be masters of both languages after this project.