Skip to content

Commit

Permalink
Merge pull request #104 from ydah/feature-embed-include
Browse files Browse the repository at this point in the history
Change to automatically insert `#include` of header files when they are specified
  • Loading branch information
yui-knk committed Oct 17, 2023
2 parents 21e405a + 71b82bc commit da4a6cd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/lrama/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Output
extend Forwardable
include Report::Duration

attr_reader :grammar_file_path, :context, :grammar, :error_recovery
attr_reader :grammar_file_path, :context, :grammar, :error_recovery, :include_header

def_delegators "@context", :yyfinal, :yylast, :yyntokens, :yynnts, :yynrules, :yynstates,
:yymaxutok, :yypact_ninf, :yytable_ninf
Expand All @@ -28,6 +28,7 @@ def initialize(
@context = context
@grammar = grammar
@error_recovery = error_recovery
@include_header = header_file_path ? header_file_path.sub("./", "") : nil
end

if ERB.instance_method(:initialize).parameters.last.first == :key
Expand Down
2 changes: 0 additions & 2 deletions sample/calc.y
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include <stdlib.h>
#include <ctype.h>

#include "calc.h"

static int yylex(YYSTYPE *val, YYLTYPE *loc);
static int yyerror(YYLTYPE *loc, const char *str);
%}
Expand Down
3 changes: 0 additions & 3 deletions sample/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

%{
// Prologue

#include "y.tab.h"

static enum yytokentype yylex(YYSTYPE *lval, YYLTYPE *yylloc);
static void yyerror(YYLTYPE *yylloc, const char *msg);

Expand Down
4 changes: 4 additions & 0 deletions template/bison/yacc.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@
# endif

<%# b4_header_include_if -%>
<%- if output.include_header -%>
#include "<%= output.include_header %>"
<%- else -%>
/* Use api.header.include to #include this header
instead of duplicating it here. */
<%- end -%>
<%# b4_shared_declarations -%>
<%-# b4_cpp_guard_open([b4_spec_mapped_header_file]) -%>
<%- if output.spec_mapped_header_file -%>
Expand Down

0 comments on commit da4a6cd

Please sign in to comment.