

Show HN: A JavaScript interpreter written in Ruby - charliesome
http://github.com/charliesome/twostroke

======
charliesome
Twostroke is also capable enough to run the CoffeeScript compiler:
<http://github.com/charliesome/coffee-script-pure>

~~~
sstephenson
Very cool! If you added a Twostroke adapter to ExecJS
(<https://github.com/sstephenson/execjs>), the ruby-coffee-script gem would
work without modification.

~~~
jewel
I'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.)

------
Xion
I'm quite flabbergasted seeing this:

[https://github.com/charliesome/twostroke/blob/master/lib/two...](https://github.com/charliesome/twostroke/blob/master/lib/twostroke/parser.rb)

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?

~~~
vidarh
Forced? I've written dozens of parsers, and personally I avoid parsing
libraries like the plague - unless you're writing a really simple parser with
few needs for error reporting and recovery, my experience is that parsing
libraries usually end up being far more pain than they are worth.

~~~
daeken
Completely agreed. Once I got the hang of hand-writing parsers, I never looked
back; they're higher-quality, generally faster, easier to write, and are
easier to maintain than generated parsers.

~~~
wglb
My favorite compiler writer (dgc of mwc fame) says "Yacc makes the hard part
of a compiler harder and the easy part easier".

------
endymi0n
You should check out HotRuby, which is a Ruby interpreter, written in
Javascript: <http://hotruby.yukoba.jp/>

Should be pretty interesting to see Twostroke running on HotRuby running on
Twostroke running on HotRuby running...

~~~
sreque
The 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?

------
vidarh
Looks fun, but it'd be interesting to hear more about your rationale for this
vs. embedding V8 etc.

~~~
charliesome
Something 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.

~~~
vidarh
Fun is always a good reason... I need to dust off my (horribly incomplete)
Ruby compiler project.

------
kyle_martin1
This look pretty neat. Could you share your motivation behind why you build
this and some use cases? :)

------
jiaaro
Very cool! I was looking for a python js interpreter just the other day, maybe
I'll take a crack at it :)

------
jemeshsu
I see no use case for this. You must be masters of both languages after this
project.

------
georgemcbay
I'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.

~~~
almost
It's just people enjoying themselves, it's fun to work on crazy projects (at
least for some people). Don't worry about it :)

