I am breaking this off from the thread "General: Triggers across lines", since it is getting a tad insane over there. lol
Having had a bit of a sleepless night, where I kept running to the computer having remembered something I forgot, I eventually came up with this:
VM operation/parts:
CodeArray - Holds the array of 'commands' that get executed.
RegExpArray - Holds the chunks of RegExp the preparser seperates out.
PC - Integer holding the 'program counter' that keeps track of the current instruction to be executed.
The PC always starts at 0 initially, but increases by 1 for each successful RegExp match. When such a match happens, the VM returns with a TRUE value and whatever wildcards where generated for the line. The next time the trigger is tested, it starts execution and the 'current' PC or if the PC is now greater than the number of instructions, it is reset to 0 and testing starts over from there.
Instructions and logic:
test RegExpPtr
if *matched* then
PC = PC + 1
return TRUE
else
PC = 0
return FALSE
end if
opt RegExpPtr, <bailout>
if *matched* then
if <bailout> then
PC = 0
else
PC = PC + 1
end if
return TRUE
else
PC = PC + 1
end if
rst
count = 0
lp <max>, <AddrChng>, RegExpPtr
if RegExpPtr <> 0 then
if *matched* then
PC = PC + 1
return TRUE
else
count = count + 1
if count > <max> and <max> > 0 then
PC = 0
return FALSE
else
PC = PC + <AddrChng>
end if
end if
else
count = count + 1
if count > <max> then
PC = 0
else
PC = PC + <AddrChng>
end if
end if
Examples of how the pre-parser would build the execution code for these:
Example 1 "^You see\:$(.*\n){1,10}^$">
test 1
rst
opt 2, 0
lp 10, -1, 3
Example 2 "^Fred says: .*">
test 1
Example 3 "^You see\:$(.*\n){1,}^$">
test 1
test 2
opt 2, 0
test 3
Example 4 "^You see\:$(.*\n){5,}^$">
test 1
rst
test 2
lp 5, -1, 0
opt 2, 0
test 3
Example 5 "^You see\:$(.*\n){5,10}^$">
test 1
rst
test 2
lp 5, -1, 0
rst
opt 2, 0
lp 10, -1, 3
Example 6 "^You see\:$(.*\n){,10}">
test 1
rst
opt 2, 0
lp 10, -1, 0
Example 7 "^You see\:$(Nothing\n)|(.*\n){1,}">
test 1
opt 2, 1
opt 3, 0
lp 0, -2, 0
Now.. If I could just find someone to design the needed pre-parser. lol But this does do both what you want Nick and follows the actual syntax, without gludging extra settings and a look-back buffer on to make it work, which is what I don't like. Unfortunately designing the pre-parser is much more complicated when you have to deal with situations like example 7. :( The rest are relatively straight forward.
Oh.. And I also considered using a set of 'opcodes' that included "test, inc, cmp, beg, bne, lp, ret <boolean>, rst", but realized that this wasn't really necessary, since all the logic really needed could be incorperated directly into the test, opt, inc and lp functions themselves. |