Use midrule action values for captures' terminated status

Bison 3.1 introduces "typed midrule values", which would write
`<captureTerminated>{ ... }` and `$$` instead of `{ ... }` and
`$<captureTerminated>[1-9]`, but rgbds supports 3.0 or even lower.
This commit is contained in:
Rangi
2021-04-19 09:23:12 -04:00
committed by Eldred Habert
parent 7ac8bd6e24
commit 7a587eb7d6
3 changed files with 19 additions and 17 deletions

View File

@@ -81,7 +81,6 @@ struct CaptureBody {
uint32_t lineNo; uint32_t lineNo;
char *body; char *body;
size_t size; size_t size;
bool unterminated;
}; };
char const *lexer_GetFileName(void); char const *lexer_GetFileName(void);
@@ -89,8 +88,8 @@ uint32_t lexer_GetLineNo(void);
uint32_t lexer_GetColNo(void); uint32_t lexer_GetColNo(void);
void lexer_DumpStringExpansions(void); void lexer_DumpStringExpansions(void);
int yylex(void); int yylex(void);
void lexer_CaptureRept(struct CaptureBody *capture); bool lexer_CaptureRept(struct CaptureBody *capture);
void lexer_CaptureMacroBody(struct CaptureBody *capture); bool lexer_CaptureMacroBody(struct CaptureBody *capture);
#define INITIAL_DS_ARG_SIZE 2 #define INITIAL_DS_ARG_SIZE 2
struct DsArgList { struct DsArgList {

View File

@@ -2336,12 +2336,12 @@ static char *startCapture(void)
} }
} }
void lexer_CaptureRept(struct CaptureBody *capture) bool lexer_CaptureRept(struct CaptureBody *capture)
{ {
capture->unterminated = false;
capture->lineNo = lexer_GetLineNo(); capture->lineNo = lexer_GetLineNo();
char *captureStart = startCapture(); char *captureStart = startCapture();
bool terminated = false;
unsigned int level = 0; unsigned int level = 0;
int c; int c;
@@ -2373,6 +2373,7 @@ void lexer_CaptureRept(struct CaptureBody *capture)
* We know we have read exactly "ENDR", not e.g. an EQUS * We know we have read exactly "ENDR", not e.g. an EQUS
*/ */
lexerState->captureSize -= strlen("ENDR"); lexerState->captureSize -= strlen("ENDR");
terminated = true;
goto finish; goto finish;
} }
level--; level--;
@@ -2383,7 +2384,6 @@ void lexer_CaptureRept(struct CaptureBody *capture)
for (;;) { for (;;) {
if (c == EOF) { if (c == EOF) {
error("Unterminated REPT/FOR block\n"); error("Unterminated REPT/FOR block\n");
capture->unterminated = true;
goto finish; goto finish;
} else if (c == '\n' || c == '\r') { } else if (c == '\n' || c == '\r') {
handleCRLF(c); handleCRLF(c);
@@ -2401,14 +2401,15 @@ finish:
lexerState->disableMacroArgs = false; lexerState->disableMacroArgs = false;
lexerState->disableInterpolation = false; lexerState->disableInterpolation = false;
lexerState->atLineStart = false; lexerState->atLineStart = false;
return terminated;
} }
void lexer_CaptureMacroBody(struct CaptureBody *capture) bool lexer_CaptureMacroBody(struct CaptureBody *capture)
{ {
capture->unterminated = false;
capture->lineNo = lexer_GetLineNo(); capture->lineNo = lexer_GetLineNo();
char *captureStart = startCapture(); char *captureStart = startCapture();
bool terminated = false;
int c; int c;
/* If the file is `mmap`ed, we need not to unmap it to keep access to the macro */ /* If the file is `mmap`ed, we need not to unmap it to keep access to the macro */
@@ -2436,6 +2437,7 @@ void lexer_CaptureMacroBody(struct CaptureBody *capture)
* We know we have read exactly "ENDM", not e.g. an EQUS * We know we have read exactly "ENDM", not e.g. an EQUS
*/ */
lexerState->captureSize -= strlen("ENDM"); lexerState->captureSize -= strlen("ENDM");
terminated = true;
goto finish; goto finish;
} }
} }
@@ -2444,7 +2446,6 @@ void lexer_CaptureMacroBody(struct CaptureBody *capture)
for (;;) { for (;;) {
if (c == EOF) { if (c == EOF) {
error("Unterminated macro definition\n"); error("Unterminated macro definition\n");
capture->unterminated = true;
goto finish; goto finish;
} else if (c == '\n' || c == '\r') { } else if (c == '\n' || c == '\r') {
handleCRLF(c); handleCRLF(c);
@@ -2462,4 +2463,5 @@ finish:
lexerState->disableMacroArgs = false; lexerState->disableMacroArgs = false;
lexerState->disableInterpolation = false; lexerState->disableInterpolation = false;
lexerState->atLineStart = false; lexerState->atLineStart = false;
return terminated;
} }

View File

@@ -463,6 +463,7 @@ enum {
int32_t step; int32_t step;
} forArgs; } forArgs;
struct StrFmtArgList strfmtArgs; struct StrFmtArgList strfmtArgs;
bool captureTerminated;
} }
%type <expr> relocexpr %type <expr> relocexpr
@@ -987,9 +988,9 @@ load : T_POP_LOAD sectmod string T_COMMA sectiontype sectorg sectattrs {
; ;
rept : T_POP_REPT uconst T_NEWLINE { rept : T_POP_REPT uconst T_NEWLINE {
lexer_CaptureRept(&captureBody); $<captureTerminated>$ = lexer_CaptureRept(&captureBody);
} endofline { } endofline {
if (!captureBody.unterminated) if ($<captureTerminated>4)
fstk_RunRept($2, captureBody.lineNo, captureBody.body, fstk_RunRept($2, captureBody.lineNo, captureBody.body,
captureBody.size); captureBody.size);
} }
@@ -1000,9 +1001,9 @@ for : T_POP_FOR {
} T_ID { } T_ID {
lexer_ToggleStringExpansion(true); lexer_ToggleStringExpansion(true);
} T_COMMA for_args T_NEWLINE { } T_COMMA for_args T_NEWLINE {
lexer_CaptureRept(&captureBody); $<captureTerminated>$ = lexer_CaptureRept(&captureBody);
} endofline { } endofline {
if (!captureBody.unterminated) if ($<captureTerminated>8)
fstk_RunFor($3, $6.start, $6.stop, $6.step, captureBody.lineNo, fstk_RunFor($3, $6.start, $6.stop, $6.step, captureBody.lineNo,
captureBody.body, captureBody.size); captureBody.body, captureBody.size);
} }
@@ -1035,16 +1036,16 @@ macrodef : T_POP_MACRO {
} T_ID { } T_ID {
lexer_ToggleStringExpansion(true); lexer_ToggleStringExpansion(true);
} T_NEWLINE { } T_NEWLINE {
lexer_CaptureMacroBody(&captureBody); $<captureTerminated>$ = lexer_CaptureMacroBody(&captureBody);
} endofline { } endofline {
if (!captureBody.unterminated) if ($<captureTerminated>6)
sym_AddMacro($3, captureBody.lineNo, captureBody.body, sym_AddMacro($3, captureBody.lineNo, captureBody.body,
captureBody.size); captureBody.size);
} }
| T_LABEL T_COLON T_POP_MACRO T_NEWLINE { | T_LABEL T_COLON T_POP_MACRO T_NEWLINE {
lexer_CaptureMacroBody(&captureBody); $<captureTerminated>$ = lexer_CaptureMacroBody(&captureBody);
} endofline { } endofline {
if (!captureBody.unterminated) if ($<captureTerminated>5)
sym_AddMacro($1, captureBody.lineNo, captureBody.body, sym_AddMacro($1, captureBody.lineNo, captureBody.body,
captureBody.size); captureBody.size);
} }