2 require 'vtparse_tables'
6 self << (" " * (len - self.length))
10 File.open("vtparse_table.h", "w") { |f|
11 f.puts "typedef enum {"
12 $states_in_order.each_with_index { |state, i|
13 f.puts " VTPARSE_STATE_#{state.to_s.upcase} = #{i+1},"
15 f.puts "} vtparse_state_t;"
17 f.puts "typedef enum {"
18 $actions_in_order.each_with_index { |action, i|
19 f.puts " VTPARSE_ACTION_#{action.to_s.upcase} = #{i+1},"
21 f.puts "} vtparse_action_t;"
23 f.puts "typedef unsigned char state_change_t;"
24 f.puts "extern state_change_t STATE_TABLE[#{$states_in_order.length}][256];"
25 f.puts "extern vtparse_action_t ENTRY_ACTIONS[#{$states_in_order.length}];"
26 f.puts "extern vtparse_action_t EXIT_ACTIONS[#{$states_in_order.length}];"
27 f.puts "extern char *ACTION_NAMES[#{$actions_in_order.length+1}];"
28 f.puts "extern char *STATE_NAMES[#{$states_in_order.length+1}];"
32 puts "Wrote vtparse_table.h"
34 File.open("vtparse_table.c", "w") { |f|
36 f.puts '#include "vtparse_table.h"'
38 f.puts "char *ACTION_NAMES[] = {"
39 f.puts " \"<no action>\","
40 $actions_in_order.each { |action|
41 f.puts " \"#{action.to_s.upcase}\","
45 f.puts "char *STATE_NAMES[] = {"
46 f.puts " \"<no state>\","
47 $states_in_order.each { |state|
48 f.puts " \"#{state.to_s}\","
52 f.puts "state_change_t STATE_TABLE[#{$states_in_order.length}][256] = {"
53 $states_in_order.each_with_index { |state, i|
54 f.puts " { /* VTPARSE_STATE_#{state.to_s.upcase} = #{i} */"
55 $state_tables[state].each_with_index { |state_change, i|
59 (action,) = state_change.find_all { |s| s.kind_of?(Symbol) }
60 (state,) = state_change.find_all { |s| s.kind_of?(StateTransition) }
61 action_str = action ? "VTPARSE_ACTION_#{action.to_s.upcase}" : "0"
62 state_str = state ? "VTPARSE_STATE_#{state.to_state.to_s}" : "0"
63 f.puts "/*#{i.to_s.pad(3)}*/ #{action_str.pad(33)} | (#{state_str.pad(33)} << 4),"
71 f.puts "vtparse_action_t ENTRY_ACTIONS[] = {"
72 $states_in_order.each { |state|
73 actions = $states[state]
75 f.puts " VTPARSE_ACTION_#{actions[:on_entry].to_s.upcase}, /* #{state} */"
77 f.puts " 0 /* none for #{state} */,"
82 f.puts "vtparse_action_t EXIT_ACTIONS[] = {"
83 $states_in_order.each { |state|
84 actions = $states[state]
86 f.puts " VTPARSE_ACTION_#{actions[:on_exit].to_s.upcase}, /* #{state} */"
88 f.puts " 0 /* none for #{state} */,"
95 puts "Wrote vtparse_table.c"