Class: Lomic::LomicParser
- Inherits:
-
Object
- Object
- Lomic::LomicParser
- Defined in:
- lib/lomic/LomicParser.rb
Class Method Summary collapse
Instance Method Summary collapse
- #event(event_name, options = {}, &block) ⇒ Object
- #gamestate ⇒ Object
-
#initialize ⇒ LomicParser
constructor
A new instance of LomicParser.
- #rule(number) ⇒ Object
Constructor Details
#initialize ⇒ LomicParser
Returns a new instance of LomicParser.
5 6 7 8 9 10 11 |
# File 'lib/lomic/LomicParser.rb', line 5 def initialize # points to the Rule that is currently being parsed @currentRule = nil # The entire state of the game @state = GameState.new @first_rule = true end |
Class Method Details
.load_source(filename) ⇒ Object
42 43 44 45 46 |
# File 'lib/lomic/LomicParser.rb', line 42 def self.load_source(filename) dsl = new dsl.instance_eval(File.read(filename),filename) dsl.gamestate end |
Instance Method Details
#event(event_name, options = {}, &block) ⇒ Object
34 35 36 |
# File 'lib/lomic/LomicParser.rb', line 34 def event(event_name, ={}, &block) @currentRule.event(event_name, , &block) end |
#gamestate ⇒ Object
38 39 40 |
# File 'lib/lomic/LomicParser.rb', line 38 def gamestate @state end |
#rule(number) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lomic/LomicParser.rb', line 13 def rule(number) # TODO: ensure number is int @currentRule = Rule.new(number) if @first_rule 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 @state.addRule(@currentRule) @currentRule = nil end |