3 ms·
This is pretty specific, but Ruby has pretty terrible support for parsing Ruby. Libraries are either unmaintained or broken or for old versions. Python is great
by boardwaalk 11y ago
This is pretty specific, but Ruby has pretty terrible support for parsing Ruby. Libraries are either unmaintained or broken or for old versions. Python is great for parsing ('import ast'), compiling ('compile(...)') and executing ('exec(...)'). So it's much easier to write code generators, write linters and autocompletion tools and such.
- cremno 11y ago>but Ruby has pretty terrible support for parsing Ruby https://github.com/whitequark/parser https://github.com/whitequark/parser Neither unmaintained, broken nor just for old versions. It has some really minor incompatibilities though: https://github.com/whitequark/parser#known-issues https://github.com/whitequark/parser#known-issues The same person also wrote a Python parser because apparently the ast module doesn't provide precise location information of tokens: https://github.com/m-labs/pythonparser https://github.com/m-labs/pythonparser
- graffitici 11y agoI had looked into the 'ast' module a little while back, and I do agree that it's pretty neat. The main use I've seen it type checking, or adding language level features (that would typically be done by macros in LISP). I am not aware of many tools written using 'ast', that don't try to extend the language in some way. Any thoughts there?
- cheald 11y agoIt's fine in MRI. > seq = RubyVM::InstructionSequence.compile("a = 1 + 2") => <RubyVM::InstructionSequence:<compiled>@<compiled>> > puts seq.disasm == disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 2] a 0000 trace 1 ( 1) 0002 putobject_OP_INT2FIX_O_1_C_ 0003 putobject 2 0005 opt_plus <callinfo!mid:+, argc:1, ARGS_SIMPLE> 0007 dup 0008 setlocal_OP__WC__0 2 0010 leave => nil > seq.eval => 3