From 9874562545d93582a75bc2e6d58fc772e981a3ba Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 25 May 2021 19:58:05 +0200 Subject: 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 --- lexer.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lexer.c') diff --git a/lexer.c b/lexer.c index 5950387..1be6978 100644 --- a/lexer.c +++ b/lexer.c @@ -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); -- cgit v1.2.3