Parsing ruby-code with the ruby-interpreter itself

C

cies

at the moment most code editors are using sets of regexps, and other
difficult stuff to do highlighting and syntax error checking...

i was (naturally) thinking: why?

ruby already contains a nice parser for parsing ruby!
would it be possible to build hooks into the ruby-interpreter for code-editors?

i was thinking a small interface exposed by a (both c and ruby)
library, that allows other programs (mainly code editors for as far as
i can imagine) to make use of the relatively fast, and standard
compliant ruby parser that is already in ruby...

searching the net i found nothing that does this. yet i might have
searched in the wrong direction.

well, i'm not a good C coder, i tried to look at ruby's internals to
figure to find out if i could make a patch... but no; i can't, i got
too dizzy ;)

am i suggesting a small layer over the parse.{c,y} and lex.c, or am
suggesting a much bigger project?


thanks for reading all the way up to the end,
cies breijs.
 
D

Dominik Bathon

at the moment most code editors are using sets of regexps, and other
difficult stuff to do highlighting and syntax error checking...

i was (naturally) thinking: why?

ruby already contains a nice parser for parsing ruby!
would it be possible to build hooks into the ruby-interpreter for
code-editors?

i was thinking a small interface exposed by a (both c and ruby)
library, that allows other programs (mainly code editors for as far as
i can imagine) to make use of the relatively fast, and standard
compliant ruby parser that is already in ruby...

searching the net i found nothing that does this. yet i might have
searched in the wrong direction.

There are multiple libraries that do things like that:

First there is Ripper. It works by putting its own hooks into parse.y and
then providing a SAX-like interface. I am not sure about its status and
how complete it is.

Then there are RubyNode and ParseTree, which wrap Ruby's internal NODEs.
They can both take a string, parse it using Ruby's parser (without
executing it) and then return the resulting NODE tree. The downside of
this approach is that comments are ignored, because they are not
represented in the NODE tree, otherwise it works quite good.

Dominik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Embedding ruby interpreter 2
Embedding Ruby Interpreter + RUBYGEMS 3
Ruby Code Parsing 9
Trouble with code 2
Parsing the Ruby File 14
parsing js with ruby 0
xml parsing in ruby 9
xml parsing in ruby 0

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top