lib/antelope/generator/ruby.rb in antelope-0.1.8 vs lib/antelope/generator/ruby.rb in antelope-0.1.9

- old
+ new

@@ -6,12 +6,15 @@ module Generator # Generates a ruby parser. class Ruby < Base - register_as "ruby" + register_as "ruby", "rubby" + has_directive "panic-mode", Boolean + has_directive "ruby.error-class", String + # Creates an action table for the parser. # # @return [String] def generate_action_table out = "" @@ -34,26 +37,41 @@ ", " block = if block.empty? "proc { |_| _ }" else - "proc #{production.block}" + "proc #{block}" end out << block << "],\n" end - out.chomp!(",\n") + out.chomp!( ",\n") out << "]" end + def define_own_handler? + directives.ruby.error_class? or + panic_mode? + end + + def panic_mode? + directives.panic_mode && + directives.ruby.error_class? && + grammar.contains_error_token? + end + + def error_class + directives.ruby.error_class + end + # Actually performs the generation. Takes the template from - # ruby.erb and outputs it to `<file>_parser.rb`. + # ruby.ant and outputs it to `<file>.rb`. # # @return [void] def generate - template "ruby.erb", "#{file}.rb" do |body| + template "ruby", "#{file}.rb" do |body| sprintf(grammar.compiler.body, :write => body) end end end end