Class: Calyx::Format::YAMLGrammar

Inherits:
Object
  • Object
show all
Defined in:
lib/calyx/format.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ YAMLGrammar

Returns a new instance of YAMLGrammar.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/calyx/format.rb', line 47

def initialize(filename)
  warn [
    "NOTE: Loading grammars defined in YAML is deprecated. ",
    "Use the JSON format instead: `Calyx::Format.load(\"hello.json\")`"
  ].join

  require 'yaml'
  @filename = filename
  @contents = File.read(@filename)
  @rules = YAML.load(@contents)
end

Instance Method Details

#each_rule(&block) ⇒ Object



59
60
61
62
63
# File 'lib/calyx/format.rb', line 59

def each_rule(&block)
  @rules.each do |rule, productions|
    yield rule, productions, Trace.new(/#{rule}:/, @filename, @contents)
  end
end