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
35 36 37 38 39 40 |
# File 'lib/lomic/LomicParser.rb', line 35 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 |
Instance Method Details
#event(event_name, options = {}, &block) ⇒ Object
27 28 29 |
# File 'lib/lomic/LomicParser.rb', line 27 def event(event_name, ={}, &block) @currentRule.event(event_name, , &block) end |
#gamestate ⇒ Object
31 32 33 |
# File 'lib/lomic/LomicParser.rb', line 31 def gamestate @state end |
#rule(number) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lomic/LomicParser.rb', line 13 def rule(number) # TODO: ensure number is int @currentRule = Rule.new(number) if @first_rule @state.globals = instance_eval 'Globals.new' @first_rule = false end yield @state.globals ensure @state.addRule(@currentRule) @currentRule = nil end |