enhance developer mode

This commit is contained in:
xensik
2021-12-31 15:22:21 +01:00
parent 454d3e23fb
commit 9dbdd37f15
65 changed files with 21605 additions and 20013 deletions

View File

@ -36,9 +36,9 @@ RGX_INT_HEX 0[xX][0-9a-fA-F]+
RGX_INT_DEC [0-9]+
RGX_DEFAULT (.|\n)
%x COMMENT_BLOCK_STATE
%s DEVBLOCK_ON_STATE
%x DEVBLOCK_OFF_STATE
%x COMMENT_STATE
%x DEV_OFF_STATE
%s DEV_ON_STATE
%%
@ -46,24 +46,28 @@ RGX_DEFAULT (.|\n)
ctx->loc.step();
%}
[ \t\r] { ctx->loc.step(); }
\n { ctx->loc.lines(yyleng); ctx->loc.step(); }
[ \t\r] { ctx->loc.step(); }
\n { ctx->loc.lines(yyleng); ctx->loc.step(); }
"//".*
"/*" { BEGIN(COMMENT_BLOCK_STATE); }
<COMMENT_BLOCK_STATE>.
<COMMENT_BLOCK_STATE>\n { ctx->loc.lines(yyleng); ctx->loc.step(); }
<COMMENT_BLOCK_STATE>"*/" { BEGIN(INITIAL); }
"/*" { BEGIN(COMMENT_STATE); }
<COMMENT_STATE>.
<COMMENT_STATE>\n { ctx->loc.lines(yyleng); ctx->loc.step(); }
<COMMENT_STATE>"*/" { BEGIN(INITIAL); }
<COMMENT_STATE><<EOF>> { throw s2::parser::syntax_error(ctx->loc, "unmatched multiline comment start ('/*')"); }
<INITIAL>"*/" { throw s2::parser::syntax_error(ctx->loc, "unmatched multiline comment end ('*/')"); }
"/#" { BEGIN(ctx->mode == xsk::gsc::build::dev ? DEVBLOCK_ON_STATE : DEVBLOCK_OFF_STATE); }
<DEVBLOCK_OFF_STATE>.
<DEVBLOCK_OFF_STATE>\n { ctx->loc.lines(yyleng); ctx->loc.step(); }
<DEVBLOCK_OFF_STATE,DEVBLOCK_ON_STATE>"#/" { BEGIN(INITIAL); }
<DEV_ON_STATE>"/#" { throw s2::parser::syntax_error(ctx->loc, "cannot recurse devblock ('/#')"); }
<DEV_ON_STATE>"#/" { BEGIN(INITIAL); return s2::parser::make_DEVEND(ctx->loc); }
<DEV_ON_STATE><<EOF>> { throw s2::parser::syntax_error(ctx->loc, "unmatched devblock start ('/#')"); }
<INITIAL>"*/" { throw s2::parser::syntax_error(ctx->loc, "unmatched multiline comment end ('*/')"); }
<INITIAL>"#/" { throw s2::parser::syntax_error(ctx->loc, "unmatched devblock end ('#/')"); }
"/#" { BEGIN(ctx->mode == xsk::gsc::build::dev ? DEV_ON_STATE : DEV_OFF_STATE); if(ctx->mode == xsk::gsc::build::dev) return s2::parser::make_DEVBEGIN(ctx->loc); }
<DEV_OFF_STATE>.
<DEV_OFF_STATE>\n { ctx->loc.lines(yyleng); ctx->loc.step(); }
<DEV_OFF_STATE>"#/" { BEGIN(INITIAL); }
<DEV_OFF_STATE><<EOF>> { throw s2::parser::syntax_error(ctx->loc, "unmatched devblock start ('/#')"); }
<INITIAL>"#/" { throw s2::parser::syntax_error(ctx->loc, "unmatched devblock end ('#/')"); }
"#inline" { return s2::parser::make_INLINE(ctx->loc); }
"#include" { return s2::parser::make_INCLUDE(ctx->loc); }

View File

@ -45,6 +45,8 @@ using namespace xsk::gsc;
xsk::gsc::s2::parser::symbol_type S2lex(yyscan_t yyscanner, xsk::gsc::context* ctx);
}
%token DEVBEGIN "/#"
%token DEVEND "#/"
%token INLINE "#inline"
%token INCLUDE "#include"
%token USINGTREE "#using_animtree"
@ -147,6 +149,7 @@ xsk::gsc::s2::parser::symbol_type S2lex(yyscan_t yyscanner, xsk::gsc::context* c
%type <ast::decl_constant::ptr> decl_constant
%type <ast::decl_thread::ptr> decl_thread
%type <ast::stmt> stmt
%type <ast::stmt_list::ptr> stmt_dev
%type <ast::stmt_list::ptr> stmt_block
%type <ast::stmt_list::ptr> stmt_list
%type <ast::stmt_expr::ptr> stmt_expr
@ -277,7 +280,9 @@ include
;
declaration
: decl_usingtree { $$.as_usingtree = std::move($1); }
: DEVBEGIN { $$.as_dev_begin = std::make_unique<ast::decl_dev_begin>(@$); }
| DEVEND { $$.as_dev_end = std::make_unique<ast::decl_dev_end>(@$); }
| decl_usingtree { $$.as_usingtree = std::move($1); }
| decl_constant { $$.as_constant = std::move($1); }
| decl_thread { $$.as_thread = std::move($1); }
;
@ -298,7 +303,8 @@ decl_thread
;
stmt
: stmt_block { $$.as_list = std::move($1); }
: stmt_dev { $$.as_list = std::move($1); }
| stmt_block { $$.as_list = std::move($1); }
| stmt_call { $$.as_call = std::move($1); }
| stmt_assign { $$.as_assign = std::move($1); }
| stmt_endon { $$.as_endon = std::move($1); }
@ -325,6 +331,11 @@ stmt
| stmt_prof_end { $$.as_prof_end = std::move($1); }
;
stmt_dev
: DEVBEGIN stmt_list DEVEND { $$ = std::move($2); }
| DEVBEGIN DEVEND { $$ = std::make_unique<ast::stmt_list>(@$); }
;
stmt_block
: LBRACE stmt_list RBRACE { $$ = std::move($2); }
| LBRACE RBRACE { $$ = std::make_unique<ast::stmt_list>(@$); }