Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to automatically insert #include of header files when they are specified #104

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 -%>
ydah marked this conversation as resolved.
Show resolved Hide resolved
<%# b4_shared_declarations -%>
<%-# b4_cpp_guard_open([b4_spec_mapped_header_file]) -%>
<%- if output.spec_mapped_header_file -%>
Expand Down