lib/lomic/LomicParser.rb in lomic-0.0.2 vs lib/lomic/LomicParser.rb in lomic-0.1.0
- old
+ new
@@ -12,11 +12,18 @@
def rule(number)
# TODO: ensure number is int
@currentRule = Rule.new(number)
if @first_rule
- @state.globals = instance_eval 'Globals.new'
+ begin
+ @state.globals = instance_eval 'Globals.new'
+ rescue
+ # No Globals class was declared. Create one
+ instance_eval "class Globals < LomicBase
+ end"
+ @state.globals = instance_eval 'Globals.new'
+ end
@first_rule = false
end
yield @state.globals
ensure
@@ -33,10 +40,9 @@
end
def self.load_source(filename)
dsl = new
dsl.instance_eval(File.read(filename),filename)
- # dsl.gamestate.globals = (dsl.instance_eval 'Globals.new')
dsl.gamestate
end
end
end # module