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},"
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}];"
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 $states_in_order.each { |state|
47 f.puts " \"#{state.to_s}\","
51 f.puts "state_change_t STATE_TABLE[#{$states_in_order.length}][256] = {"
52 $states_in_order.each { |state|
53 f.puts " { /* VTPARSE_STATE_#{state.to_s.upcase} */"
54 $state_tables[state].each_with_index { |state_change, i|
58 (action,) = state_change.find_all { |s| s.kind_of?(Symbol) }
59 (state,) = state_change.find_all { |s| s.kind_of?(StateTransition) }
60 action_str = action ? "VTPARSE_ACTION_#{action.to_s.upcase}" : "0"
61 state_str = state ? "VTPARSE_STATE_#{state.to_state.to_s}" : "0"
62 f.puts "/*#{i.to_s.pad(3)}*/ #{action_str.pad(33)} | (#{state_str.pad(33)} << 4),"
70 f.puts "vtparse_action_t ENTRY_ACTIONS[] = {"
71 $states_in_order.each { |state|
72 actions = $states[state]
74 f.puts " VTPARSE_ACTION_#{actions[:on_entry].to_s.upcase}, /* #{state} */"
76 f.puts " 0 /* none for #{state} */,"
81 f.puts "vtparse_action_t EXIT_ACTIONS[] = {"
82 $states_in_order.each { |state|
83 actions = $states[state]
85 f.puts " VTPARSE_ACTION_#{actions[:on_exit].to_s.upcase}, /* #{state} */"
87 f.puts " 0 /* none for #{state} */,"
94 puts "Wrote vtparse_table.c"