class Antelope::Generator::CHeader

Public Instance Methods

define_stype?() click to toggle source
# File lib/antelope/generator/c_header.rb, line 20
def define_stype?
  !!directives.union[0] && !directives.api.value.type
end
generate() click to toggle source
# File lib/antelope/generator/c_header.rb, line 100
def generate
  template "c_header", "#{file}.h"
end
guard_name() click to toggle source
# File lib/antelope/generator/c_header.rb, line 96
def guard_name
  "#{prefix.upcase}#{file.gsub(/[\W]/, "_").upcase}"
end
lex_params() click to toggle source
# File lib/antelope/generator/c_header.rb, line 24
def lex_params
  params = [directives.lex_param, directives.param].compact.
    flatten

  if params.any?
    ", " << params.join(", ")
  else
    ""
  end
end
params() click to toggle source
# File lib/antelope/generator/c_header.rb, line 40
def params
  if directives.param
    directives.param.join(", ")
  else
    ""
  end
end
parse_params() click to toggle source
# File lib/antelope/generator/c_header.rb, line 35
def parse_params
  [directives.parse_param, directives.param].compact.flatten.
    join(", ")
end
prefix() click to toggle source
# File lib/antelope/generator/c_header.rb, line 76
def prefix
  if directives.api.prefix
    directives.api.prefix
  else
    "yy"
  end
end
push?() click to toggle source
# File lib/antelope/generator/c_header.rb, line 16
def push?
  directives.api.push_pull == "push"
end
stype() click to toggle source
# File lib/antelope/generator/c_header.rb, line 48
def stype
  prefix.upcase << if directives.api.value.type
    directives.api.value.type
  elsif directives.union.size > 1
    directives.union[0]
  else
    "STYPE"
  end
end
symbols() click to toggle source
# File lib/antelope/generator/c_header.rb, line 88
def symbols
  @_symbols ||= begin
    sym  = grammar.terminals.map(&:name) + grammar.nonterminals
    nums = sym.each_with_index.map { |v, i| [v, i + 257] }
    Hash[nums]
  end
end
terminal_type() click to toggle source
# File lib/antelope/generator/c_header.rb, line 62
def terminal_type
  "int" # for now
end
token_prefix() click to toggle source
# File lib/antelope/generator/c_header.rb, line 66
def token_prefix
  if directives.api.token.prefix
    directives.api.token.prefix
  elsif directives.api.prefix
    prefix.upcase
  else
    ""
  end
end
union_body() click to toggle source
# File lib/antelope/generator/c_header.rb, line 58
def union_body
  directives.union.last
end
upper_prefix() click to toggle source
# File lib/antelope/generator/c_header.rb, line 84
def upper_prefix
  prefix.upcase
end