diff --git a/include/asm/lexer.h b/include/asm/lexer.h index 84b8e259..706e92e9 100644 --- a/include/asm/lexer.h +++ b/include/asm/lexer.h @@ -81,7 +81,6 @@ struct CaptureBody { uint32_t lineNo; char *body; size_t size; - bool unterminated; }; char const *lexer_GetFileName(void); @@ -89,8 +88,8 @@ uint32_t lexer_GetLineNo(void); uint32_t lexer_GetColNo(void); void lexer_DumpStringExpansions(void); int yylex(void); -void lexer_CaptureRept(struct CaptureBody *capture); -void lexer_CaptureMacroBody(struct CaptureBody *capture); +bool lexer_CaptureRept(struct CaptureBody *capture); +bool lexer_CaptureMacroBody(struct CaptureBody *capture); #define INITIAL_DS_ARG_SIZE 2 struct DsArgList { diff --git a/src/asm/lexer.c b/src/asm/lexer.c index f8230bef..fe364cda 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -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(); char *captureStart = startCapture(); + bool terminated = false; unsigned int level = 0; int c; @@ -2373,6 +2373,7 @@ void lexer_CaptureRept(struct CaptureBody *capture) * We know we have read exactly "ENDR", not e.g. an EQUS */ lexerState->captureSize -= strlen("ENDR"); + terminated = true; goto finish; } level--; @@ -2383,7 +2384,6 @@ void lexer_CaptureRept(struct CaptureBody *capture) for (;;) { if (c == EOF) { error("Unterminated REPT/FOR block\n"); - capture->unterminated = true; goto finish; } else if (c == '\n' || c == '\r') { handleCRLF(c); @@ -2401,14 +2401,15 @@ finish: lexerState->disableMacroArgs = false; lexerState->disableInterpolation = 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(); char *captureStart = startCapture(); + bool terminated = false; int c; /* 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 */ lexerState->captureSize -= strlen("ENDM"); + terminated = true; goto finish; } } @@ -2444,7 +2446,6 @@ void lexer_CaptureMacroBody(struct CaptureBody *capture) for (;;) { if (c == EOF) { error("Unterminated macro definition\n"); - capture->unterminated = true; goto finish; } else if (c == '\n' || c == '\r') { handleCRLF(c); @@ -2462,4 +2463,5 @@ finish: lexerState->disableMacroArgs = false; lexerState->disableInterpolation = false; lexerState->atLineStart = false; + return terminated; } diff --git a/src/asm/parser.y b/src/asm/parser.y index c919ae8b..b96bce48 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -463,6 +463,7 @@ enum { int32_t step; } forArgs; struct StrFmtArgList strfmtArgs; + bool captureTerminated; } %type relocexpr @@ -987,9 +988,9 @@ load : T_POP_LOAD sectmod string T_COMMA sectiontype sectorg sectattrs { ; rept : T_POP_REPT uconst T_NEWLINE { - lexer_CaptureRept(&captureBody); + $$ = lexer_CaptureRept(&captureBody); } endofline { - if (!captureBody.unterminated) + if ($4) fstk_RunRept($2, captureBody.lineNo, captureBody.body, captureBody.size); } @@ -1000,9 +1001,9 @@ for : T_POP_FOR { } T_ID { lexer_ToggleStringExpansion(true); } T_COMMA for_args T_NEWLINE { - lexer_CaptureRept(&captureBody); + $$ = lexer_CaptureRept(&captureBody); } endofline { - if (!captureBody.unterminated) + if ($8) fstk_RunFor($3, $6.start, $6.stop, $6.step, captureBody.lineNo, captureBody.body, captureBody.size); } @@ -1035,16 +1036,16 @@ macrodef : T_POP_MACRO { } T_ID { lexer_ToggleStringExpansion(true); } T_NEWLINE { - lexer_CaptureMacroBody(&captureBody); + $$ = lexer_CaptureMacroBody(&captureBody); } endofline { - if (!captureBody.unterminated) + if ($6) sym_AddMacro($3, captureBody.lineNo, captureBody.body, captureBody.size); } | T_LABEL T_COLON T_POP_MACRO T_NEWLINE { - lexer_CaptureMacroBody(&captureBody); + $$ = lexer_CaptureMacroBody(&captureBody); } endofline { - if (!captureBody.unterminated) + if ($5) sym_AddMacro($1, captureBody.lineNo, captureBody.body, captureBody.size); }