Fork me on GitHub
  1. RubyLess

    There are quite some parts in the zafu templating language where we need some kind of pseudo ruby. For example in test conditions like <r:if test='id eq main.id'/>. A couple of days ago, I needed to use a more complicated test and… bang! My toy parser could not handled the test. The options are:

    1. adapt the toy parser
    2. make something really better

    I chose the second path and started writing a simplified ruby parser with ragel. That could be fun, but it’s time consuming and I would prefer to move on faster so I looked around for such a ruby parser and found ParseTree, a tool that generates an S-expression tree from a string of ruby code. That’s nice. For example, if you send it the following string:

    !prev.ancestor?(main) && !node.ancestor?(main)
    

    you get:

    [:and, [:not, [:call, [:vcall, :prev], :ancestor?, [:array, [:vcall, :main]]]], [:not, [:call, [:vcall, :node], :ancestor?, [:array, [:vcall, :main]]]]]
    

    And then you can use SexpProcessor to transform the given junk into something useful in the context of a compiled zafu template:

    (not var1_prev.ancestor?(@node) and not var1.ancestor?(@node))
    

    type safety

    In order to have compile time type checking (that’s what we do in zafu), I had to use some clever tricks during processing in order to keep track of the types using a TypedString as expected return value from processors in place of a String .

    method call safety

    If any method is not safe enough to be called in the rubyless context, we produce a zafu compilation error. Safe methods have to be explicitly allowed with argument and return types in order to be used. All “safe” methods must return the return type they advertise or nil in which case they have to set the :nil option to true:

    class Dummy
      include RubyLess::SafeClass
      safe_method :friend => {:class => Dummy, :nil => true}
    end
    

    conclusion

    Changing from the current (bad) toy languages to rubyless means we can use the full ruby syntax and nobody needs to learn any new syntax (and we do not need to maintain yet another language). I will see if this parser could not be used with query builder to parse query parameters. This would mean that we could write:

    images where name like "#{params[:s]}%" in site

    instead of the current

    images where name like "[param:s]%" in site

    This would simplify APIs from both zafu and SQLiss, only needing to define secure methods in one place (the object’s class).

    Just like query builder is a project on its own, RubyLess will be a gem because it should be an interesting tool in many places where you need simplified scripting without the burden of writing yet another toy language.

    Gaspard Bucher

    comments

    1. Wednesday, May 27 2009 10:58 Gaspard

      Main project page created: rubyless.

    2. Tuesday, June 02 2009 14:41 Gaspard

      Gem published !

    3. Friday, June 05 2009 14:21 alpern

      I try today your CMS, good work, i use actualy SPIP, its simpler to find a hosting with php mysql than Rails. But i like zena. *First test over windows and instantrails, stoping for the moment. some probleme with the rake:migrate *Second test with VirtualBox OK.
      I think there is not enought documentation, but i will go on to try it.
      best Regard (sorry for my poor english.)

    4. Saturday, June 06 2009 17:11 Gaspard

      Hi Alpern !

      Thanks for the nice message. You are right, we still need to do quite some work with the documentation. User documentation is actually on hold until we reach 1.0 (first non-beta release, rails 2+) because there might be some important changes. We should reach 1.0 this summer (we have funding to work exclusively on this).

    5. leave a comment