diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-02-02 21:53:23 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-02-02 21:53:23 -0500 |
commit | c07038c627a5601bf331b5c755b9fcce02249fe3 (patch) | |
tree | 920fba38081591ffe2f62a78886a24f4d101abc8 | |
parent | 48cf99abba57ac20d32421f57bf04cb96d92bc7c (diff) | |
download | dimension-c07038c627a5601bf331b5c755b9fcce02249fe3.tar.xz |
Skip over invalid tokens in non-taken conditionals.
-rw-r--r-- | dimension/lexer.l | 16 | ||||
-rw-r--r-- | dimension/tokenize.c | 10 | ||||
-rw-r--r-- | tests/dimension/directives.pov | 2 | ||||
-rwxr-xr-x | tests/dimension/directives.sh | 2 |
4 files changed, 13 insertions, 17 deletions
diff --git a/dimension/lexer.l b/dimension/lexer.l index cd02da1..eb5184c 100644 --- a/dimension/lexer.l +++ b/dimension/lexer.l @@ -285,17 +285,11 @@ dmnsn_tokenize(FILE *file, const char *filename) while ((token.type = dmnsn_yylex_impl(&item, &location, filename, scanner)) != 0) { - if (token.type == DMNSN_T_LEX_ERROR) { - dmnsn_delete_tokens(tokens); - tokens = NULL; - break; - } else { - token.value = item.value; - token.filename = location.first_filename; - token.line = location.first_line; - token.col = location.first_column; - dmnsn_array_push(tokens, &token); - } + token.value = item.value; + token.filename = location.first_filename; + token.line = location.first_line; + token.col = location.first_column; + dmnsn_array_push(tokens, &token); } yylex_destroy(scanner); diff --git a/dimension/tokenize.c b/dimension/tokenize.c index 8e696ed..cc912b6 100644 --- a/dimension/tokenize.c +++ b/dimension/tokenize.c @@ -263,9 +263,6 @@ dmnsn_if_buffer(int token, dmnsn_token_buffer *prev, "syntax error, unexpected end-of-file"); dmnsn_delete_token_buffer(tbuffer); return NULL; - } else if (buffered.type == DMNSN_T_LEX_ERROR) { - dmnsn_delete_token_buffer(tbuffer); - return NULL; } switch (buffered.type) { @@ -294,7 +291,12 @@ dmnsn_if_buffer(int token, dmnsn_token_buffer *prev, } if (cond) { - dmnsn_array_push(tbuffer->buffered, &buffered); + if (buffered.type == DMNSN_T_LEX_ERROR) { + dmnsn_delete_token_buffer(tbuffer); + return NULL; + } else { + dmnsn_array_push(tbuffer->buffered, &buffered); + } } else { free(buffered.lval.value); } diff --git a/tests/dimension/directives.pov b/tests/dimension/directives.pov index 1bb712d..187189f 100644 --- a/tests/dimension/directives.pov +++ b/tests/dimension/directives.pov @@ -27,7 +27,7 @@ #undef Unused #if (#if (1 = 1) 0 #end = 0 & 0) - Illegal + `Illegal #else sphere { Center, R diff --git a/tests/dimension/directives.sh b/tests/dimension/directives.sh index 955ea15..e24a62a 100755 --- a/tests/dimension/directives.sh +++ b/tests/dimension/directives.sh @@ -27,7 +27,7 @@ directives_exp="$(echo -n \ #declare (identifier "Unused") = - (integer "1") ; #undef (identifier "Unused") #if \( #if \( (integer "1") = (integer "1") \) (integer "0") #end = (integer "0") & (integer "0") \) - (identifier "Illegal") + error (identifier "Illegal") #else sphere { (identifier "Center") , (identifier "R") |