66 void vAlt(parser* spCtx,
const opcode* spOp) {
67 const aint* uipChildBeg;
68 const aint* uipChildEnd;
69 const opcode* spChildOp;
70 spCtx->sState.uiHitCount++;
72 if(spCtx->uiTreeDepth > spCtx->sState.uiMaxTreeDepth){
73 spCtx->sState.uiMaxTreeDepth = spCtx->uiTreeDepth;
77 TRACE_DOWN(spCtx->vpTrace, spOp, spCtx->uiOffset);
79 uipChildBeg = spOp->sAlt.uipChildList;
80 uipChildEnd = uipChildBeg + spOp->sAlt.uiChildCount;
81 for (; uipChildBeg < uipChildEnd; uipChildBeg++) {
85 spChildOp = spCtx->spOpcodes + *uipChildBeg;
86 spCtx->pfnOpFunc[spChildOp->sGen.uiId](spCtx, spChildOp);
94 TRACE_UP(spCtx->vpTrace, spOp, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
95 STATS_HIT(spCtx->vpStats, spOp, spCtx->uiOpState);
99 void vCat(parser* spCtx,
const opcode* spOp) {
100 aint uiOffset = spCtx->uiOffset;
101 aint uiPhraseLength = 0;
103 const aint* uipChildBeg;
104 const aint* uipChildEnd;
105 const opcode* spChildOp;
106 spCtx->sState.uiHitCount++;
107 spCtx->uiTreeDepth++;
108 if(spCtx->uiTreeDepth > spCtx->sState.uiMaxTreeDepth){
109 spCtx->sState.uiMaxTreeDepth = spCtx->uiTreeDepth;
111 TRACE_DOWN(spCtx->vpTrace, spOp, spCtx->uiOffset);
116 uipChildBeg = spOp->sCat.uipChildList;
117 uipChildEnd = uipChildBeg + spOp->sCat.uiChildCount;
118 while (uipChildBeg < uipChildEnd) {
121 spChildOp = spCtx->spOpcodes + *uipChildBeg;
122 spCtx->pfnOpFunc[spChildOp->sGen.uiId](spCtx, spChildOp);
126 spCtx->uiOffset = uiOffset;
130 uiPhraseLength += spCtx->uiPhraseLength;
134 spCtx->uiPhraseLength = uiPhraseLength;
137 spCtx->uiOffset = uiOffset;
142 AST_OP_CLOSE(spCtx->vpAst, spCtx->uiInLookaround, spCtx->uiOpState);
143 TRACE_UP(spCtx->vpTrace, spOp, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
144 STATS_HIT(spCtx->vpStats, spOp, spCtx->uiOpState);
145 spCtx->uiTreeDepth--;
148 void vRep(parser* spCtx,
const opcode* spOp) {
149 aint uiMatchCount = 0;
150 aint uiPhraseLength = 0;
151 aint uiOffset = spCtx->uiOffset;
152 spCtx->sState.uiHitCount++;
153 spCtx->uiTreeDepth++;
154 if(spCtx->uiTreeDepth > spCtx->sState.uiMaxTreeDepth){
155 spCtx->sState.uiMaxTreeDepth = spCtx->uiTreeDepth;
157 TRACE_DOWN(spCtx->vpTrace, spOp, spCtx->uiOffset);
170 spCtx->pfnOpFunc[(spOp + 1)->sGen.uiId](spCtx, (spOp + 1));
174 AST_OP_CLOSE(spCtx->vpAst, spCtx->uiInLookaround, spCtx->uiOpState);
175 if ((spCtx->uiOpState ==
ID_MATCH) && (spCtx->uiPhraseLength == 0)) {
178 spCtx->uiOffset = uiOffset + uiPhraseLength;
179 spCtx->uiPhraseLength = uiPhraseLength;
184 if (uiMatchCount >= spOp->sRep.uiMin && uiMatchCount <= spOp->sRep.uiMax) {
187 spCtx->uiOffset = uiOffset + uiPhraseLength;
188 spCtx->uiPhraseLength = uiPhraseLength;
192 spCtx->uiOffset = uiOffset;
193 spCtx->uiPhraseLength = 0;
200 uiPhraseLength += spCtx->uiPhraseLength;
201 if (uiMatchCount >= spOp->sRep.uiMax) {
204 spCtx->uiOffset = uiOffset + uiPhraseLength;
205 spCtx->uiPhraseLength = uiPhraseLength;
213 AST_OP_CLOSE(spCtx->vpAst, spCtx->uiInLookaround, spCtx->uiOpState);
214 TRACE_UP(spCtx->vpTrace, spOp, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
215 STATS_HIT(spCtx->vpStats, spOp, spCtx->uiOpState);
216 spCtx->uiTreeDepth--;
219 static void vRnmValidateCallback(parser* spCtx,
rule* spRule,
aint uiOffset,
const char* cpFile,
const char* cpFunc,
221 aint uiState = spCtx->sCBData.uiCallbackState;
223 XTHROW(spCtx->spException,
224 "user rule name callback function: returned invalid state");
228 if ((uiOffset + spCtx->sCBData.uiCallbackPhraseLength) > spCtx->uiSubStringEnd) {
229 XTHROW(spCtx->spException,
230 "user rule name callback function: returned phrase length too long - beyond end of input string");
233 && (spCtx->sCBData.uiCallbackPhraseLength == 0)) {
234 XTHROW(spCtx->spException,
235 "user rule name callback function: returned empty phrase for non-empty rule");
239 spCtx->sCBData.uiCallbackPhraseLength = 0;
245 void vRnm(parser* spCtx,
const opcode* spOp) {
246 rule* spRule = spOp->sRnm.spRule;
248 aint uiOffset = spCtx->uiOffset;
249 spCtx->sState.uiHitCount++;
250 spCtx->uiTreeDepth++;
251 if(spCtx->uiTreeDepth > spCtx->sState.uiMaxTreeDepth){
252 spCtx->sState.uiMaxTreeDepth = spCtx->uiTreeDepth;
254 TRACE_DOWN(spCtx->vpTrace, spOp, spCtx->uiOffset);
261 spCtx->sCBData.uiCallbackState =
ID_ACTIVE;
262 spCtx->sCBData.uiCallbackPhraseLength = 0;
263 spCtx->sCBData.uiParserOffset = uiOffset - spCtx->uiSubStringBeg;
264 spCtx->sCBData.uiParserState =
ID_ACTIVE;
265 spCtx->sCBData.uiParserPhraseLength = 0;
268 pfnCallback(&spCtx->sCBData);
269 vRnmValidateCallback(spCtx, spRule, uiOffset, __FILE__, __func__, __LINE__);
270 if (spCtx->sCBData.uiCallbackState !=
ID_ACTIVE) {
272 if (spCtx->sCBData.uiCallbackState ==
ID_EMPTY) {
274 spCtx->sCBData.uiCallbackState =
ID_MATCH;
275 spCtx->sCBData.uiCallbackPhraseLength = 0;
277 spCtx->uiOpState = spCtx->sCBData.uiCallbackState;
278 spCtx->uiOffset = uiOffset + spCtx->sCBData.uiCallbackPhraseLength;
279 spCtx->uiPhraseLength = spCtx->sCBData.uiCallbackPhraseLength;
286 spCtx->pfnOpFunc[spOp->sRnm.spRule->spOp->sGen.uiId](spCtx, spOp->sRnm.spRule->spOp);
291 spCtx->sCBData.uiCallbackState =
ID_ACTIVE;
292 spCtx->sCBData.uiCallbackPhraseLength = 0;
293 spCtx->sCBData.uiParserOffset = uiOffset - spCtx->uiSubStringBeg;
294 spCtx->sCBData.uiParserState = spCtx->uiOpState;
295 spCtx->sCBData.uiParserPhraseLength = spCtx->uiPhraseLength;
298 pfnCallback(&spCtx->sCBData);
299 vRnmValidateCallback(spCtx, spRule, uiOffset, __FILE__, __func__, __LINE__);
300 if (spCtx->sCBData.uiCallbackState !=
ID_ACTIVE) {
302 if (spCtx->sCBData.uiCallbackState ==
ID_EMPTY) {
304 spCtx->sCBData.uiCallbackState =
ID_MATCH;
305 spCtx->sCBData.uiCallbackPhraseLength = 0;
307 spCtx->uiOpState = spCtx->sCBData.uiCallbackState;
308 spCtx->uiOffset = uiOffset + spCtx->sCBData.uiCallbackPhraseLength;
309 spCtx->uiPhraseLength = spCtx->sCBData.uiCallbackPhraseLength;
315 BKRU_RULE_CLOSE(spCtx->vpBkru, spRule->
uiRuleIndex, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
316 BKRP_RULE_CLOSE(spCtx->vpBkrp, spRule->
uiRuleIndex, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
317 AST_RULE_CLOSE(spCtx->vpAst, spCtx->uiInLookaround, spRule->
uiRuleIndex, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
318 TRACE_UP(spCtx->vpTrace, spOp, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
319 STATS_HIT(spCtx->vpStats, spOp, spCtx->uiOpState);
320 spCtx->uiTreeDepth--;
323 void vTrg(parser* spCtx,
const opcode* spOp) {
324 spCtx->sState.uiHitCount++;
325 spCtx->uiTreeDepth++;
326 if(spCtx->uiTreeDepth > spCtx->sState.uiMaxTreeDepth){
327 spCtx->sState.uiMaxTreeDepth = spCtx->uiTreeDepth;
329 TRACE_DOWN(spCtx->vpTrace, spOp, spCtx->uiOffset);
332 spCtx->uiPhraseLength = 0;
333 if (spCtx->uiOffset < spCtx->uiSubStringEnd) {
334 achar aChar = spCtx->acpInputString[spCtx->uiOffset];
335 if (aChar >= spOp->sTrg.acMin && aChar <= spOp->sTrg.acMax) {
337 spCtx->uiOffset += 1;
338 spCtx->uiPhraseLength = 1;
342 TRACE_UP(spCtx->vpTrace, spOp, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
343 STATS_HIT(spCtx->vpStats, spOp, spCtx->uiOpState);
344 spCtx->uiTreeDepth--;
347 void vTls(parser* spCtx,
const opcode* spOp) {
348 spCtx->sState.uiHitCount++;
349 spCtx->uiTreeDepth++;
350 if(spCtx->uiTreeDepth > spCtx->sState.uiMaxTreeDepth){
351 spCtx->sState.uiMaxTreeDepth = spCtx->uiTreeDepth;
353 TRACE_DOWN(spCtx->vpTrace, spOp, spCtx->uiOffset);
355 if (spCtx->uiOffset + spOp->sTls.uiStrLen > spCtx->uiSubStringEnd) {
357 spCtx->uiPhraseLength = 0;
359 const achar* acpInputBeg = &spCtx->acpInputString[spCtx->uiOffset];
360 const achar* acpStrBeg = spOp->sTls.acpStrTbl;
361 const achar* acpStrEnd = spOp->sTls.acpStrTbl + spOp->sTls.uiStrLen;
363 for (; acpStrBeg < acpStrEnd; acpStrBeg++, acpInputBeg++) {
365 achar acChar = *acpInputBeg;
366 if (acChar >= (
achar) 65 && acChar <= (
achar) 90) {
367 acChar += (
achar) 32;
369 if (acChar != *acpStrBeg) {
371 spCtx->uiPhraseLength = 0;
376 spCtx->uiOffset += spOp->sTls.uiStrLen;
377 spCtx->uiPhraseLength = spOp->sTls.uiStrLen;
381 TRACE_UP(spCtx->vpTrace, spOp, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
382 STATS_HIT(spCtx->vpStats, spOp, spCtx->uiOpState);
383 spCtx->uiTreeDepth--;
386 void vTbs(parser* spCtx,
const opcode* spOp) {
387 spCtx->sState.uiHitCount++;
388 spCtx->uiTreeDepth++;
389 if(spCtx->uiTreeDepth > spCtx->sState.uiMaxTreeDepth){
390 spCtx->sState.uiMaxTreeDepth = spCtx->uiTreeDepth;
392 TRACE_DOWN(spCtx->vpTrace, spOp, spCtx->uiOffset);
394 if (spCtx->uiOffset + spOp->sTbs.uiStrLen > spCtx->uiSubStringEnd) {
396 spCtx->uiPhraseLength = 0;
398 const achar* acpInputBeg = &spCtx->acpInputString[spCtx->uiOffset];
399 const achar* acpStrBeg = spOp->sTbs.acpStrTbl;
400 const achar* acpStrEnd = spOp->sTbs.acpStrTbl + spOp->sTbs.uiStrLen;
402 for (; acpStrBeg < acpStrEnd; acpStrBeg++, acpInputBeg++) {
404 if (*acpInputBeg != *acpStrBeg) {
406 spCtx->uiPhraseLength = 0;
411 spCtx->uiOffset += spOp->sTbs.uiStrLen;
412 spCtx->uiPhraseLength = spOp->sTbs.uiStrLen;
416 TRACE_UP(spCtx->vpTrace, spOp, spCtx->uiOpState, (spCtx->uiOffset - spCtx->uiPhraseLength), spCtx->uiPhraseLength);
417 STATS_HIT(spCtx->vpStats, spOp, spCtx->uiOpState);
418 spCtx->uiTreeDepth--;