I need to create a parser for Ruby so I can use the origami folding package. To make matters more complex, I use enh-ruby-mode
, so I 'd like to build the parser for that, if it makes a difference.
The package has the following instructions:
It should be fairly easy to write a parser. An origami parser is a function that takes a 'create function' and returns a function taking the string to be parsed. The returned function should return a list of fold nodes. Fold nodes are created using the passed-in create function. Best to use an example:
(defun my-amazing-parser (create)
(lambda (content)
(list (funcall create beginning-of-the-fold-node-point-position ; inclusive
end-of-the-fold-node-point-position ; exclusive
offset ; this allows you to show some of the start of the folded text
child-nodes))))
The origami package has a parsers file that has the built-in examples, and they also support regular expressions.
Unfortunately, I am a little too weak with elisp yet to understand it (and it looks like he uses some libraries with functions like ->>
and I don't know how to go and find out what they are or where they came from).
My first guess would be something like this:
(defun origami-ruby-parser (create)
(lambda (content)
(list (funcall create (enh-ruby-beginning-of-block) ; inclusive
(enh-ruby-end-of-block) ; exclusive
10 ; this allows you to show some of the start of the folded text
child-nodes))))
I don't know what child-nodes
is supposed to be.
And from there, the question will be "can I create more complex matching rules using if/else/etc ?"