added line-break escaping
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-18 22:55:50 +08:00
parent b3f363c94f
commit f01c499832
7 changed files with 36 additions and 12 deletions

View File

@ -161,6 +161,7 @@ static char* synerrstr[] =
"unbalanced key/value pair",
"unbalanced parenthesis/brace/bracket",
"unexpected semicolon",
"stray backslash",
"block expression expected",
"block expression disallowed",
"invalid lvalue"

View File

@ -635,6 +635,7 @@ struct hcl_flx_st_t
enum hcl_flx_state_t
{
HCL_FLX_START,
HCL_FLX_BACKSLASHED,
HCL_FLX_COMMENT,
HCL_FLX_DELIM_TOKEN,
HCL_FLX_HMARKED_TOKEN, /* hash-marked token */

View File

@ -165,6 +165,7 @@ enum hcl_synerrnum_t
HCL_SYNERR_UNBALKV, /* unbalanced key/value pair */
HCL_SYNERR_UNBALPBB, /* unbalanced parenthesis/brace/bracket */
HCL_SYNERR_SEMICOLON, /* unexpected semicolon */
HCL_SYNERR_BACKSLASH, /* stray backslash */
HCL_SYNERR_BLOCK, /* block expression expected */
HCL_SYNERR_BLOCKBANNED, /* block expression disallowed */
HCL_SYNERR_LVALUE /* invalid lvalue */

View File

@ -1833,6 +1833,14 @@ static int flx_start (hcl_t* hcl, hcl_ooci_t c)
FEED_WRAP_UP_WITH_CHARS (hcl, vocas[VOCA_EOF].str, vocas[VOCA_EOF].len, HCL_TOK_EOF);
goto consumed;
case '\\':
FEED_CONTINUE_WITH_CHAR (hcl, c, HCL_FLX_BACKSLASHED);
goto consumed;
case '\n': /* specify all linebreak chars */
FEED_WRAP_UP_WITH_CHAR (hcl, c, HCL_TOK_SEMICOLON);
goto consumed;
/* this part is never hit because the semicolon sign is part of delim_tok_tab{}
TODO: remove this part once the language spec is finalized to not require this
case ';':
@ -1880,6 +1888,18 @@ not_consumed:
return 0;
}
static int flx_backslashed (hcl_t* hcl, hcl_ooci_t c)
{
if (is_linebreak(c))
{
FEED_CONTINUE (hcl, HCL_FLX_START);
return 1; /* consumed */
}
hcl_setsynerrbfmt (hcl, HCL_SYNERR_BACKSLASH, TOKEN_LOC(hcl), TOKEN_NAME(hcl), "stray backslash");
return -1;
}
static int flx_comment (hcl_t* hcl, hcl_ooci_t c)
{
if (is_linebreak(c)) FEED_CONTINUE (hcl, HCL_FLX_START);
@ -2574,6 +2594,7 @@ static int feed_char (hcl_t* hcl, hcl_ooci_t c)
switch (FLX_STATE(hcl))
{
case HCL_FLX_START: return flx_start(hcl, c);
case HCL_FLX_BACKSLASHED: return flx_backslashed(hcl, c);
case HCL_FLX_COMMENT: return flx_comment(hcl, c);
case HCL_FLX_DELIM_TOKEN: return flx_delim_token(hcl, c);
case HCL_FLX_HMARKED_TOKEN: return flx_hmarked_token(hcl, c);