--[[ Configure Semantic Model Using API Directly (Rules00) Lair Configuration DSL Case Study H. Conrad Cunningham, Professor Computer and Information Science University of Mississippi This Lua test code is based on the Ruby code "rules0" associated with the book chapter: Martin Fowler, "One Lair and Twenty Ruby DSLs," Chapter 3, The ThoughtWorks Anthology: Essays on Software Technology and Innovation, The Pragmatic Bookshelf, 2008. This code directly uses the API provided by the Semantic Model module. Developed for CSci 658, Software Language Engineering, Fall 2013 1234567890123456789012345678901234567890123456789012345678901234567890 2013-10-14: Adapted from Fowler's file lairs/rules0.rb Note: There are two test functions below that only differ in that the second uses "symbols" instead of strings. It was the first test program for symbols. There is no separate test00.lua file associated with this example. --]] -- Load semantic model module local sm = require "model" -- Local definitions for convenience local Configuration, Item, S = sm.Configuration, sm.Item, sm.S local Resource, Electricity, Acid = sm.Resource, sm.Electricity, sm.Acid -- rules00 based on Fowler's rules0.rb local function rules00() local config = Configuration:make() config:add_item(Item:make("secure_air_vent")) config:add_item(Item:make("acid_bath")) config:get_item("acid_bath"):add_usage(Electricity:make(12)) local acid = Acid:make() config:get_item("acid_bath"):add_usage(acid) acid:set_type("hcl") acid:set_grade(5) config:add_item(Item:make("camera")) config:get_item("camera"):add_usage(Electricity:make(1)) config:add_item(Item:make("small_power_plant")) config:get_item("small_power_plant") :add_provision(Electricity:make(11)) config:get_item("small_power_plant") :add_dependency(config:get_item("secure_air_vent")) return config end -- Same as rules00() above except this uses symbols local function rules00a() local config = Configuration:make() config:add_item(Item:make(S.secure_air_vent)) config:add_item(Item:make(S.acid_bath)) config:get_item(S.acid_bath):add_usage(Electricity:make(12)) local acid = Acid:make() config:get_item(S.acid_bath):add_usage(acid) acid:set_type(S.hcl) acid:set_grade(5) config:add_item(Item:make(S.camera)) config:get_item(S.camera):add_usage(Electricity:make(1)) config:add_item(Item:make(S.small_power_plant)) config:get_item(S.small_power_plant) :add_provision(Electricity:make(11)) config:get_item(S.small_power_plant) :add_dependency(config:get_item(S.secure_air_vent)) return config end -- Call test driver functions local res0 = rules00() print(res0:toString()) local res0a = rules00a() print(res0a:toString())