class Antelope::Generator::Ruby

Generates a ruby parser.

Public Instance Methods

basic_indent() click to toggle source
# File lib/antelope/generator/ruby.rb, line 36
def basic_indent
  @_indent ||= case indent_type
               when 'space'
                 ' '
               when 'tab'
                 "\t"
               else
                 indent_type
               end * indent_size
end
define_own_handler?() click to toggle source
# File lib/antelope/generator/ruby.rb, line 83
def define_own_handler?
  directives.ruby.error_class? ||
    panic_mode?
end
error_class() click to toggle source
# File lib/antelope/generator/ruby.rb, line 94
def error_class
  directives.ruby.error_class
end
generate() click to toggle source

Actually performs the generation. Takes the template from ruby.ant and outputs it to ‘<file>.rb`.

@return [void]

# File lib/antelope/generator/ruby.rb, line 102
def generate
  template 'ruby', "#{file}.rb" do |body|
    body
      .gsub!("\n", "\n#{indent}")
      .gsub!(/^[ \t]*\n/, "\n")
    format(grammar.compiler.body, write: body)
  end
end
generate_action_table() click to toggle source

Creates an action table for the parser.

@return [String]

# File lib/antelope/generator/ruby.rb, line 18
def generate_action_table
  parts = []
  table.each do |state|
    out = ''
    state.each do |token, action|
      inspect = %(:"#{token}" =>)
      out << "#{basic_indent}#{inspect} #{action.inspect},\n"
    end
    parts << "{\n#{out.chomp(",\n")}\n}"
  end

  "[#{parts.join(', ')}]"
end
generate_productions_list() click to toggle source

Outputs an array of all of the productions.

@return [String]

# File lib/antelope/generator/ruby.rb, line 64
def generate_productions_list
  out = "[\n"

  productions.each do |(label, size, block)|
    out << '[' << label.name.inspect << ', ' <<
      size.inspect << ', '

    block = if block.empty?
              'DEFAULT_PROC'
            else
              "proc { |match| #{block[1..-2]} }"
            end

    out << block << "],\n"
  end
  out.chomp!(",\n")
  out << ']'
end
indent() click to toggle source
# File lib/antelope/generator/ruby.rb, line 32
def indent
  basic_indent * (directives.ruby.indent || 2)
end
indent_size() click to toggle source
# File lib/antelope/generator/ruby.rb, line 51
def indent_size
  directives.ruby.indent_size ||
    case indent_type
    when 'tab'
      1
    else
      2
    end
end
indent_type() click to toggle source
# File lib/antelope/generator/ruby.rb, line 47
def indent_type
  directives.ruby.indent_type || 'space'
end
panic_mode?() click to toggle source
# File lib/antelope/generator/ruby.rb, line 88
def panic_mode?
  directives.panic_mode &&
    directives.ruby.error_class? &&
    grammar.contains_error_token?
end