BOO的例子 7
基于boo这个语言实现的几个dsl例子,可以作为我们学习的参考
Brail
Castle Project
http://www.castleproject.org/monorail/documentation/trunk/viewengines/brail/index.html.
It’s a text templating language, built by me, in which in you can mix code and text freely. Here’s a sample:
<h1>My name is ${name}</h1>
<ul>
<% for element in list: %>
<li>${element}</li>
<% end %>
</ul>
Rhino ETL
Rhino ETL employs the concept of steps, with data flowing from one step to the next.
Usually the first step will extract the data from some source, and the last will load it to
the final destination.
Here’s an example of a full ETL process:
operationsplit_name:
for row in rows:
continue if row.Name is null
row.FirstName, row.LastName = row.Name.Split()
yield row
processUsersToPeople:
input "source_db", Command = "SELECT id, name, email FROM Users"
split_names()
output "destination_db", Command = """
INSERT INTO People (UserId, FirstName, LastName, Email)
VALUES (@UserId, @FirstName, @LastName, @Email)
""":
row.UserId = row.Id
This code gets the users list from the source database, splits the names, and then saves
them to the destination database. This is a good example of a DSL that requires some
knowledge of the domain before you can utilize it.
http://www.ayende.com/Blog/category/545.aspx
Bake (Boo Build System)
Task "init build dir":
if not Directory.Exists("build"):
MkDir "build"
CpFileSet("lib/*.dll").Files, "build", true
http://code.google.com/p/boo-build-system/
Specter
Specter is a behavior-driven development (BDD) testing framework
context "Empty stack":
stack as Stack
setup:
stack = Stack()
specifystack.Count.Must == 0
specify "Stack must accept an item and count is then one":
stack.Push(42)
stack.Count.Must == 1