From 16fd267fc78f888b10f12e0aa55441332461c411 Mon Sep 17 00:00:00 2001 From: thurston Date: Fri, 11 Jan 2008 03:26:36 +0000 Subject: [PATCH] Prevent the left machine from persisting through :>> via an empty string on the right. git-svn-id: http://svn.complang.org/ragel/trunk@396 052ea7fc-9027-0410-9066-f65837a77df0 --- doc/ragel-guide.tex | 5 ++++- ragel/parsetree.cpp | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/ragel-guide.tex b/doc/ragel-guide.tex index 4777840..f7c9b07 100644 --- a/doc/ragel-guide.tex +++ b/doc/ragel-guide.tex @@ -2355,7 +2355,10 @@ main := any* :>> 'FIN'; \end{center} \graphspace -Finish-guarded concatenation is equivalent to the following: +Finish-guarded concatenation is equivalent to the following, with one +exception. If the right machine's start state is final, the higher priority is +also embedded into it as a leaving priority. This prevents the left machine +from persisting via the zero-length string. \verbspace \begin{verbatim} diff --git a/ragel/parsetree.cpp b/ragel/parsetree.cpp index c95921f..f31d8bc 100644 --- a/ragel/parsetree.cpp +++ b/ragel/parsetree.cpp @@ -840,8 +840,8 @@ FsmAp *Term::walk( ParseData *pd, bool lastInSeq ) priorDescs[0].priority = 0; rtnVal->allTransPrior( pd->curPriorOrd++, &priorDescs[0] ); - /* The start transitions right machine get the higher priority. - * Use the same unique key. */ + /* The start transitions of the right machine gets the higher + * priority. Use the same unique key. */ priorDescs[1].key = priorDescs[0].key; priorDescs[1].priority = 1; rhs->startFsmPrior( pd->curPriorOrd++, &priorDescs[1] ); @@ -871,6 +871,14 @@ FsmAp *Term::walk( ParseData *pd, bool lastInSeq ) priorDescs[1].priority = 1; rhs->finishFsmPrior( pd->curPriorOrd++, &priorDescs[1] ); + /* If the right machine's start state is final we need to guard + * against the left machine persisting by moving through the empty + * string. */ + if ( rhs->startState->isFinState() ) { + rhs->startState->outPriorTable.setPrior( + pd->curPriorOrd++, &priorDescs[1] ); + } + /* Perform concatenation. */ rtnVal->concatOp( rhs ); afterOpMinimize( rtnVal, lastInSeq ); -- 2.7.4