summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-03-17 10:30:50 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-03-17 10:30:50 -0700
commit2c3a4ff60e91bf71911dd8c68f22871a7e11da55 (patch)
tree906d6406f569a453d92a7dda5b4bc847df42d2e7 /parser.c
parent8e7bba1e12c8d5f583c958b9eac0a68c18bf1c9a (diff)
downloadtxr-2c3a4ff60e91bf71911dd8c68f22871a7e11da55.tar.gz
txr-2c3a4ff60e91bf71911dd8c68f22871a7e11da55.tar.bz2
txr-2c3a4ff60e91bf71911dd8c68f22871a7e11da55.zip
listener: fix poor regex handling in balance check.
* parser.c (is_balanced_line): Introduce the ST_RGXC state to which we switch when we encounter a regex character class. Also introduce ST_RGXE for regex subexpressions. In these states, do not recognize / as the regex terminator.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/parser.c b/parser.c
index 849de26d..cbd2f4fe 100644
--- a/parser.c
+++ b/parser.c
@@ -948,7 +948,7 @@ static int is_balanced_line(const char *line, void *ctx)
{
enum state {
ST_START, ST_CMNT, ST_PAR, ST_BKT, ST_BRC, ST_HASH,
- ST_LIT, ST_QLIT, ST_RGX, ST_CHR, ST_ESC, ST_AT,
+ ST_LIT, ST_QLIT, ST_RGX, ST_RGXC, ST_RGXE, ST_CHR, ST_ESC, ST_AT,
ST_HASH_B, ST_BUF
};
int count[32], sp = 0;
@@ -1062,6 +1062,38 @@ static int is_balanced_line(const char *line, void *ctx)
case '/':
sp--;
break;
+ case '[':
+ state[++sp] = ST_RGXC;
+ break;
+ case '(':
+ state[++sp] = ST_RGXE;
+ break;
+ case '\\':
+ state[++sp] = ST_ESC;
+ break;
+ }
+ break;
+ case ST_RGXC:
+ switch (ch) {
+ case ']':
+ sp--;
+ break;
+ case '\\':
+ state[++sp] = ST_ESC;
+ break;
+ }
+ break;
+ case ST_RGXE:
+ switch (ch) {
+ case ')':
+ sp--;
+ break;
+ case '[':
+ state[++sp] = ST_RGXC;
+ break;
+ case '(':
+ state[++sp] = ST_RGXE;
+ break;
case '\\':
state[++sp] = ST_ESC;
break;