reduce memory usage and cleanup code

This commit is contained in:
xensik
2022-01-19 20:01:12 +01:00
parent 9dbdd37f15
commit 9c8a67ff46
167 changed files with 25818 additions and 18774 deletions

View File

@ -28,7 +28,8 @@ void h1_pop_header(xsk::gsc::context* ctx);
RGX_PATH ([_A-Za-z0-9]+\\)+[_A-Za-z0-9]+
RGX_IDENTIFIER [_A-Za-z][_A-Za-z0-9]*
RGX_STRING \"(?:\\.|[^\"])*?\"|\'(?:\\.|[^\'])*?\'
RGX_COLOR #([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
RGX_COLOR_S #[0-9a-fA-F]{3}
RGX_COLOR_L #[0-9a-fA-F]{6}
RGX_FLT_DEC [0-9]+\.(?:[0-9]*)?f?|\.[0-9]+f?
RGX_INT_OCT 0[1-7][0-7]*
RGX_INT_BIN 0[bB][01]+
@ -153,16 +154,17 @@ RGX_DEFAULT (.|\n)
\| { return h1::parser::make_BITWISE_OR(ctx->loc); }
\& { return h1::parser::make_BITWISE_AND(ctx->loc); }
\^ { return h1::parser::make_BITWISE_EXOR(ctx->loc); }
{RGX_PATH} { return h1::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
{RGX_IDENTIFIER} { return h1::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
\&{RGX_STRING} { return h1::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
{RGX_PATH} { return h1::parser::make_PATH(xsk::gsc::h1::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
{RGX_IDENTIFIER} { return h1::parser::make_IDENTIFIER(xsk::gsc::h1::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
\&{RGX_STRING} { return h1::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_STRING} { return h1::parser::make_STRING(std::string(yytext), ctx->loc); }
{RGX_COLOR} { return h1::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
{RGX_COLOR_S} { return h1::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_COLOR_L} { return h1::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_FLT_DEC} { return h1::parser::make_FLOAT(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return h1::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return h1::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return h1::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return h1::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return h1::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return h1::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return h1::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return h1::parser::make_INTEGER(std::string(yytext), ctx->loc); }
<<EOF>> { if(ctx->header_top > 0) h1_pop_header(ctx); else return h1::parser::make_H1EOF(ctx->loc); }
<*>{RGX_DEFAULT} { throw h1::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
@ -170,60 +172,60 @@ RGX_DEFAULT (.|\n)
void h1_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -231,8 +233,8 @@ void h1_push_header(xsk::gsc::context* ctx, const std::string& file)
void h1_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -137,10 +137,7 @@ xsk::gsc::h1::parser::symbol_type H1lex(yyscan_t yyscanner, xsk::gsc::context* c
%token <std::string> ISTRING "localized string"
%token <std::string> COLOR "color"
%token <std::string> FLOAT "float"
%token <std::string> INT_DEC "int"
%token <std::string> INT_OCT "octal int"
%token <std::string> INT_BIN "binary int"
%token <std::string> INT_HEX "hexadecimal int"
%token <std::string> INTEGER "integer"
%type <ast::program::ptr> program
%type <ast::include::ptr> include
@ -468,7 +465,7 @@ stmt_default
;
stmt_break
: BREAK SEMICOLON
: BREAK SEMICOLON
{ $$ = std::make_unique<ast::stmt_break>(@$); }
;
@ -821,15 +818,9 @@ expr_float
;
expr_integer
: SUB INT_DEC %prec NEG
: SUB INTEGER %prec NEG
{ $$ = std::make_unique<ast::expr_integer>(@$, "-" + $2); };
| INT_DEC
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_OCT
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_BIN
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_HEX
| INTEGER
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
;

View File

@ -28,7 +28,8 @@ void h2_pop_header(xsk::gsc::context* ctx);
RGX_PATH ([_A-Za-z0-9]+\\)+[_A-Za-z0-9]+
RGX_IDENTIFIER [_A-Za-z][_A-Za-z0-9]*
RGX_STRING \"(?:\\.|[^\"])*?\"|\'(?:\\.|[^\'])*?\'
RGX_COLOR #([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
RGX_COLOR_S #[0-9a-fA-F]{3}
RGX_COLOR_L #[0-9a-fA-F]{6}
RGX_FLT_DEC [0-9]+\.(?:[0-9]*)?f?|\.[0-9]+f?
RGX_INT_OCT 0[1-7][0-7]*
RGX_INT_BIN 0[bB][01]+
@ -153,16 +154,17 @@ RGX_DEFAULT (.|\n)
\| { return h2::parser::make_BITWISE_OR(ctx->loc); }
\& { return h2::parser::make_BITWISE_AND(ctx->loc); }
\^ { return h2::parser::make_BITWISE_EXOR(ctx->loc); }
{RGX_PATH} { return h2::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
{RGX_IDENTIFIER} { return h2::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
\&{RGX_STRING} { return h2::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
{RGX_PATH} { return h2::parser::make_PATH(xsk::gsc::h2::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
{RGX_IDENTIFIER} { return h2::parser::make_IDENTIFIER(xsk::gsc::h2::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
\&{RGX_STRING} { return h2::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_STRING} { return h2::parser::make_STRING(std::string(yytext), ctx->loc); }
{RGX_COLOR} { return h2::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
{RGX_COLOR_S} { return h2::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_COLOR_L} { return h2::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_FLT_DEC} { return h2::parser::make_FLOAT(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return h2::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return h2::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return h2::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return h2::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return h2::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return h2::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return h2::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return h2::parser::make_INTEGER(std::string(yytext), ctx->loc); }
<<EOF>> { if(ctx->header_top > 0) h2_pop_header(ctx); else return h2::parser::make_H2EOF(ctx->loc); }
<*>{RGX_DEFAULT} { throw h2::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
@ -170,60 +172,60 @@ RGX_DEFAULT (.|\n)
void h2_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -231,8 +233,8 @@ void h2_push_header(xsk::gsc::context* ctx, const std::string& file)
void h2_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -137,10 +137,7 @@ xsk::gsc::h2::parser::symbol_type H2lex(yyscan_t yyscanner, xsk::gsc::context* c
%token <std::string> ISTRING "localized string"
%token <std::string> COLOR "color"
%token <std::string> FLOAT "float"
%token <std::string> INT_DEC "int"
%token <std::string> INT_OCT "octal int"
%token <std::string> INT_BIN "binary int"
%token <std::string> INT_HEX "hexadecimal int"
%token <std::string> INTEGER "integer"
%type <ast::program::ptr> program
%type <ast::include::ptr> include
@ -468,7 +465,7 @@ stmt_default
;
stmt_break
: BREAK SEMICOLON
: BREAK SEMICOLON
{ $$ = std::make_unique<ast::stmt_break>(@$); }
;
@ -821,15 +818,9 @@ expr_float
;
expr_integer
: SUB INT_DEC %prec NEG
: SUB INTEGER %prec NEG
{ $$ = std::make_unique<ast::expr_integer>(@$, "-" + $2); };
| INT_DEC
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_OCT
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_BIN
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_HEX
| INTEGER
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
;

View File

@ -28,7 +28,8 @@ void iw5_pop_header(xsk::gsc::context* ctx);
RGX_PATH ([_A-Za-z0-9]+\\)+[_A-Za-z0-9]+
RGX_IDENTIFIER [_A-Za-z][_A-Za-z0-9]*
RGX_STRING \"(?:\\.|[^\"])*?\"|\'(?:\\.|[^\'])*?\'
RGX_COLOR #([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
RGX_COLOR_S #[0-9a-fA-F]{3}
RGX_COLOR_L #[0-9a-fA-F]{6}
RGX_FLT_DEC [0-9]+\.(?:[0-9]*)?f?|\.[0-9]+f?
RGX_INT_OCT 0[1-7][0-7]*
RGX_INT_BIN 0[bB][01]+
@ -152,16 +153,17 @@ RGX_DEFAULT (.|\n)
\| { return iw5::parser::make_BITWISE_OR(ctx->loc); }
\& { return iw5::parser::make_BITWISE_AND(ctx->loc); }
\^ { return iw5::parser::make_BITWISE_EXOR(ctx->loc); }
{RGX_PATH} { return iw5::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
{RGX_IDENTIFIER} { return iw5::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
\&{RGX_STRING} { return iw5::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
{RGX_PATH} { return iw5::parser::make_PATH(xsk::gsc::iw5::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
{RGX_IDENTIFIER} { return iw5::parser::make_IDENTIFIER(xsk::gsc::iw5::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
\&{RGX_STRING} { return iw5::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_STRING} { return iw5::parser::make_STRING(std::string(yytext), ctx->loc); }
{RGX_COLOR} { return iw5::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
{RGX_COLOR_S} { return iw5::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_COLOR_L} { return iw5::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_FLT_DEC} { return iw5::parser::make_FLOAT(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return iw5::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return iw5::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return iw5::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return iw5::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return iw5::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return iw5::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return iw5::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return iw5::parser::make_INTEGER(std::string(yytext), ctx->loc); }
<<EOF>> { if(ctx->header_top > 0) iw5_pop_header(ctx); else return iw5::parser::make_IW5EOF(ctx->loc); }
<*>{RGX_DEFAULT} { throw iw5::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
@ -169,60 +171,60 @@ RGX_DEFAULT (.|\n)
void iw5_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -230,8 +232,8 @@ void iw5_push_header(xsk::gsc::context* ctx, const std::string& file)
void iw5_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -136,10 +136,7 @@ xsk::gsc::iw5::parser::symbol_type IW5lex(yyscan_t yyscanner, xsk::gsc::context*
%token <std::string> ISTRING "localized string"
%token <std::string> COLOR "color"
%token <std::string> FLOAT "float"
%token <std::string> INT_DEC "int"
%token <std::string> INT_OCT "octal int"
%token <std::string> INT_BIN "binary int"
%token <std::string> INT_HEX "hexadecimal int"
%token <std::string> INTEGER "integer"
%type <ast::program::ptr> program
%type <ast::include::ptr> include
@ -458,7 +455,7 @@ stmt_default
;
stmt_break
: BREAK SEMICOLON
: BREAK SEMICOLON
{ $$ = std::make_unique<ast::stmt_break>(@$); }
;
@ -811,15 +808,9 @@ expr_float
;
expr_integer
: SUB INT_DEC %prec NEG
: SUB INTEGER %prec NEG
{ $$ = std::make_unique<ast::expr_integer>(@$, "-" + $2); };
| INT_DEC
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_OCT
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_BIN
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_HEX
| INTEGER
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
;

View File

@ -28,7 +28,8 @@ void iw6_pop_header(xsk::gsc::context* ctx);
RGX_PATH ([_A-Za-z0-9]+\\)+[_A-Za-z0-9]+
RGX_IDENTIFIER [_A-Za-z][_A-Za-z0-9]*
RGX_STRING \"(?:\\.|[^\"])*?\"|\'(?:\\.|[^\'])*?\'
RGX_COLOR #([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
RGX_COLOR_S #[0-9a-fA-F]{3}
RGX_COLOR_L #[0-9a-fA-F]{6}
RGX_FLT_DEC [0-9]+\.(?:[0-9]*)?f?|\.[0-9]+f?
RGX_INT_OCT 0[1-7][0-7]*
RGX_INT_BIN 0[bB][01]+
@ -152,16 +153,17 @@ RGX_DEFAULT (.|\n)
\| { return iw6::parser::make_BITWISE_OR(ctx->loc); }
\& { return iw6::parser::make_BITWISE_AND(ctx->loc); }
\^ { return iw6::parser::make_BITWISE_EXOR(ctx->loc); }
{RGX_PATH} { return iw6::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
{RGX_IDENTIFIER} { return iw6::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
\&{RGX_STRING} { return iw6::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
{RGX_PATH} { return iw6::parser::make_PATH(xsk::gsc::iw6::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
{RGX_IDENTIFIER} { return iw6::parser::make_IDENTIFIER(xsk::gsc::iw6::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
\&{RGX_STRING} { return iw6::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_STRING} { return iw6::parser::make_STRING(std::string(yytext), ctx->loc); }
{RGX_COLOR} { return iw6::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
{RGX_COLOR_S} { return iw6::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_COLOR_L} { return iw6::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_FLT_DEC} { return iw6::parser::make_FLOAT(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return iw6::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return iw6::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return iw6::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return iw6::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return iw6::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return iw6::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return iw6::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return iw6::parser::make_INTEGER(std::string(yytext), ctx->loc); }
<<EOF>> { if(ctx->header_top > 0) iw6_pop_header(ctx); else return iw6::parser::make_IW6EOF(ctx->loc); }
<*>{RGX_DEFAULT} { throw iw6::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
@ -169,60 +171,60 @@ RGX_DEFAULT (.|\n)
void iw6_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -230,8 +232,8 @@ void iw6_push_header(xsk::gsc::context* ctx, const std::string& file)
void iw6_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -136,10 +136,7 @@ xsk::gsc::iw6::parser::symbol_type IW6lex(yyscan_t yyscanner, xsk::gsc::context*
%token <std::string> ISTRING "localized string"
%token <std::string> COLOR "color"
%token <std::string> FLOAT "float"
%token <std::string> INT_DEC "int"
%token <std::string> INT_OCT "octal int"
%token <std::string> INT_BIN "binary int"
%token <std::string> INT_HEX "hexadecimal int"
%token <std::string> INTEGER "integer"
%type <ast::program::ptr> program
%type <ast::include::ptr> include
@ -458,7 +455,7 @@ stmt_default
;
stmt_break
: BREAK SEMICOLON
: BREAK SEMICOLON
{ $$ = std::make_unique<ast::stmt_break>(@$); }
;
@ -811,15 +808,9 @@ expr_float
;
expr_integer
: SUB INT_DEC %prec NEG
: SUB INTEGER %prec NEG
{ $$ = std::make_unique<ast::expr_integer>(@$, "-" + $2); };
| INT_DEC
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_OCT
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_BIN
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_HEX
| INTEGER
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
;

View File

@ -28,7 +28,8 @@ void iw7_pop_header(xsk::gsc::context* ctx);
RGX_PATH ([_A-Za-z0-9]+\\)+[_A-Za-z0-9]+
RGX_IDENTIFIER [_A-Za-z][_A-Za-z0-9]*
RGX_STRING \"(?:\\.|[^\"])*?\"|\'(?:\\.|[^\'])*?\'
RGX_COLOR #([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
RGX_COLOR_S #[0-9a-fA-F]{3}
RGX_COLOR_L #[0-9a-fA-F]{6}
RGX_FLT_DEC [0-9]+\.(?:[0-9]*)?f?|\.[0-9]+f?
RGX_INT_OCT 0[1-7][0-7]*
RGX_INT_BIN 0[bB][01]+
@ -152,16 +153,17 @@ RGX_DEFAULT (.|\n)
\| { return iw7::parser::make_BITWISE_OR(ctx->loc); }
\& { return iw7::parser::make_BITWISE_AND(ctx->loc); }
\^ { return iw7::parser::make_BITWISE_EXOR(ctx->loc); }
{RGX_PATH} { return iw7::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
{RGX_IDENTIFIER} { return iw7::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
\&{RGX_STRING} { return iw7::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
{RGX_PATH} { return iw7::parser::make_PATH(xsk::gsc::iw7::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
{RGX_IDENTIFIER} { return iw7::parser::make_IDENTIFIER(xsk::gsc::iw7::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
\&{RGX_STRING} { return iw7::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_STRING} { return iw7::parser::make_STRING(std::string(yytext), ctx->loc); }
{RGX_COLOR} { return iw7::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
{RGX_COLOR_S} { return iw7::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_COLOR_L} { return iw7::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_FLT_DEC} { return iw7::parser::make_FLOAT(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return iw7::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return iw7::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return iw7::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return iw7::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return iw7::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return iw7::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return iw7::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return iw7::parser::make_INTEGER(std::string(yytext), ctx->loc); }
<<EOF>> { if(ctx->header_top > 0) iw7_pop_header(ctx); else return iw7::parser::make_IW7EOF(ctx->loc); }
<*>{RGX_DEFAULT} { throw iw7::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
@ -169,60 +171,60 @@ RGX_DEFAULT (.|\n)
void iw7_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -230,8 +232,8 @@ void iw7_push_header(xsk::gsc::context* ctx, const std::string& file)
void iw7_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -136,10 +136,7 @@ xsk::gsc::iw7::parser::symbol_type IW7lex(yyscan_t yyscanner, xsk::gsc::context*
%token <std::string> ISTRING "localized string"
%token <std::string> COLOR "color"
%token <std::string> FLOAT "float"
%token <std::string> INT_DEC "int"
%token <std::string> INT_OCT "octal int"
%token <std::string> INT_BIN "binary int"
%token <std::string> INT_HEX "hexadecimal int"
%token <std::string> INTEGER "integer"
%type <ast::program::ptr> program
%type <ast::include::ptr> include
@ -458,7 +455,7 @@ stmt_default
;
stmt_break
: BREAK SEMICOLON
: BREAK SEMICOLON
{ $$ = std::make_unique<ast::stmt_break>(@$); }
;
@ -811,15 +808,9 @@ expr_float
;
expr_integer
: SUB INT_DEC %prec NEG
: SUB INTEGER %prec NEG
{ $$ = std::make_unique<ast::expr_integer>(@$, "-" + $2); };
| INT_DEC
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_OCT
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_BIN
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_HEX
| INTEGER
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
;

View File

@ -28,7 +28,8 @@ void iw8_pop_header(xsk::gsc::context* ctx);
RGX_PATH ([_A-Za-z0-9]+\\)+[_A-Za-z0-9]+
RGX_IDENTIFIER [_A-Za-z][_A-Za-z0-9]*
RGX_STRING \"(?:\\.|[^\"])*?\"|\'(?:\\.|[^\'])*?\'
RGX_COLOR #([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
RGX_COLOR_S #[0-9a-fA-F]{3}
RGX_COLOR_L #[0-9a-fA-F]{6}
RGX_FLT_DEC [0-9]+\.(?:[0-9]*)?f?|\.[0-9]+f?
RGX_INT_OCT 0[1-7][0-7]*
RGX_INT_BIN 0[bB][01]+
@ -108,8 +109,8 @@ RGX_DEFAULT (.|\n)
"self" { return iw8::parser::make_SELF(ctx->loc); }
"anim" { return iw8::parser::make_ANIM(ctx->loc); }
"level" { return iw8::parser::make_LEVEL(ctx->loc); }
(?i:isdefined) { return iw8::parser::make_ISDEFINED(ctx->loc); }
(?i:istrue) { return iw8::parser::make_ISTRUE(ctx->loc); }
(?i:isdefined) { return iw8::parser::make_ISDEFINED(ctx->loc); }
(?i:istrue) { return iw8::parser::make_ISTRUE(ctx->loc); }
\( { return iw8::parser::make_LPAREN(ctx->loc); }
\) { return iw8::parser::make_RPAREN(ctx->loc); }
\{ { return iw8::parser::make_LBRACE(ctx->loc); }
@ -155,16 +156,17 @@ RGX_DEFAULT (.|\n)
\| { return iw8::parser::make_BITWISE_OR(ctx->loc); }
\& { return iw8::parser::make_BITWISE_AND(ctx->loc); }
\^ { return iw8::parser::make_BITWISE_EXOR(ctx->loc); }
{RGX_PATH} { return iw8::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
{RGX_IDENTIFIER} { return iw8::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
\&{RGX_STRING} { return iw8::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
{RGX_PATH} { return iw8::parser::make_PATH(xsk::gsc::iw8::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
{RGX_IDENTIFIER} { return iw8::parser::make_IDENTIFIER(xsk::gsc::iw8::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
\&{RGX_STRING} { return iw8::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_STRING} { return iw8::parser::make_STRING(std::string(yytext), ctx->loc); }
{RGX_COLOR} { return iw8::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
{RGX_COLOR_S} { return iw8::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_COLOR_L} { return iw8::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_FLT_DEC} { return iw8::parser::make_FLOAT(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return iw8::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return iw8::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return iw8::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return iw8::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return iw8::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return iw8::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return iw8::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return iw8::parser::make_INTEGER(std::string(yytext), ctx->loc); }
<<EOF>> { if(ctx->header_top > 0) iw8_pop_header(ctx); else return iw8::parser::make_IW8EOF(ctx->loc); }
<*>{RGX_DEFAULT} { throw iw8::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
@ -172,60 +174,60 @@ RGX_DEFAULT (.|\n)
void iw8_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -233,8 +235,8 @@ void iw8_push_header(xsk::gsc::context* ctx, const std::string& file)
void iw8_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -139,10 +139,7 @@ xsk::gsc::iw8::parser::symbol_type IW8lex(yyscan_t yyscanner, xsk::gsc::context*
%token <std::string> ISTRING "localized string"
%token <std::string> COLOR "color"
%token <std::string> FLOAT "float"
%token <std::string> INT_DEC "int"
%token <std::string> INT_OCT "octal int"
%token <std::string> INT_BIN "binary int"
%token <std::string> INT_HEX "hexadecimal int"
%token <std::string> INTEGER "integer"
%type <ast::program::ptr> program
%type <ast::include::ptr> include
@ -472,7 +469,7 @@ stmt_default
;
stmt_break
: BREAK SEMICOLON
: BREAK SEMICOLON
{ $$ = std::make_unique<ast::stmt_break>(@$); }
;
@ -837,15 +834,9 @@ expr_float
;
expr_integer
: SUB INT_DEC %prec NEG
: SUB INTEGER %prec NEG
{ $$ = std::make_unique<ast::expr_integer>(@$, "-" + $2); };
| INT_DEC
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_OCT
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_BIN
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_HEX
| INTEGER
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
;

View File

@ -28,7 +28,8 @@ void s1_pop_header(xsk::gsc::context* ctx);
RGX_PATH ([_A-Za-z0-9]+\\)+[_A-Za-z0-9]+
RGX_IDENTIFIER [_A-Za-z][_A-Za-z0-9]*
RGX_STRING \"(?:\\.|[^\"])*?\"|\'(?:\\.|[^\'])*?\'
RGX_COLOR #([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
RGX_COLOR_S #[0-9a-fA-F]{3}
RGX_COLOR_L #[0-9a-fA-F]{6}
RGX_FLT_DEC [0-9]+\.(?:[0-9]*)?f?|\.[0-9]+f?
RGX_INT_OCT 0[1-7][0-7]*
RGX_INT_BIN 0[bB][01]+
@ -153,16 +154,17 @@ RGX_DEFAULT (.|\n)
\| { return s1::parser::make_BITWISE_OR(ctx->loc); }
\& { return s1::parser::make_BITWISE_AND(ctx->loc); }
\^ { return s1::parser::make_BITWISE_EXOR(ctx->loc); }
{RGX_PATH} { return s1::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
{RGX_IDENTIFIER} { return s1::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
\&{RGX_STRING} { return s1::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
{RGX_PATH} { return s1::parser::make_PATH(xsk::gsc::s1::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
{RGX_IDENTIFIER} { return s1::parser::make_IDENTIFIER(xsk::gsc::s1::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
\&{RGX_STRING} { return s1::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_STRING} { return s1::parser::make_STRING(std::string(yytext), ctx->loc); }
{RGX_COLOR} { return s1::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
{RGX_COLOR_S} { return s1::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_COLOR_L} { return s1::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_FLT_DEC} { return s1::parser::make_FLOAT(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return s1::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return s1::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return s1::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return s1::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return s1::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return s1::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return s1::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return s1::parser::make_INTEGER(std::string(yytext), ctx->loc); }
<<EOF>> { if(ctx->header_top > 0) s1_pop_header(ctx); else return s1::parser::make_S1EOF(ctx->loc); }
<*>{RGX_DEFAULT} { throw s1::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
@ -170,60 +172,60 @@ RGX_DEFAULT (.|\n)
void s1_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -231,8 +233,8 @@ void s1_push_header(xsk::gsc::context* ctx, const std::string& file)
void s1_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -137,10 +137,7 @@ xsk::gsc::s1::parser::symbol_type S1lex(yyscan_t yyscanner, xsk::gsc::context* c
%token <std::string> ISTRING "localized string"
%token <std::string> COLOR "color"
%token <std::string> FLOAT "float"
%token <std::string> INT_DEC "int"
%token <std::string> INT_OCT "octal int"
%token <std::string> INT_BIN "binary int"
%token <std::string> INT_HEX "hexadecimal int"
%token <std::string> INTEGER "integer"
%type <ast::program::ptr> program
%type <ast::include::ptr> include
@ -468,7 +465,7 @@ stmt_default
;
stmt_break
: BREAK SEMICOLON
: BREAK SEMICOLON
{ $$ = std::make_unique<ast::stmt_break>(@$); }
;
@ -821,15 +818,9 @@ expr_float
;
expr_integer
: SUB INT_DEC %prec NEG
: SUB INTEGER %prec NEG
{ $$ = std::make_unique<ast::expr_integer>(@$, "-" + $2); };
| INT_DEC
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_OCT
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_BIN
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_HEX
| INTEGER
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
;

View File

@ -28,7 +28,8 @@ void s2_pop_header(xsk::gsc::context* ctx);
RGX_PATH ([_A-Za-z0-9]+\\)+[_A-Za-z0-9]+
RGX_IDENTIFIER [_A-Za-z][_A-Za-z0-9]*
RGX_STRING \"(?:\\.|[^\"])*?\"|\'(?:\\.|[^\'])*?\'
RGX_COLOR #([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
RGX_COLOR_S #[0-9a-fA-F]{3}
RGX_COLOR_L #[0-9a-fA-F]{6}
RGX_FLT_DEC [0-9]+\.(?:[0-9]*)?f?|\.[0-9]+f?
RGX_INT_OCT 0[1-7][0-7]*
RGX_INT_BIN 0[bB][01]+
@ -153,16 +154,17 @@ RGX_DEFAULT (.|\n)
\| { return s2::parser::make_BITWISE_OR(ctx->loc); }
\& { return s2::parser::make_BITWISE_AND(ctx->loc); }
\^ { return s2::parser::make_BITWISE_EXOR(ctx->loc); }
{RGX_PATH} { return s2::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
{RGX_IDENTIFIER} { return s2::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
\&{RGX_STRING} { return s2::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
{RGX_PATH} { return s2::parser::make_PATH(xsk::gsc::s2::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
{RGX_IDENTIFIER} { return s2::parser::make_IDENTIFIER(xsk::gsc::s2::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
\&{RGX_STRING} { return s2::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_STRING} { return s2::parser::make_STRING(std::string(yytext), ctx->loc); }
{RGX_COLOR} { return s2::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
{RGX_COLOR_S} { return s2::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_COLOR_L} { return s2::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_FLT_DEC} { return s2::parser::make_FLOAT(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return s2::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return s2::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return s2::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return s2::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return s2::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return s2::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return s2::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return s2::parser::make_INTEGER(std::string(yytext), ctx->loc); }
<<EOF>> { if(ctx->header_top > 0) s2_pop_header(ctx); else return s2::parser::make_S2EOF(ctx->loc); }
<*>{RGX_DEFAULT} { throw s2::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
@ -170,60 +172,60 @@ RGX_DEFAULT (.|\n)
void s2_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -231,8 +233,8 @@ void s2_push_header(xsk::gsc::context* ctx, const std::string& file)
void s2_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -137,10 +137,7 @@ xsk::gsc::s2::parser::symbol_type S2lex(yyscan_t yyscanner, xsk::gsc::context* c
%token <std::string> ISTRING "localized string"
%token <std::string> COLOR "color"
%token <std::string> FLOAT "float"
%token <std::string> INT_DEC "int"
%token <std::string> INT_OCT "octal int"
%token <std::string> INT_BIN "binary int"
%token <std::string> INT_HEX "hexadecimal int"
%token <std::string> INTEGER "integer"
%type <ast::program::ptr> program
%type <ast::include::ptr> include
@ -468,7 +465,7 @@ stmt_default
;
stmt_break
: BREAK SEMICOLON
: BREAK SEMICOLON
{ $$ = std::make_unique<ast::stmt_break>(@$); }
;
@ -821,15 +818,9 @@ expr_float
;
expr_integer
: SUB INT_DEC %prec NEG
: SUB INTEGER %prec NEG
{ $$ = std::make_unique<ast::expr_integer>(@$, "-" + $2); };
| INT_DEC
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_OCT
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_BIN
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_HEX
| INTEGER
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
;

View File

@ -28,7 +28,8 @@ void s4_pop_header(xsk::gsc::context* ctx);
RGX_PATH ([_A-Za-z0-9]+\\)+[_A-Za-z0-9]+
RGX_IDENTIFIER [_A-Za-z][_A-Za-z0-9]*
RGX_STRING \"(?:\\.|[^\"])*?\"|\'(?:\\.|[^\'])*?\'
RGX_COLOR #([0-9a-fA-F]{6}|[0-9a-fA-F]{3})
RGX_COLOR_S #[0-9a-fA-F]{3}
RGX_COLOR_L #[0-9a-fA-F]{6}
RGX_FLT_DEC [0-9]+\.(?:[0-9]*)?f?|\.[0-9]+f?
RGX_INT_OCT 0[1-7][0-7]*
RGX_INT_BIN 0[bB][01]+
@ -108,8 +109,8 @@ RGX_DEFAULT (.|\n)
"self" { return s4::parser::make_SELF(ctx->loc); }
"anim" { return s4::parser::make_ANIM(ctx->loc); }
"level" { return s4::parser::make_LEVEL(ctx->loc); }
(?i:isdefined) { return s4::parser::make_ISDEFINED(ctx->loc); }
(?i:istrue) { return s4::parser::make_ISTRUE(ctx->loc); }
(?i:isdefined) { return s4::parser::make_ISDEFINED(ctx->loc); }
(?i:istrue) { return s4::parser::make_ISTRUE(ctx->loc); }
\( { return s4::parser::make_LPAREN(ctx->loc); }
\) { return s4::parser::make_RPAREN(ctx->loc); }
\{ { return s4::parser::make_LBRACE(ctx->loc); }
@ -155,16 +156,17 @@ RGX_DEFAULT (.|\n)
\| { return s4::parser::make_BITWISE_OR(ctx->loc); }
\& { return s4::parser::make_BITWISE_AND(ctx->loc); }
\^ { return s4::parser::make_BITWISE_EXOR(ctx->loc); }
{RGX_PATH} { return s4::parser::make_PATH(xsk::utils::string::fordslash(yytext), ctx->loc); }
{RGX_IDENTIFIER} { return s4::parser::make_IDENTIFIER((std::string(yytext, 3) == "_ID") ? std::string(yytext) : xsk::utils::string::to_lower(yytext), ctx->loc); }
\&{RGX_STRING} { return s4::parser::make_ISTRING(std::string(yytext).substr(1), ctx->loc); }
{RGX_PATH} { return s4::parser::make_PATH(xsk::gsc::s4::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
{RGX_IDENTIFIER} { return s4::parser::make_IDENTIFIER(xsk::gsc::s4::resolver::make_token(std::string_view(yytext, yyleng)), ctx->loc); }
\&{RGX_STRING} { return s4::parser::make_ISTRING(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_STRING} { return s4::parser::make_STRING(std::string(yytext), ctx->loc); }
{RGX_COLOR} { return s4::parser::make_COLOR(std::string(yytext).substr(1), ctx->loc); }
{RGX_COLOR_S} { return s4::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_COLOR_L} { return s4::parser::make_COLOR(std::string(++yytext, --yyleng), ctx->loc); }
{RGX_FLT_DEC} { return s4::parser::make_FLOAT(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return s4::parser::make_INT_OCT(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return s4::parser::make_INT_BIN(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return s4::parser::make_INT_HEX(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return s4::parser::make_INT_DEC(std::string(yytext), ctx->loc); }
{RGX_INT_OCT} { return s4::parser::make_INTEGER(xsk::utils::string::oct_to_dec(yytext), ctx->loc); }
{RGX_INT_BIN} { return s4::parser::make_INTEGER(xsk::utils::string::bin_to_dec(yytext), ctx->loc); }
{RGX_INT_HEX} { return s4::parser::make_INTEGER(xsk::utils::string::hex_to_dec(yytext), ctx->loc); }
{RGX_INT_DEC} { return s4::parser::make_INTEGER(std::string(yytext), ctx->loc); }
<<EOF>> { if(ctx->header_top > 0) s4_pop_header(ctx); else return s4::parser::make_S4EOF(ctx->loc); }
<*>{RGX_DEFAULT} { throw s4::parser::syntax_error(ctx->loc, "bad token: \'" + std::string(yytext) + "\'"); }
@ -172,60 +174,60 @@ RGX_DEFAULT (.|\n)
void s4_push_header(xsk::gsc::context* ctx, const std::string& file)
{
try
try
{
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
if (ctx->header_top >= 4)
{
throw xsk::gsc::error("maximum gsh depth exceeded '4'");
}
ctx->header_top++;
ctx->header_top++;
char* buf_data = 0;
size_t buf_size = 0;
char* buf_data = 0;
size_t buf_size = 0;
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
for (auto& src : *ctx->sources)
{
if (src.name == file)
{
buf_data = reinterpret_cast<char*>(src.buf.data());
buf_size = src.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&src.name);
}
}
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
if (buf_data == 0)
{
ctx->sources->push_back(xsk::gsc::source());
auto& source = ctx->sources->back();
source.name = file;
source.buf = ctx->read_callback(file + ".gsh");
source.buf.push_back(0);
source.buf.push_back(0);
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
buf_data = reinterpret_cast<char*>(source.buf.data());
buf_size = source.buf.size();
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
ctx->locs.push(ctx->loc);
ctx->loc.initialize(&source.name);
}
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
auto state = new yy_buffer_state();
state->yy_buf_size = buf_size - 2;
state->yy_buf_pos = state->yy_ch_buf = buf_data;
state->yy_is_our_buffer = 0;
state->yy_input_file = NULL;
state->yy_n_chars = state->yy_buf_size;
state->yy_is_interactive = 0;
state->yy_at_bol = 1;
state->yy_fill_buffer = 0;
state->yy_buffer_status = 0;
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
yypush_buffer_state(state, ctx->scanner);
}
catch (const std::exception& e)
{
throw xsk::gsc::error("parsing header file '" + file + "': " + e.what());
}
@ -233,8 +235,8 @@ void s4_push_header(xsk::gsc::context* ctx, const std::string& file)
void s4_pop_header(xsk::gsc::context* ctx)
{
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
ctx->header_top--;
ctx->loc = ctx->locs.top();
ctx->locs.pop();
yypop_buffer_state(ctx->scanner);
}

View File

@ -139,10 +139,7 @@ xsk::gsc::s4::parser::symbol_type S4lex(yyscan_t yyscanner, xsk::gsc::context* c
%token <std::string> ISTRING "localized string"
%token <std::string> COLOR "color"
%token <std::string> FLOAT "float"
%token <std::string> INT_DEC "int"
%token <std::string> INT_OCT "octal int"
%token <std::string> INT_BIN "binary int"
%token <std::string> INT_HEX "hexadecimal int"
%token <std::string> INTEGER "integer"
%type <ast::program::ptr> program
%type <ast::include::ptr> include
@ -472,7 +469,7 @@ stmt_default
;
stmt_break
: BREAK SEMICOLON
: BREAK SEMICOLON
{ $$ = std::make_unique<ast::stmt_break>(@$); }
;
@ -837,15 +834,9 @@ expr_float
;
expr_integer
: SUB INT_DEC %prec NEG
: SUB INTEGER %prec NEG
{ $$ = std::make_unique<ast::expr_integer>(@$, "-" + $2); };
| INT_DEC
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_OCT
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_BIN
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
| INT_HEX
| INTEGER
{ $$ = std::make_unique<ast::expr_integer>(@$, $1); };
;