diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-05-25 19:58:05 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-05-25 22:21:25 +0200 |
commit | 9874562545d93582a75bc2e6d58fc772e981a3ba (patch) | |
tree | 02084ca6771d425cef509d0a5504a5591dcdb7fd /lexer.c | |
parent | 3b665c84d70885a976179f01ce12626255cb5e52 (diff) |
lexer: implement raw code mode
Enabling raw code mode allows writing ucode scripts without any template
tag decorations (that is, without the need to provide an initial opening
'{%' tag).
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lexer.c')
-rw-r--r-- | lexer.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -1047,6 +1047,13 @@ lex_step(uc_lexer *lex, FILE *fp) return NULL; } + /* in raw code mode, ignore template tag tokens */ + if (lex->config && lex->config->raw_mode && + (tok->type == TK_LSTM || tok->type == TK_RSTM || + tok->type == TK_LEXP || tok->type == TK_REXP)) { + continue; + } + /* disallow nesting blocks */ if (tok->type == TK_LSTM || tok->type == TK_LEXP) { buf_consume(lex, tok->plen); @@ -1188,6 +1195,11 @@ uc_lexer_init(uc_lexer *lex, uc_parse_config *config, uc_source *source) lex->lastoff = 0; + if (config && config->raw_mode) { + lex->state = UT_LEX_IDENTIFY_TOKEN; + lex->block = STATEMENTS; + } + /* Skip any potential interpreter line */ if (lex->source->off == 0) uc_lexer_skip_shebang(lex); |