Tcl Source Code

Artifact [929c948693]
Login

Artifact 929c94869334e49d3cfdd110ffbc20fb914cdf81:

Attachment "bosonly.patch" to ticket [1178541fff] added by tgl 2015-11-06 22:10:40. (unpublished)
diff -pcdr src/generic/regc_lex.c bosonlyfix/generic/regc_lex.c
*** src/generic/regc_lex.c	Mon Sep 21 18:12:24 2015
--- bosonlyfix/generic/regc_lex.c	Fri Nov  6 16:59:39 2015
*************** next(
*** 309,323 ****
      v->lasttype = v->nexttype;
  
      /*
-      * REG_BOSONLY
-      */
- 
-     if (v->nexttype == EMPTY && (v->cflags&REG_BOSONLY)) {
- 	/* at start of a REG_BOSONLY RE */
- 	RETV(SBEGIN, 0);	/* same as \A */
-     }
- 
-     /*
       * If we're nested and we've hit end, return to outer level.
       */
  
--- 309,314 ----
diff -pcdr src/generic/regc_nfa.c bosonlyfix/generic/regc_nfa.c
*** src/generic/regc_nfa.c	Tue Oct 27 14:39:17 2015
--- bosonlyfix/generic/regc_nfa.c	Fri Nov  6 16:58:47 2015
*************** newnfa(
*** 74,82 ****
  	freenfa(nfa);
  	return NULL;
      }
!     rainbow(nfa, nfa->cm, PLAIN, COLORLESS, nfa->pre, nfa->init);
      newarc(nfa, '^', 1, nfa->pre, nfa->init);
      newarc(nfa, '^', 0, nfa->pre, nfa->init);
      rainbow(nfa, nfa->cm, PLAIN, COLORLESS, nfa->final, nfa->post);
      newarc(nfa, '$', 1, nfa->final, nfa->post);
      newarc(nfa, '$', 0, nfa->final, nfa->post);
--- 74,99 ----
  	freenfa(nfa);
  	return NULL;
      }
! 
!     /*
!      * pre to init arcs match the character before the match proper.
!      * Ordinarily that can be anything including BOS/BOL.  (If the regexp
!      * constrains the preceding character, we'll discover that and remove arcs
!      * as appropriate during NFA optimization.)  However, REG_BOSONLY tells us
!      * to only allow BOS/BOL, if this is the top level NFA.
!      */
!     if (parent == NULL && (v->cflags & REG_BOSONLY)) {
! 	/* BOSONLY, do not insert rainbow */
!     } else {
! 	rainbow(nfa, nfa->cm, PLAIN, COLORLESS, nfa->pre, nfa->init);
!     }
      newarc(nfa, '^', 1, nfa->pre, nfa->init);
      newarc(nfa, '^', 0, nfa->pre, nfa->init);
+ 
+     /*
+      * Similarly, final to post arcs match the character after the match
+      * proper, and initially that can be any character or EOS/EOL.
+      */
      rainbow(nfa, nfa->cm, PLAIN, COLORLESS, nfa->final, nfa->post);
      newarc(nfa, '$', 1, nfa->final, nfa->post);
      newarc(nfa, '$', 0, nfa->final, nfa->post);
diff -pcdr src/generic/regex.h bosonlyfix/generic/regex.h
*** src/generic/regex.h	Tue Oct 27 14:39:17 2015
--- bosonlyfix/generic/regex.h	Fri Nov  6 16:44:57 2015
*************** typedef struct {
*** 220,226 ****
  #define	REG_NEWLINE	000300	/* newlines are line terminators */
  #define	REG_PEND	000400	/* ugh -- backward-compatibility hack */
  #define	REG_EXPECT	001000	/* report details on partial/limited matches */
! #define	REG_BOSONLY	002000	/* temporary kludge for BOS-only matches */
  #define	REG_DUMP	004000	/* none of your business :-) */
  #define	REG_FAKE	010000	/* none of your business :-) */
  #define	REG_PROGRESS	020000	/* none of your business :-) */
--- 220,226 ----
  #define	REG_NEWLINE	000300	/* newlines are line terminators */
  #define	REG_PEND	000400	/* ugh -- backward-compatibility hack */
  #define	REG_EXPECT	001000	/* report details on partial/limited matches */
! #define	REG_BOSONLY	002000	/* match only at string start (like \A) */
  #define	REG_DUMP	004000	/* none of your business :-) */
  #define	REG_FAKE	010000	/* none of your business :-) */
  #define	REG_PROGRESS	020000	/* none of your business :-) */
diff -pcdr src/generic/tclInt.h bosonlyfix/generic/tclInt.h
*** src/generic/tclInt.h	Fri Nov  6 12:24:34 2015
--- bosonlyfix/generic/tclInt.h	Fri Nov  6 16:43:50 2015
*************** typedef void **TclHandle;
*** 1331,1338 ****
   *----------------------------------------------------------------
   */
  
! #define TCL_REG_BOSONLY 002000	/* Prepend \A to pattern so it only matches at
! 				 * the beginning of the string. */
  
  /*
   * These are a thin layer over TclpThreadKeyDataGet and TclpThreadKeyDataSet
--- 1331,1338 ----
   *----------------------------------------------------------------
   */
  
! #define TCL_REG_BOSONLY 002000	/* Allow pattern to match only at the
! 				 * beginning of the string (implicit \A). */
  
  /*
   * These are a thin layer over TclpThreadKeyDataGet and TclpThreadKeyDataSet
diff -pcdr src/tests/reg.test bosonlyfix/tests/reg.test
*** src/tests/reg.test	Tue Oct 27 14:39:17 2015
--- bosonlyfix/tests/reg.test	Fri Nov  6 16:47:12 2015
*************** expectMatch	30.4 &		a*b	aab	aab
*** 940,950 ****
  expectMatch	30.5 &		^a*b	aaaab	aaaab
  expectMatch	30.6 &M		{[0-6][1-2][0-3][0-6][1-6][0-6]} \
  	"010010" 010010
! # temporary REG_BOSONLY kludge
  expectMatch	30.7 s		abc	abcd	abc
  expectNomatch	30.8 s		abc	xabcd
  # back to normal stuff
! expectMatch	30.9 HLP	{(?n)^(?![t#])\S+} \
  	"tk\n\n#\n#\nit0"	it0
  
  
--- 940,951 ----
  expectMatch	30.5 &		^a*b	aaaab	aaaab
  expectMatch	30.6 &M		{[0-6][1-2][0-3][0-6][1-6][0-6]} \
  	"010010" 010010
! # REG_BOSONLY (kludge for Expect, not really public otherwise)
  expectMatch	30.7 s		abc	abcd	abc
  expectNomatch	30.8 s		abc	xabcd
+ expectNomatch	30.9 s		abc|def	xdef
  # back to normal stuff
! expectMatch	30.10 HLP	{(?n)^(?![t#])\S+} \
  	"tk\n\n#\n#\nit0"	it0