Sha256: 6a2f2ccd446e0554c30f81f3041bf855c30872be825bbdef62f83f2643b4ef26

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

Productions:
% len = grammar.all_productions.size.to_s.size
% productions = grammar.all_productions.
%   map { |x| ["#{x.label}: #{x.items.join(' ')}", x.block] }
% body = productions.map { |_| _.first.size }.max
<%= body %>
% productions.each_with_index do |prod, i|
  <%= "%#{len}s" % i %> <%= "%-#{body}s" % prod[0] %> <%= prod[1] %>
% end

Precedence:
  --- highest
% grammar.precedence.each do |pr|
  <%= "%-8s" % pr.type %> <%= pr.level %>:
    {<%= pr.tokens.to_a.join(", ") %>}
% end
  --- lowest

% len = tableizer.table.flatten.map(&:keys).flatten.map(&:size).max
% states = grammar.states.to_a
% tableizer.table.each_with_index do |v, i|
%   state = states[i]
  State <%= i %>:
%   state.rules.each do |rule|
    <%= rule %>
      {<%= rule.lookahead.to_a.join(", ") %>}
%   end
%   transitions = v.each.select { |_, a| a && a[0] == :state }
%   reductions  = v.each.select { |_, a| a && a[0] == :reduce}
%   accepting   = v.each.select { |_, a| a && a[0] == :accept}
%   conflicts   = v.each.select { |_, (a, b)| a.is_a?(Array) }
%   thing = [:transitions, :reductions, :accepting]
%   num_type = {transitions: "State", reductions: "Rule", accepting: "Rule"}
%   h = Hash[thing.zip([transitions, reductions, accepting])]
%   h.each do |key, value|
%     next unless value.any?
    <%= key %>:
%     value.each do |token, (_, name)|
%     token_value = grammar.terminals.find { |_| _.name == token } || token
      <%= token_value %>: <%= num_type[key] %> <%= name %>
%     end
%   end
%   if conflicts.any?
    conflicts:
%     conflicts.each do |token, (first, second)|
      <%= token %>: <%= first.join(" ") %>/<%= second.join(" ") %>
%     end
%   end

% end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
antelope-0.1.7 lib/antelope/generator/templates/output.erb