jbr / treesl

DSL definition tool

Home Page:http://github.com/jbr/treesl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TreeSL

TreeSL is my effort to define a flexible domain specific language (DSL). I think it’s similar to a recursive descent parser.

TreeSL will try a number of alternative matches for a given node until it finds a matching alternative. This is incredibly inefficient, but the goal is flexibility, not on-the-fly DSL speed.

Installation

#install gemcutter if you haven't
  gem install gemcutter
  gem tumble
  
  #install treesl
  gem install treesl

Example


  require 'treesl'

  parser = TreeSL.define do
    root 'person'

    person 'title firstname lastname'
    person 'title lastname'
    person 'firstname lastname'

    title /^Mr|Mrs|Ms$/
    firstname 'propernoun'
    lastname 'propernoun'
    propernoun /^[A-Z][a-z]+/
  end

  p parser.match("Sam Jones")    #=> {"firstname lastname"=>{"lastname"=>"Jones", "firstname"=>"Sam"}}
  p parser.match("Mr Sam Jones") #=> {"title firstname lastname"=>{"title"=>"Mr", "lastname"=>"Jones", "firstname"=>"Sam"}}
  p parser.match("Mr Jones")     #=> {"title lastname"=>{"title"=>"Mr", "lastname"=>"Jones"}}

Copyright

Copyright © 2009 Jacob Rothstein. See LICENSE for details.

About

DSL definition tool

http://github.com/jbr/treesl

License:MIT License


Languages

Language:Ruby 100.0%