diff options
| author | Quentin Carbonneaux | 2015-10-04 15:15:56 -0400 |
|---|---|---|
| committer | Quentin Carbonneaux | 2015-10-04 15:15:56 -0400 |
| commit | 36f20203ed9debdf9d4ceaafa7ea6dd3993c7713 (patch) | |
| tree | e1dc08c38e0d3e46ed59cf184042e1cc19bedd97 | |
| parent | dd12fbab7742801ee2c3cc1ad79897885f4e2893 (diff) | |
improve handling of strings in code blocks
| -rw-r--r-- | yacc.c | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -851,7 +851,7 @@ nexttk() char * cpycode() { - int c, nest, len, pos; + int c, nest, in, len, pos; char *s; len = 64; @@ -859,17 +859,26 @@ cpycode() s[0] = '{'; pos = 1; nest = 1; + in = 0; while (nest) { c = fgetc(fin); - if (c == '{') - nest++; - if (c == '}') - nest--; - if (c == EOF) - die("syntax error, unclosed code block"); - if (c == '\n') - lineno++; + if (in) { + if (c == in) + if (s[pos-1] != '\\') + in = 0; + } else { + if (c == '"' || c == '\'') + in = c; + if (c == '{') + nest++; + if (c == '}') + nest--; + if (c == EOF) + die("syntax error, unclosed code block"); + if (c == '\n') + lineno++; + } if (pos>=len) if (!(s=realloc(s, len=2*len+1))) die("out of memory"); |
