Patches from Diego Elio 'Flameeyes' Pettenò.
[external/ragel.git] / ragel / parsetree.cpp
index 6a97a28..3245a54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Adrian Thurston <thurston@cs.queensu.ca>
+ *  Copyright 2001-2006 Adrian Thurston <thurston@complang.org>
  */
 
 /*  This file is part of Ragel.
@@ -38,14 +38,14 @@ ostream &operator<<( ostream &out, const NameInst &nameInst );
  * characters with escapes and options interpreted. Also null terminates the
  * string. Though this null termination should not be relied on for
  * interpreting literals in the parser because the string may contain \0 */
-char *prepareLitString( const InputLoc &loc, char *data, long length, 
+char *prepareLitString( const InputLoc &loc, const char *data, long length, 
                long &resLen, bool &caseInsensitive )
 {
        char *resData = new char[length+1];
        caseInsensitive = false;
 
-       char *src = data + 1;
-       char *end = data + length - 1;
+       const char *src = data + 1;
+       const char *end = data + length - 1;
 
        while ( *end != '\'' && *end != '\"' ) {
                if ( *end == 'i' )
@@ -91,7 +91,7 @@ FsmAp *VarDef::walk( ParseData *pd )
        NameFrame nameFrame = pd->enterNameScope( true, 1 );
 
        /* Recurse on the expression. */
-       FsmAp *rtnVal = joinOrLm->walk( pd );
+       FsmAp *rtnVal = machineDef->walk( pd );
        
        /* Do the tranfer of local error actions. */
        LocalErrDictEl *localErrDictEl = pd->localErrDict.find( name );
@@ -103,7 +103,7 @@ FsmAp *VarDef::walk( ParseData *pd )
        /* If the expression below is a join operation with multiple expressions
         * then it just had epsilon transisions resolved. If it is a join
         * with only a single expression then run the epsilon op now. */
-       if ( joinOrLm->type == JoinOrLm::JoinType && joinOrLm->join->exprList.length() == 1 )
+       if ( machineDef->type == MachineDef::JoinType && machineDef->join->exprList.length() == 1 )
                rtnVal->epsilonOp();
 
        /* We can now unset entry points that are not longer used. */
@@ -125,11 +125,11 @@ void VarDef::makeNameTree( const InputLoc &loc, ParseData *pd )
        NameInst *prevNameInst = pd->curNameInst;
        pd->curNameInst = pd->addNameInst( loc, name, false );
 
-       if ( joinOrLm->type == JoinOrLm::LongestMatchType )
+       if ( machineDef->type == MachineDef::LongestMatchType )
                pd->curNameInst->isLongestMatch = true;
 
        /* Recurse. */
-       joinOrLm->makeNameTree( pd );
+       machineDef->makeNameTree( pd );
 
        /* The name scope ends, pop the name instantiation. */
        pd->curNameInst = prevNameInst;
@@ -141,7 +141,7 @@ void VarDef::resolveNameRefs( ParseData *pd )
        NameFrame nameFrame = pd->enterNameScope( true, 1 );
 
        /* Recurse. */
-       joinOrLm->resolveNameRefs( pd );
+       machineDef->resolveNameRefs( pd );
        
        /* The name scope ends, pop the name instantiation. */
        pd->popNameScope( nameFrame );
@@ -229,6 +229,7 @@ void LongestMatch::makeActions( ParseData *pd )
        InputLoc loc;
        loc.line = 1;
        loc.col = 1;
+       loc.fileName = "NONE";
 
        /* Create the error action. */
        InlineList *il6 = new InlineList;
@@ -524,7 +525,7 @@ FsmAp *LongestMatch::walk( ParseData *pd )
        return rtnVal;
 }
 
-FsmAp *JoinOrLm::walk( ParseData *pd )
+FsmAp *MachineDef::walk( ParseData *pd )
 {
        FsmAp *rtnVal = 0;
        switch ( type ) {
@@ -534,11 +535,16 @@ FsmAp *JoinOrLm::walk( ParseData *pd )
        case LongestMatchType:
                rtnVal = longestMatch->walk( pd );
                break;
+       case LengthDefType:
+               condData->lastCondKey.increment();
+               rtnVal = new FsmAp();
+               rtnVal->concatFsm( condData->lastCondKey );
+               break;
        }
        return rtnVal;
 }
 
-void JoinOrLm::makeNameTree( ParseData *pd )
+void MachineDef::makeNameTree( ParseData *pd )
 {
        switch ( type ) {
        case JoinType:
@@ -547,10 +553,12 @@ void JoinOrLm::makeNameTree( ParseData *pd )
        case LongestMatchType:
                longestMatch->makeNameTree( pd );
                break;
+       case LengthDefType:
+               break;
        }
 }
 
-void JoinOrLm::resolveNameRefs( ParseData *pd )
+void MachineDef::resolveNameRefs( ParseData *pd )
 {
        switch ( type ) {
        case JoinType:
@@ -559,6 +567,8 @@ void JoinOrLm::resolveNameRefs( ParseData *pd )
        case LongestMatchType:
                longestMatch->resolveNameRefs( pd );
                break;
+       case LengthDefType:
+               break;
        }
 }
 
@@ -1439,7 +1449,7 @@ FsmAp *FactorWithRep::walk( ParseData *pd )
                retFsm = factorWithRep->walk( pd );
                if ( retFsm->startState->isFinState() ) {
                        warning(loc) << "applying plus operator to a machine that "
-                                       "accpets zero length word" << endl;
+                                       "accepts zero length word" << endl;
                }
 
                /* Need a duplicated for the star end. */
@@ -2012,7 +2022,7 @@ FsmAp *ReItem::walk( ParseData *pd, RegExpr *rootRegex )
        if ( star ) {
                if ( rtnVal->startState->isFinState() ) {
                        warning(loc) << "applying kleene star to a machine that "
-                                       "accpets zero length word" << endl;
+                                       "accepts zero length word" << endl;
                }
 
                rtnVal->starOp();