<commit_before>% * -*- Mode: Prolog -*- */

:- module(gnumake_parser,
          [
              parse_gnu_makefile/2
	  ]).

:- use_module(library(pio)).

% Wrapper for reading GNU Makefile
parse_gnu_makefile(F,M) :-
    debug(makefile,'reading: ~w\n',[F]),
    phrase_from_file(makefile_rules(Mf,1,F),F),
    atom_string(MAKEFILE_LIST,"MAKEFILE_LIST"),
    M = [assignment(MAKEFILE_LIST,"+=",F)|Mf],
    debug(makefile,"rules: ~w\n",[M]).

% Grammar for reading GNU Makefile
makefile_rules([],_,_) --> call(eos), !.
makefile_rules(Rules,Line,File) --> comment, !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules(Rules,Line,File) --> blank_line, !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules(Rules,Line,File) --> info_line, !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules(Rules,Line,File) --> warning_line, !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules(Rules,Line,File) --> include_line(Included), !, {Lnext is Line + 1, append(Included,Next,Rules)}, makefile_rules(Next,Lnext,File).
makefile_rules([Assignment|Rules],Line,File) --> makefile_assignment(Assignment), !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules([Rule|Rules],Line,File) --> makefile_rule(Rule,Lrule), !, {Lnext is Line + Lrule}, makefile_rules(Rules,Lnext,File).
makefile_rules(_,Line,File) --> line_as_string(L), !, {format(string(Err),"GNU makefile parse error at line ~d of file ~w: ~w",[Line,File,L]),syntax_error(Err)}.

eos([], []).

warning_line -->
    opt_whitespace,
    "$(warning",
    whitespace,
    makefile_warning_text(W),<commit_msg>$(error...)<commit_after>% * -*- Mode: Prolog -*- */

:- module(gnumake_parser,
          [
              parse_gnu_makefile/2
	  ]).

:- use_module(library(pio)).

% Wrapper for reading GNU Makefile
parse_gnu_makefile(F,M) :-
    debug(makefile,'reading: ~w\n',[F]),
    phrase_from_file(makefile_rules(Mf,1,F),F),
    atom_string(MAKEFILE_LIST,"MAKEFILE_LIST"),
    M = [assignment(MAKEFILE_LIST,"+=",F)|Mf],
    debug(makefile,"rules: ~w\n",[M]).

% Grammar for reading GNU Makefile
makefile_rules([],_,_) --> call(eos), !.
makefile_rules(Rules,Line,File) --> comment, !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules(Rules,Line,File) --> blank_line, !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules(Rules,Line,File) --> info_line, !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules(Rules,Line,File) --> warning_line, !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules(Rules,Line,File) --> error_line, !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules(Rules,Line,File) --> include_line(Included), !, {Lnext is Line + 1, append(Included,Next,Rules)}, makefile_rules(Next,Lnext,File).
makefile_rules([Assignment|Rules],Line,File) --> makefile_assignment(Assignment), !, {Lnext is Line + 1}, makefile_rules(Rules,Lnext,File).
makefile_rules([Rule|Rules],Line,File) --> makefile_rule(Rule,Lrule), !, {Lnext is Line + Lrule}, makefile_rules(Rules,Lnext,File).
makefile_rules(_,Line,File) --> line_as_string(L), !, {format(string(Err),"GNU makefile parse error at line ~d of file ~w: ~w",[Line,File,L]),syntax_error(Err)}.

eos([], []).

error_line -->
    opt_whitespace,
    "$(error",
    whitespace,
    makefile_warning_text(W),
    ")",
    opt_whitespace,
    "\n",
    !,
    {format(string(Warning),"~w~n",[W]),
     write(user_error,Warning),
     throw(Warning)}.

warning_line -->
    opt_whitespace,
    "$(warning",
    whitespace,
    makefile_warning_text(W),
{'fraction_non_alphanumeric': 0.18915198237885464, 'fraction_numerical': 0.004680616740088106, 'mean_word_length': 5.318260869565218, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2990955', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1343, 'n_words': 208}