<commit_before>%defines
%locations
%pure-parser
%name-prefix "gra_"
%error-verbose
%verbose
%lex-param { void *scanner }
%parse-param { grammar *instance }

%expect 1

%code requires
{
    #pragma GCC diagnostic ignored "-Wconversion"

    #include "log/log.hpp"
    using namespace gorc;
    using namespace gorc::cog;

    #define YYLTYPE diagnostic_context_location

    #define YYLLOC_DEFAULT(Cur, Rhs, N)                                                 \
    do {                                                                                \
        if(N) {                                                                         \
            (Cur) = diagnostic_context_location(nullptr,                                \
                                                YYRHSLOC(Rhs, 1).first_line,            \
                                                YYRHSLOC(Rhs, 1).first_col,             \
                                                YYRHSLOC(Rhs, N).last_line,             \
                                                YYRHSLOC(Rhs, N).last_col);             \
        }                                                                               \
        else {                                                                          \
            (Cur) = diagnostic_context_location(nullptr,                                \
                                                YYRHSLOC(Rhs, 0).last_line,             \
                                                YYRHSLOC(Rhs, 0).last_col,              \
                                                YYRHSLOC(Rhs, 0).last_line,             \
                                                YYRHSLOC(Rhs, 0).last_col);             \
        }                                                                               \
    } while(0)
}

%code top
{
    #include "grammar.hpp"
    #include "log/log.hpp"

    using namespace gorc;
    using namespace gorc::cog;
    using namespace gorc::cog::ast;
}

%union
{
    char *string;
    int integer;
    float floating;

    ast::identifier *identifier;

    ast::symbol_field *symbol_field;
    ast::symbol_extension *symbol_extension;
    ast::list_node<ast::symbol_extension*> *symbol_extension_list;
    ast::symbol *symbol;
    ast::list_node<ast::symbol*> *symbol_list;

    ast::unary_operator unary_operator;
    ast::infix_operator infix_operator;
    ast::expression *expression;
    ast::list_node<ast::expression*> *expression_list;

    ast::statement *statement;
    ast::list_node<ast::statement*> *statement_list;
    ast::for_optional_expression *for_optional_expression;

    ast::translation_unit *translation_unit;
}

/* Destructors */
%destructor { free($$); } <string>

/* Main keyword tokens */
%token FLAGS SYMBOLS CODE END

/* Symbols keyword tokens */
%token ENDLINE

/* Code keyword tokens */
%token BREAK CALL DO ELSE FOR IF RETURN WHILE

/* Code operator tokens */
%token EQ_OP NE_OP GE_OP LE_OP LOGICAL_AND_OP LOGICAL_OR_OP

/* Literals */
%token <string> RAW_IDENTIFIER STRING_FRAGMENT STRING_LITERAL
%token <integer> INTEGER_LITERAL
%token <floating> FLOAT_LITERAL

%type <identifier> identifier

/* Symbols */
%type <symbol_field> symbol_field
%type <symbol_extension> symbol_extension
%type <symbol_extension_list> symbol_extension_seq optional_symbol_extension_seq
%type <symbol> inner_symbol symbol
%type <symbol_list> symbol_seq optional_symbol_seq symbol_section

/* Expressions */
%type <floating> vector_component_scalar vector_component
%type <unary_operator> unary_operator
%type <infix_operator> multiplicative_operator additive_operator relational_operator
%type <infix_operator> equality_operator
%type <expression> literal_expression primary_expression postfix_expression unary_expression
%type <expression> multiplicative_expression additive_expression relational_expression
%type <expression> equality_expression and_expression exclusive_or_expression
%type <expression> inclusive_or_expression logical_and_expression logical_or_expression
%type <expression> assignment_expression expression vector_literal_expression
%type <expression_list> argument_expression_list optional_argument_expression_list

/* Statements */
%type <statement> compound_statement expression_statement jump_statement selection_statement
%type <statement> iteration_statement labeled_statement statement
%type <statement_list> statement_seq optional_statement_seq code_section
%type <for_optional_expression> for_optional_expression

/* Translation unit */
%type <integer> flags_section
%type <translation_unit> translation_unit

%start translation_unit

%{
    using namespace gorc;
    using namespace gorc::cog;

    int yylex(YYSTYPE *lvalp, diagnostic_context_location *llocp, void *scanner);

    void yyerror(diagnostic_context_location *llocp, grammar*, char const *err)
    {
        diagnostic_context dc(*llocp);
        LOG_ERROR(err);
    }

    gorc::cog::ast::translation_unit* gorc::cog::grammar::parse()
    {
        gra_parse(this);
        return tu;
    }

    #define scanner instance->get_scanner()
    #define ast instance->factory
%}

%%
<commit_msg>Tweak cog parser to fix build failure on travis<commit_after>%defines
%locations
%pure-parser
%name-prefix "gra_"
%error-verbose
%verbose
%lex-param { void *scanner }
%parse-param { grammar *instance }

%expect 1

%code requires
{
    #pragma GCC diagnostic ignored "-Wconversion"

    #include "log/log.hpp"
    using namespace gorc;
    using namespace gorc::cog;

    #define YYLTYPE diagnostic_context_location

    #define YYLLOC_DEFAULT(Cur, Rhs, N)                                                 \
    do {                                                                                \
        if(N) {                                                                         \
            (Cur) = diagnostic_context_location(nullptr,                                \
                                                YYRHSLOC(Rhs, 1).first_line,            \
                                                YYRHSLOC(Rhs, 1).first_col,             \
                                                YYRHSLOC(Rhs, N).last_line,             \
                                                YYRHSLOC(Rhs, N).last_col);             \
        }                                                                               \
        else {                                                                          \
            (Cur) = diagnostic_context_location(nullptr,                                \
                                                YYRHSLOC(Rhs, 0).last_line,             \
                                                YYRHSLOC(Rhs, 0).last_col,              \
                                                YYRHSLOC(Rhs, 0).last_line,             \
                                                YYRHSLOC(Rhs, 0).last_col);             \
        }                                                                               \
    } while(0)
}

%code top
{
    #include "grammar.hpp"
    #include "log/log.hpp"

    using namespace gorc;
    using namespace gorc::cog;
    using namespace gorc::cog::ast;
}

%union
{
    char *string;
    int integer;
    float floating;

    ast::identifier *identifier;

    ast::symbol_field *symbol_field;
    ast::symbol_extension *symbol_extension;
    ast::list_node<ast::symbol_extension*> *symbol_extension_list;
    ast::symbol *symbol;
    ast::list_node<ast::symbol*> *symbol_list;

    ast::unary_operator unary_operator;
    ast::infix_operator infix_operator;
    ast::expression *expression;
    ast::list_node<ast::expression*> *expression_list;

    ast::statement *statement;
    ast::list_node<ast::statement*> *statement_list;
    ast::for_optional_expression *for_optional_expression;

    ast::translation_unit *translation_unit;
}

/* Destructors */
%destructor { free($$); } <string>

/* Main keyword tokens */
%token FLAGS SYMBOLS CODE END

/* Symbols keyword tokens */
%token ENDLINE

/* Code keyword tokens */
%token BREAK CALL DO ELSE FOR IF RETURN WHILE

/* Code operator tokens */
%token EQ_OP NE_OP GE_OP LE_OP LOGICAL_AND_OP LOGICAL_OR_OP

/* Literals */
%token <string> RAW_IDENTIFIER STRING_FRAGMENT STRING_LITERAL
%token <integer> INTEGER_LITERAL
%token <floating> FLOAT_LITERAL

%type <identifier> identifier

/* Symbols */
%type <symbol_field> symbol_field
%type <symbol_extension> symbol_extension
%type <symbol_extension_list> symbol_extension_seq optional_symbol_extension_seq
%type <symbol> inner_symbol symbol
%type <symbol_list> symbol_seq optional_symbol_seq symbol_section

/* Expressions */
%type <floating> vector_component_scalar vector_component
%type <unary_operator> unary_operator
%type <infix_operator> multiplicative_operator additive_operator relational_operator
%type <infix_operator> equality_operator
%type <expression> literal_expression primary_expression postfix_expression unary_expression
%type <expression> multiplicative_expression additive_expression relational_expression
%type <expression> equality_expression and_expression exclusive_or_expression
%type <expression> inclusive_or_expression logical_and_expression logical_or_expression
%type <expression> assignment_expression expression vector_literal_expression
%type <expression_list> argument_expression_list optional_argument_expression_list

/* Statements */
%type <statement> compound_statement expression_statement jump_statement selection_statement
%type <statement> iteration_statement labeled_statement statement
%type <statement_list> statement_seq optional_statement_seq code_section
%type <for_optional_expression> for_optional_expression

/* Translation unit */
%type <integer> flags_section
%type <translation_unit> translation_unit

%start translation_unit

%{
    using namespace gorc;
    using namespace gorc::cog;

    int yylex(YYSTYPE *lvalp, diagnostic_context_location *llocp, void *scanner);

    void yyerror(diagnostic_context_location *llocp, grammar*, char const *err)
    {
        diagnostic_context dc(*llocp);
        LOG_ERROR(err);
    }

    gorc::cog::ast::translation_unit* gorc::cog::grammar::parse()
    {
        yyparse(this);
        return tu;
    }

    #define scanner instance->get_scanner()
    #define ast instance->factory
%}

%%

{'fraction_non_alphanumeric': 0.08158508158508158, 'fraction_numerical': 0.001554001554001554, 'mean_word_length': 2.0783258594917786, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 66, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3284069', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2636, 'n_words': 598}