This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Error: "quantifier operand invalid"

Help for those learning Tcl or writing their own scripts.
Post Reply
t
tueb
Halfop
Posts: 76
Joined: Thu Oct 04, 2007 6:09 am
Location: #quiz.de @ irc.gamesurge.net
Contact:

Error: "quantifier operand invalid"

Post by tueb »

Hi,

I get the following error:
couldn't compile regular expression pattern: quantifier operand invalid
while executing
"regexp -- $theq(Regexp) $subexp"
(procedure "moxquiz_ask" line 152)
invoked from within
"moxquiz_ask $botnick {} {} $quizconf(quizchannel) {}"
(procedure "mx_timer_ask" line 3)
invoked from within
"mx_timer_ask"


This is the code:

Code: Select all

	# protect embedded numbers
	if {[regexp "\[0-9\]+" $theq(Regexp)]} {
	    set newexp ""
	    set oldexp $theq(Regexp)
	    set theq(Oldexp) $oldexp

	    while {[regexp -indices "(\[0-9\]+)" $oldexp pair]} {
		set subexp [string range $oldexp [lindex $pair 0]  [lindex $pair 1]]
		set newexp "${newexp}[string range $oldexp -1 [expr [lindex $pair 0] - 1]]"
		if {[regexp -- $theq(Regexp) $subexp]} {
		    set newexp "${newexp}(^|\[^0-9\])${subexp}(\$|\[^0-9\])"
		} else {
		    set newexp "${newexp}${subexp}"
		}
		set oldexp "[string range $oldexp [expr [lindex $pair 1] + 1] [string length $oldexp]]"
	    }
	    set newexp "${newexp}${oldexp}"
	    set theq(Regexp) $newexp
	    #mx_log "---- replaced regexp '$theq(Oldexp)' with '$newexp' to protect numbers."
	}

If I understand corretly, the "$theq(Regexp)" includes braces, which aren't balanced.

Is there a way to prevent the bot from aborting the proc upon this error? I can't prevent the unbalanced braces in the file out of which the "$theq(Regexp)" is generated.

Thank you for your help,

tueb
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I am abit puzzled by the extensive mangling of the regular expression.
In any case, an invalid quantifier operand would suggest one of the below have been broken by the mangling:
A quantified atom is an atom possibly followed by a single quantifier. Without a quantifier, it matches a match for the atom. The quantifiers, and
what a so-quantified atom matches, are:

* a sequence of 0 or more matches of the atom

+ a sequence of 1 or more matches of the atom

? a sequence of 0 or 1 matches of the atom

{m} a sequence of exactly m matches of the atom

{m,} a sequence of m or more matches of the atom

{m,n} a sequence of m through n (inclusive) matches of the atom; m may not exceed n

*? +? ?? {m}? {m,}? {m,n}?
non-greedy quantifiers, which match the same possibilities, but prefer the smallest number rather than the largest number of matches (see
MATCHING)
It might be possible that there's an unmatched brace, as you suspect. There are, however numerous other ways it might be broken.
Try adding something like: putlog "Mangling regexp: $theq(Regexp)" just above the line: if {[regexp -- $theq(Regexp) $subexp]} {
This should reveal the actual regular expression that is broken, might assist in figuring what's going wrong...
NML_375
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

you could remove the braces if they are not actually used
for regular braces:

Code: Select all

regsub -all -- {\[|\]} $theq(Regexp) {} theq(Regexp)
for curly braces:

Code: Select all

regsub -all -- {\{|\}} $theq(Regexp) {} theq(Regexp)
t
tueb
Halfop
Posts: 76
Joined: Thu Oct 04, 2007 6:09 am
Location: #quiz.de @ irc.gamesurge.net
Contact:

Post by tueb »

Thanks for your quick help!


nml375: I added the putlog "Mangling regexp: $theq(Regexp)". Now I'll have to wait until the error occurs next.

DragnLord: Unfortunately the braces are used. For example: "Answer[ -]?(1|2)"


Thanks again,

tueb
t
tueb
Halfop
Posts: 76
Joined: Thu Oct 04, 2007 6:09 am
Location: #quiz.de @ irc.gamesurge.net
Contact:

Post by tueb »

I got the first result with unbalanced braces:
[16:38] Mangling regexp: (1861 - 1865|1861?[ -]?1865


but this time, the errorlog also stated:
03/03/08@16:38.07> : couldn't compile regular expression pattern: parentheses () not balanced

-------
Edit:
[22:18] Mangling regexp: (7 x|7|sieben)
[22:19] Last message repeated 1 time(s).
[22:19] Tcl error [moxquiz_pubm]: couldn't compile regular expression pattern: quantifier operand invalid
[22:19] couldn't compile regular expression pattern: quantifier operand invalid
while executing
"regexp -nocase -- $answer $saveanswer"
(procedure "moxquiz_pubm" line 668)
invoked from within
"moxquiz_pubm $_pubm1 $_pubm2 $_pubm3 $_pubm4 $_pubm5"
Post Reply