lib/lrama/output.rb in lrama-0.6.2 vs lib/lrama/output.rb in lrama-0.6.3

- old
+ new

@@ -14,12 +14,11 @@ def_delegators "@grammar", :eof_symbol, :error_symbol, :undef_symbol, :accept_symbol def initialize( out:, output_file_path:, template_name:, grammar_file_path:, - header_out: nil, header_file_path: nil, - context:, grammar:, error_recovery: false + context:, grammar:, header_out: nil, header_file_path: nil, error_recovery: false ) @out = out @output_file_path = output_file_path @template_name = template_name @grammar_file_path = grammar_file_path @@ -157,9 +156,64 @@ <<-STR #{comment} #line #{@grammar.initial_action.line} "#{@grammar_file_path}" {#{@grammar.initial_action.translated_code}} + STR + end + + def after_shift_function(comment = "") + return "" unless @grammar.after_shift + + <<-STR + #{comment} +#line #{@grammar.after_shift.line} "#{@grammar_file_path}" + {#{@grammar.after_shift.s_value}(#{parse_param_name});} +#line [@oline@] [@ofile@] + STR + end + + def before_reduce_function(comment = "") + return "" unless @grammar.before_reduce + + <<-STR + #{comment} +#line #{@grammar.before_reduce.line} "#{@grammar_file_path}" + {#{@grammar.before_reduce.s_value}(yylen#{user_args});} +#line [@oline@] [@ofile@] + STR + end + + def after_reduce_function(comment = "") + return "" unless @grammar.after_reduce + + <<-STR + #{comment} +#line #{@grammar.after_reduce.line} "#{@grammar_file_path}" + {#{@grammar.after_reduce.s_value}(yylen#{user_args});} +#line [@oline@] [@ofile@] + STR + end + + def after_shift_error_token_function(comment = "") + return "" unless @grammar.after_shift_error_token + + <<-STR + #{comment} +#line #{@grammar.after_shift_error_token.line} "#{@grammar_file_path}" + {#{@grammar.after_shift_error_token.s_value}(#{parse_param_name});} +#line [@oline@] [@ofile@] + STR + end + + def after_pop_stack_function(len, comment = "") + return "" unless @grammar.after_pop_stack + + <<-STR + #{comment} +#line #{@grammar.after_pop_stack.line} "#{@grammar_file_path}" + {#{@grammar.after_pop_stack.s_value}(#{len}#{user_args});} +#line [@oline@] [@ofile@] STR end def symbol_actions_for_error_token str = ""