diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-10 18:37:24 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-10 18:37:24 +0200 |
commit | 9ea4368ff1e4842286e0e7a6aec58a2c2c799d5b (patch) | |
tree | 47d31fa6d686dd50220edfa505fcc21ce6c860fe /lexer.c | |
parent | 39164c57d893b02f9a253c661abc2459bcd57e5c (diff) |
treewide: implement default lstrip_blocks and trim_blocks behaviour
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lexer.c')
-rw-r--r-- | lexer.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -58,6 +58,7 @@ static const struct token tokens[] = { { T_ASRIGHT, ">>=", 3 }, { T_LEXP, "{{-", 3 }, { T_REXP, "-}}", 3 }, + { T_LSTM, "{%+", 3 }, { T_LSTM, "{%-", 3 }, { T_RSTM, "-%}", 3 }, { T_AND, "&&", 2 }, @@ -731,9 +732,16 @@ ut_get_token(struct ut_state *s, const char *input, int *mlen) s->off += *mlen; /* strip whitespace before block */ - if (p[2] == '-') + if (p[2] == '-') { while (p > o && isspace(p[-1])) p--; + } + + /* lstrip */ + else if (s->lstrip_blocks && s->blocktype == UT_BLOCK_STATEMENT && p[2] != '+') { + while (p > o && p[-1] != '\n' && isspace(p[-1])) + p--; + } if (p == o) return 0; @@ -789,9 +797,6 @@ ut_get_token(struct ut_state *s, const char *input, int *mlen) *mlen = 0; } else { - s->semicolon_emitted = false; - s->blocktype = UT_BLOCK_NONE; - /* strip whitespace after block */ if (*p == '-') { while (isspace(p[3])) { @@ -799,6 +804,13 @@ ut_get_token(struct ut_state *s, const char *input, int *mlen) p++; } } + else if (s->blocktype == UT_BLOCK_STATEMENT && + s->trim_blocks && p[2] == '\n') { + (*mlen)++; + } + + s->semicolon_emitted = false; + s->blocktype = UT_BLOCK_NONE; } } |