aboutsummaryrefslogtreecommitdiff
path: root/jimregexp.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2011-11-09 05:32:09 +1000
committerSteve Bennett <steveb@workware.net.au>2011-11-10 07:39:18 +1000
commitcd2e4d7831ccc468a11247596c7891a1df81f505 (patch)
tree4ac931917f116ba9c9b73d1dd45614cfd30d4bba /jimregexp.c
parent5773653645346329ae65c8e7c865f43ffd7d9b0b (diff)
downloadjimtcl-cd2e4d7831ccc468a11247596c7891a1df81f505.zip
jimtcl-cd2e4d7831ccc468a11247596c7891a1df81f505.tar.gz
jimtcl-cd2e4d7831ccc468a11247596c7891a1df81f505.tar.bz2
regex: add support for non-capturing parentheses
Tcl-compatible syntax: (?:...) Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jimregexp.c')
-rw-r--r--jimregexp.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/jimregexp.c b/jimregexp.c
index c652ad4..45f7c31 100644
--- a/jimregexp.c
+++ b/jimregexp.c
@@ -77,7 +77,7 @@
* to the thing following the set of BRANCHes.) The opcodes are:
*/
-/* This *MUST* be less than (255-20)/2=117 */
+/* This *MUST* be less than (255-20-1)/2=117 */
#define REG_MAX_PAREN 100
/* definition number opnd? meaning */
@@ -98,10 +98,12 @@
#define WORDA 15 /* no Match "" at wordchar, where prev is nonword */
#define WORDZ 16 /* no Match "" at nonwordchar, where prev is word */
+#define OPENNC 19 /* no Non-capturing parentheses - must be OPEN-1 */
#define OPEN 20 /* no Mark this point in input as start of #n. */
/* OPEN+1 is number 1, etc. */
-#define CLOSE (OPEN+REG_MAX_PAREN) /* no Analogous to OPEN. */
+#define CLOSE (OPEN+REG_MAX_PAREN+1) /* no Analogous to OPEN. */
#define CLOSE_END (CLOSE+REG_MAX_PAREN)
+#define CLOSENC (CLOSE-1) /* no Non-capturing parentheses - must be CLOSE-1 */
/*
* The first byte of the regexp internal "program" is actually this magic
@@ -333,7 +335,14 @@ static int reg(regex_t *preg, int paren /* Parenthesized? */, int *flagp )
/* Make an OPEN node, if parenthesized. */
if (paren) {
- parno = ++preg->re_nsub;
+ if (preg->regparse[0] == '?' && preg->regparse[1] == ':') {
+ /* non-capturing paren */
+ preg->regparse += 2;
+ parno = -1;
+ }
+ else {
+ parno = ++preg->re_nsub;
+ }
ret = regnode(preg, OPEN+parno);
} else
ret = 0;
@@ -1446,6 +1455,14 @@ static int regmatch(regex_t *preg, int prog)
case END:
return(1); /* Success! */
break;
+
+ case OPENNC:
+ case CLOSENC:
+ if (regmatch(preg, next)) {
+ return 1;
+ }
+ return 0;
+
default:
if (OP(preg, scan) >= OPEN+1 && OP(preg, scan) < CLOSE_END) {
const char *save;