summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lexer.c12
-rw-r--r--main.c9
-rw-r--r--tests/cram/test_basic.t3
-rw-r--r--types.h1
4 files changed, 22 insertions, 3 deletions
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);
diff --git a/main.c b/main.c
index 4b34ef2..5d14c83 100644
--- a/main.c
+++ b/main.c
@@ -40,7 +40,7 @@ print_usage(const char *app)
{
printf(
"== Usage ==\n\n"
- " # %s [-d] [-l] [-r] [-S] [-e '[prefix=]{\"var\": ...}'] [-E [prefix=]env.json] {-i <file> | -s \"ucode script...\"}\n"
+ " # %s [-d] [-l] [-r] [-S] [-R] [-e '[prefix=]{\"var\": ...}'] [-E [prefix=]env.json] {-i <file> | -s \"ucode script...\"}\n"
" -h, --help Print this help\n"
" -i file Specify an ucode script to parse\n"
" -s \"ucode script...\" Specify an ucode fragment to parse\n"
@@ -48,6 +48,7 @@ print_usage(const char *app)
" -l Do not strip leading block whitespace\n"
" -r Do not trim trailing block newlines\n"
" -S Enable strict mode\n"
+ " -R Enable raw code mode\n"
" -e Set global variables from given JSON object\n"
" -E Set global variables from given JSON file\n"
" -m Preload given module\n",
@@ -214,7 +215,7 @@ main(int argc, char **argv)
goto out;
}
- while ((opt = getopt(argc, argv, "hlrSe:E:i:s:m:")) != -1)
+ while ((opt = getopt(argc, argv, "hlrSRe:E:i:s:m:")) != -1)
{
switch (opt) {
case 'h':
@@ -262,6 +263,10 @@ main(int argc, char **argv)
config.strict_declarations = true;
break;
+ case 'R':
+ config.raw_mode = true;
+ break;
+
case 'e':
c = strchr(optarg, '=');
diff --git a/tests/cram/test_basic.t b/tests/cram/test_basic.t
index 3d4cd9e..aab5b16 100644
--- a/tests/cram/test_basic.t
+++ b/tests/cram/test_basic.t
@@ -12,7 +12,7 @@ check that ucode provides exepected help:
$ ucode | sed 's/ucode-san/ucode/'
== Usage ==
- # ucode [-d] [-l] [-r] [-S] [-e '[prefix=]{"var": ...}'] [-E [prefix=]env.json] {-i <file> | -s "ucode script..."}
+ # ucode [-d] [-l] [-r] [-S] [-R] [-e '[prefix=]{"var": ...}'] [-E [prefix=]env.json] {-i <file> | -s "ucode script..."}
-h, --help\tPrint this help (esc)
-i file\tSpecify an ucode script to parse (esc)
-s "ucode script..."\tSpecify an ucode fragment to parse (esc)
@@ -20,6 +20,7 @@ check that ucode provides exepected help:
-l Do not strip leading block whitespace
-r Do not trim trailing block newlines
-S Enable strict mode
+ -R Enable raw code mode
-e Set global variables from given JSON object
-E Set global variables from given JSON file
-m Preload given module
diff --git a/types.h b/types.h
index 3aaf8bc..a4377ad 100644
--- a/types.h
+++ b/types.h
@@ -205,6 +205,7 @@ typedef struct {
bool lstrip_blocks;
bool trim_blocks;
bool strict_declarations;
+ bool raw_mode;
} uc_parse_config;