NFAUNode * WCPattern::parseBackref() { #define is_dig(x) ((x) >= '0' && (x) <= '9') #define to_int(x) ((x) - '0') int ci = curInd; int oldRef = 0, ref = 0; while (ci < pattern.GetLength() && is_dig(pattern[ci]) && (ref < 10 || ref < groupCount)) { oldRef = ref; ref = ref * 10 + to_int(pattern[ci++]); } if (ci == pattern.GetLength()) { oldRef = ref; ++ci; } if (oldRef < 0 || ci <= curInd) { raiseError(); return registerNode(new NFAReferenceUNode(-1)); } curInd = ci; return registerNode(new NFAReferenceUNode(ref)); #undef is_dig #undef to_int }
// start<limit && all strings longer than unitIndex && // length different units at unitIndex StringTrieBuilder::Node * StringTrieBuilder::makeBranchSubNode(int32_t start, int32_t limit, int32_t unitIndex, int32_t length, UErrorCode &errorCode) { if(U_FAILURE(errorCode)) { return NULL; } UChar middleUnits[kMaxSplitBranchLevels]; Node *lessThan[kMaxSplitBranchLevels]; int32_t ltLength=0; while(length>getMaxBranchLinearSubNodeLength()) { // Branch on the middle unit. // First, find the middle unit. int32_t i=skipElementsBySomeUnits(start, unitIndex, length/2); // Create the less-than branch. middleUnits[ltLength]=getElementUnit(i, unitIndex); // middle unit lessThan[ltLength]=makeBranchSubNode(start, i, unitIndex, length/2, errorCode); ++ltLength; // Continue for the greater-or-equal branch. start=i; length=length-length/2; } if(U_FAILURE(errorCode)) { return NULL; } ListBranchNode *listNode=new ListBranchNode(); if(listNode==NULL) { errorCode=U_MEMORY_ALLOCATION_ERROR; return NULL; } // For each unit, find its elements array start and whether it has a final value. int32_t unitNumber=0; do { int32_t i=start; UChar unit=getElementUnit(i++, unitIndex); i=indexOfElementWithNextUnit(i, unitIndex, unit); if(start==i-1 && unitIndex+1==getElementStringLength(start)) { listNode->add(unit, getElementValue(start)); } else { listNode->add(unit, makeNode(start, i, unitIndex+1, errorCode)); } start=i; } while(++unitNumber<length-1); // unitNumber==length-1, and the maxUnit elements range is [start..limit[ UChar unit=getElementUnit(start, unitIndex); if(start==limit-1 && unitIndex+1==getElementStringLength(start)) { listNode->add(unit, getElementValue(start)); } else { listNode->add(unit, makeNode(start, limit, unitIndex+1, errorCode)); } Node *node=registerNode(listNode, errorCode); // Create the split-branch nodes. while(ltLength>0) { --ltLength; node=registerNode( new SplitBranchNode(middleUnits[ltLength], lessThan[ltLength], node), errorCode); } return node; }
// Requires start<limit, // and all strings of the [start..limit[ elements must be sorted and // have a common prefix of length unitIndex. StringTrieBuilder::Node * StringTrieBuilder::makeNode(int32_t start, int32_t limit, int32_t unitIndex, UErrorCode &errorCode) { if(U_FAILURE(errorCode)) { return NULL; } UBool hasValue=FALSE; int32_t value=0; if(unitIndex==getElementStringLength(start)) { // An intermediate or final value. value=getElementValue(start++); if(start==limit) { return registerFinalValue(value, errorCode); } hasValue=TRUE; } Node *node; // Now all [start..limit[ strings are longer than unitIndex. int32_t minUnit=getElementUnit(start, unitIndex); int32_t maxUnit=getElementUnit(limit-1, unitIndex); if(minUnit==maxUnit) { // Linear-match node: All strings have the same character at unitIndex. int32_t lastUnitIndex=getLimitOfLinearMatch(start, limit-1, unitIndex); Node *nextNode=makeNode(start, limit, lastUnitIndex, errorCode); // Break the linear-match sequence into chunks of at most kMaxLinearMatchLength. int32_t length=lastUnitIndex-unitIndex; int32_t maxLinearMatchLength=getMaxLinearMatchLength(); while(length>maxLinearMatchLength) { lastUnitIndex-=maxLinearMatchLength; length-=maxLinearMatchLength; node=createLinearMatchNode(start, lastUnitIndex, maxLinearMatchLength, nextNode); nextNode=registerNode(node, errorCode); } node=createLinearMatchNode(start, unitIndex, length, nextNode); } else { // Branch node. int32_t length=countElementUnits(start, limit, unitIndex); // length>=2 because minUnit!=maxUnit. Node *subNode=makeBranchSubNode(start, limit, unitIndex, length, errorCode); node=new BranchHeadNode(length, subNode); } if(hasValue && node!=NULL) { if(matchNodesCanHaveValues()) { ((ValueNode *)node)->setValue(value); } else { node=new IntermediateValueNode(value, registerNode(node, errorCode)); } } return registerNode(node, errorCode); }
void PackageDataBase::loadNodeEntriesHelper(Node* a_pNode, const boost::filesystem::path& a_Path) { o_assert(boost::filesystem::is_directory(a_Path)); // is p a directory? static_cast<PackageNode*>(a_pNode)->loadAttributes(); boost::filesystem::directory_iterator it(a_Path); boost::filesystem::directory_iterator end; for(;it != end; ++it) { const boost::filesystem::path& dir_path = it->path(); if(NOT(boost::filesystem::is_directory(dir_path))) continue; uint guid = o_invalid_guid; #if o_COMPILER == o_COMPILER_VISUAL_STUDIO # pragma warning(disable:4996) #endif sscanf(dir_path.stem().generic_string().c_str(), "[%x]", &guid); #if o_COMPILER == o_COMPILER_VISUAL_STUDIO # pragma warning(default:4996) #endif if(guid != o_invalid_guid) { Node* pChildNode = createNode(guid, a_pNode); registerNode(pChildNode); loadNodeEntriesHelper(pChildNode, dir_path); } } }
void TestScene12::runPURGE() { // initialize framework PURGEBridge::Ogre_1_7::OgreRenderer::createInstance("./resources/Ogre"); // open window PURGE::Window::create(800, 600); // adjust camera auto camera = PURGE::Camera::create() ->move(PURGE::Vector3(100, 100, 100)) ->setDirection(PURGE::Vector3(-1, -1, -1)); auto task = PURGE::SceneNodeModificationTask::create() ->rotate(PURGE::Degree(360 / 5), PURGE::CoordinateSystem::get().getUpVector()); PURGE::MainTaskGroup::get()->add(task); PURGE::ObjectGroup* groups[ROWS]; for (int i = 0; i < ROWS; i++) { groups[i] = PURGE::ObjectGroup::create(); task->registerNode(groups[i]); } // load & integrate model for (int i = 0; i < ROWS * COLS; i++) { PURGE::ModelNode::create(PURGE::ModelDefinition::load("cube")) ->move(-LEFT(i), UP(i), 0, camera) ->attachTo(groups[i % ROWS]); } // loop runPURGELoop(); }
void Canvas::setRoot(NodePtr pRootNode) { assert(!m_pRootNode); m_pRootNode = dynamic_pointer_cast<CanvasNode>(pRootNode); m_pRootNode->setParent(0, Node::NS_CONNECTED, shared_from_this()); registerNode(m_pRootNode); }
void SamplerApollo::registerJSCell(JSGlobalObject* globalObject, JSCell* cell, size_t size) { WTF::PassRefPtr<SamplerJSCellNode> constructorNode = m_constructorNode.release(); if (UNLIKELY(!samplingNow)) return; uint64_t globalObjectIdentifier = 0; if (globalObject) { BaseSamplerNode* globalObjectSample = getSamplerNodeFor(globalObject); if (globalObjectSample) globalObjectIdentifier = globalObjectSample->identifier(); } PassRefPtr<SamplerJSCellNode> samplerNodeRef = adoptRef(new SamplerJSCellNode(globalObjectIdentifier, cell, size)); SamplerJSCellNode *samplerNode = samplerNodeRef.get(); if (registerNode(samplerNodeRef)) { // cannot check the type because we are called directly from operator new if (constructorNode.get() /* && cell->isObject() */) { JSCell * const cell = constructorNode->impl(); // we don't want to make standard objects to show like Functions // Internal construct for String,Boolean,... inherits directly InternalFunctions if (! (cell && cell->getObject() && cell->getObject()->inherits(&InternalFunction::info) && !cell->getObject()->inherits(&JSFunction::info)) ) { // try to set the name from the function samplerNode->setObjectType(constructorNode->name()); } } } }
NFAUNode * WCPattern::quantifyGroup(NFAUNode * start, NFAUNode * stop, const int gn) { NFAUNode * newNode = NULL; int type = 0; if (curInd < pattern.GetLength()) { wchar_t ch = (curInd + 1 >= pattern.GetLength()) ? USHRT_MAX : pattern[curInd + 1]; switch (pattern[curInd]) { case '*': ++curInd; switch (ch) { case '?': ++curInd; type = 1; break; case '+': ++curInd; type = 2; break; } newNode = registerNode(new NFAGroupLoopPrologueUNode(gn)); newNode->next = registerNode(new NFAGroupLoopUNode(start, MIN_QMATCH, MAX_QMATCH, gn, type)); stop->next = newNode->next; return newNode; case '?': ++curInd; switch (ch) { case '?': ++curInd; type = 1; break; case '+': ++curInd; type = 2; break; } newNode = registerNode(new NFAGroupLoopPrologueUNode(gn)); newNode->next = registerNode(new NFAGroupLoopUNode(start, MIN_QMATCH, 1, gn, type)); stop->next = newNode->next; return newNode; case '+': ++curInd; switch (ch) { case '?': ++curInd; type = 1; break; case '+': ++curInd; type = 2; break; } newNode = registerNode(new NFAGroupLoopPrologueUNode(gn)); newNode->next = registerNode(new NFAGroupLoopUNode(start, 1, MAX_QMATCH, gn, type)); stop->next = newNode->next; return newNode; case '{': { int s, e; if (quantifyCurly(s, e)) { ch = (curInd < pattern.GetLength()) ? pattern[curInd] : USHRT_MAX; switch (ch) { case '?': ++curInd; type = 1; break; case '+': ++curInd; type = 2; break; } newNode = registerNode(new NFAGroupLoopPrologueUNode(gn)); newNode->next = registerNode(new NFAGroupLoopUNode(start, s, e, gn, type)); stop->next = newNode->next; return newNode; } } } } return NULL; }
struct node* createNode(char value) { struct node* temporaryNode = malloc(sizeof(struct node)); temporaryNode->value = value; temporaryNode->next = NULL; registerNode((void*)temporaryNode); return temporaryNode; }
// look behind should interpret everything as a literal (except \\) since the // pattern must have a concrete length NFAUNode* WCPattern::parseBehind(const bool pos, NFAUNode ** end) { CMString t; while (curInd < pattern.GetLength() && pattern[curInd] != ')') { wchar_t ch = pattern[curInd++]; if (ch == '\\') { if (curInd + 1 >= pattern.GetLength()) { raiseError(); return *end = registerNode(new NFACharUNode(' ')); } ch = pattern[curInd++]; } t.AppendChar(ch); } if (curInd >= pattern.GetLength() || pattern[curInd] != ')') raiseError(); else ++curInd; return *end = registerNode(new NFALookBehindUNode(t, pos)); }
//------------------------------------------------------------------------- CCNode* FKCW_UI_Table::createCellNode() { CCNode* pRet = CCNode::create(); pRet->setContentSize(m_tCellSize); registerNode(pRet); return pRet; }
CCNode* CCTableWorker::createCellNode() { CCNode* pRet = CCNode::create(); pRet->setContentSize(m_tCellSize); registerNode(pRet); return pRet; }
void Canvas::registerNode(NodePtr pNode) { addNodeID(pNode); DivNodePtr pDivNode = boost::dynamic_pointer_cast<DivNode>(pNode); if (pDivNode) { for (unsigned i=0; i<pDivNode->getNumChildren(); i++) { registerNode(pDivNode->getChild(i)); } } }
BaseSamplerNode* SamplerApollo::willExecute(ExecState* exec, JSValue function, int32_t& lineNo) { ASSERT(lineNo == 0); if (!seenByProfiler(function)) return 0; JSObject* object = asObject(function); if (object->inherits(&JSFunction::info)) { JSFunction* jsFunction = asFunction(function); // we should take lineno only for non host functions // otherwise we end up with wrong line numbers for functions like // DOM functions, which should have 0 as line number // see bug 2587164 if (!jsFunction->isHostFunction()) lineNo = jsFunction->jsExecutable()->lineNo(); } BaseSamplerNode* samplerNode = getSamplerNodeFor(static_cast<JSCell*>(object)); if (!samplerNode) { // try to inject the object now // as it might have been created while sampling was disabled // this can happen when the sample buffer runs out of space ASSERT(exec->dynamicGlobalObject()); uint64_t globalObjectIdentifier = 0; JSGlobalObject* globalObject = exec->dynamicGlobalObject(); BaseSamplerNode* globalObjectSample = getSamplerNodeFor(globalObject); if (globalObjectSample) globalObjectIdentifier = globalObjectSample->identifier(); PassRefPtr<SamplerJSCellNode> samplerNodeRef = adoptRef(new SamplerJSCellNode(globalObjectIdentifier, static_cast<JSCell*>(object), sizeof(JSObject))); samplerNode = samplerNodeRef.get(); // the sampler might be stopped by the time we get here // and register node will not give an id // in this cases we just fail here if (!registerNode(samplerNodeRef)) return 0; } samplerDidEnterFunction(samplerNode->identifier(), lineNo); // do not increment invocationCount if sampling is paused // however, we called samplerDidEnterFunction because we need to keep the callstack in sync if (UNLIKELY(!samplingNow)) return samplerNode; samplerNode->willExecute(); return samplerNode; }
NFAUNode* WCPattern::parseQuote() { bool done = 0; CMString s; while (!done) { if (curInd >= pattern.GetLength()) { raiseError(); done = 1; } else if (pattern.Mid(curInd, 2) == L"\\E") { curInd += 2; done = 1; } else if (pattern[curInd] == '\\') { s.AppendChar(pattern[++curInd]); ++curInd; } else s.AppendChar(pattern[curInd++]); } if ((flags & WCPattern::CASE_INSENSITIVE) != 0) return registerNode(new NFACIQuoteUNode(s)); return registerNode(new NFAQuoteUNode(s)); }
bool Net_Node::registerNodeDynamic(Net_ClassID cid, Net_Control* con) { eNet_NodeRole role = con->intern->cbNodeRequest_Dynamic ? eNet_RoleProxy : eNet_RoleAuthority; if(con->intern->isServer && role != eNet_RoleAuthority) { errors << "registerNodeDynamic: want to register proxy node on server" << endl; return false; // stop because otherwise we probably would crash } if(!con->intern->isServer && role == eNet_RoleAuthority) { errors << "registerNodeDynamic: want to register authority node on client" << endl; return false; // stop because otherwise we probably would crash } Net_NodeID nid = con->intern->cbNodeRequest_Dynamic ? con->intern->cbNodeRequest_nodeId : con->intern->getUnusedNodeId(); con->intern->cbNodeRequest_Dynamic = false; // only for first node return registerNode(cid, this, nid, role, con->intern); }
void SceneManager::registerGeometryNodes(Node * rootNode) { forEachNodeTopDown<GeometryNode>(rootNode, [this](Node* node){registerNode(node);}); }
bool ContextPrivate::loadSettings( QSettings &pSettings, bool pPartial ) { QSettings CFG( pSettings.fileName(), pSettings.format() ); QList<QSharedPointer<fugio::NodeInterface>> NodeLst; QMap<QUuid,QUuid> NodeMap; QMap<QUuid,QUuid> PinsMap; pSettings.beginGroup( "nodes" ); for( const QString &K : pSettings.childKeys() ) { QString NodeName = K; const QUuid NodeOrigUuid = fugio::utils::string2uuid( K ); const QUuid NodeUuid = ( findNode( NodeOrigUuid ).isNull() ? NodeOrigUuid : QUuid::createUuid() ); const QUuid ControlUuid = fugio::utils::string2uuid( pSettings.value( K ).toString() ); QVariantHash NodeData; if( CFG.childGroups().contains( K ) ) { CFG.beginGroup( K ); NodeName = CFG.value( "name", NodeName ).toString(); if( CFG.childGroups().contains( "settings" ) ) { QStringList VarBse; CFG.beginGroup( "settings" ); loadNodeSettings( CFG, NodeData, VarBse ); CFG.endGroup(); } CFG.endGroup(); } QSharedPointer<fugio::NodeInterface> N = createNode( NodeName, NodeUuid, ControlUuid, NodeData ); if( !N ) { qWarning() << "Can't create node" << NodeName; continue; } NodeLst << N; NodeMap.insert( NodeUuid, NodeOrigUuid ); } pSettings.endGroup(); //------------------------------------------------------------------------- for( QSharedPointer<fugio::NodeInterface> N : NodeLst ) { const QUuid NodeUuid = N->uuid(); const QUuid OrigUuid = NodeMap.value( N->uuid() ); // do this before we registerNode() to give everyone a chance to record the relabel // and look up data if( NodeUuid != OrigUuid ) { emit qobject()->nodeRelabled( OrigUuid, NodeUuid ); } registerNode( N ); pSettings.beginGroup( fugio::utils::uuid2string( OrigUuid ) ); N->loadSettings( pSettings, PinsMap, pPartial ); pSettings.endGroup(); } //------------------------------------------------------------------------- // CFG.beginGroup( "connections" ); // foreach( const QString &NodeDst, CFG.childGroups() ) // { // CF2.beginGroup( NodeDst ); // foreach( const QString &PinDst, CFG.childKeys() ) // { // QStringList SrcList = CFG.value( PinDst ).toString().split( '\\' ); // if( SrcList.size() != 2 ) // { // continue; // } // mConnectionMap.insert( ConnectionPair( SrcList.at( 0 ), SrcList.at( 1 ) ), ConnectionPair( NodeDst, PinDst ) ); // } // CFG.endGroup(); // } // CFG.endGroup(); //------------------------------------------------------------------------- pSettings.beginGroup( "connections" ); for( const QString &G : pSettings.childKeys() ) { QUuid SrcId = PinsMap.value( fugio::utils::string2uuid( G ) ); PinHash::iterator SrcIt = mPinHash.find( SrcId ); if( SrcIt == mPinHash.end() ) { qWarning() << "SRC PIN NOT FOUND" << SrcId; continue; } QSharedPointer<fugio::PinInterface> SrcP = SrcIt.value(); if( SrcP == 0 ) { continue; } QUuid DstId = PinsMap.value( fugio::utils::string2uuid( pSettings.value( G ).toString() ) ); PinHash::iterator DstIt = mPinHash.find( DstId ); if( DstIt == mPinHash.end() ) { qWarning() << "DST PIN NOT FOUND" << DstId; continue; } QSharedPointer<fugio::PinInterface> DstP = DstIt.value(); if( DstP == 0 ) { continue; } connectPins( SrcP->globalId(), DstP->globalId() ); } pSettings.endGroup(); return( true ); }
bool Net_Node::registerNodeUnique(Net_ClassID cid, eNet_NodeRole role, Net_Control* con) { return registerNode(cid, this, UNIQUE_NODE_ID, role, con->intern); }
NFAUNode * WCPattern::parse(const bool inParen, const bool inOr, NFAUNode ** end) { NFAUNode * start, *cur, *next = NULL; CMString t; int grc = groupCount++; bool inv, quo; bool ahead = 0, pos = 0, noncap = 0, indep = 0; unsigned long oldFlags = flags; if (inParen) { if (pattern[curInd] == '?') { ++curInd; --groupCount; if (pattern[curInd] == ':') { noncap = 1; ++curInd; grc = --nonCapGroupCount; } else if (pattern[curInd] == '=') { ++curInd; ahead = 1; pos = 1; } else if (pattern[curInd] == '!') { ++curInd; ahead = 1; pos = 0; } else if (pattern.Mid(curInd, 2) == L"<=") { curInd += 2; return parseBehind(1, end); } else if (pattern.Mid(curInd, 2) == L"<!") { curInd += 2; return parseBehind(0, end); } else if (pattern[curInd] == '>') { ++curInd; indep = 1; } else { bool negate = false, done = false; while (!done) { if (curInd >= pattern.GetLength()) { raiseError(); return NULL; } else if (negate) { switch (pattern[curInd]) { case 'i': flags &= ~WCPattern::CASE_INSENSITIVE; break; case 'd': flags &= ~WCPattern::UNIX_LINE_MODE; break; case 'm': flags &= ~WCPattern::MULTILINE_MATCHING; break; case 's': flags &= ~WCPattern::DOT_MATCHES_ALL; break; case ':': done = true; break; case ')': ++curInd; *end = registerNode(new NFALookBehindUNode(L"", true)); return *end; case '-': default: raiseError(); return NULL; } } else { switch (pattern[curInd]) { case 'i': flags |= WCPattern::CASE_INSENSITIVE; break; case 'd': flags |= WCPattern::UNIX_LINE_MODE; break; case 'm': flags |= WCPattern::MULTILINE_MATCHING; break; case 's': flags |= WCPattern::DOT_MATCHES_ALL; break; case ':': done = true; break; case '-': negate = true; break; case ')': ++curInd; *end = registerNode(new NFALookBehindUNode(L"", true)); return *end; default: raiseError(); return NULL; } } ++curInd; } noncap = 1; grc = --nonCapGroupCount; } if (noncap) cur = start = registerNode(new NFAGroupHeadUNode(grc)); else cur = start = registerNode(new NFASubStartUNode); } else cur = start = registerNode(new NFAGroupHeadUNode(grc)); } else cur = start = registerNode(new NFASubStartUNode); while (curInd < pattern.GetLength()) { wchar_t ch = pattern[curInd++]; next = NULL; if (error) return NULL; switch (ch) { case '^': if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAStartOfLineUNode); else next = registerNode(new NFAStartOfInputUNode); break; case '$': if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAEndOfLineUNode); else next = registerNode(new NFAEndOfInputUNode(0)); break; case '|': --groupCount; cur->next = registerNode(new NFAAcceptUNode); cur = start = registerNode(new NFAOrUNode(start, parse(inParen, 1))); break; case '\\': if (curInd < pattern.GetLength()) { bool eoi = 0; switch (pattern[curInd]) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': next = parseBackref(); break; case 'A': ++curInd; next = registerNode(new NFAStartOfInputUNode); break; case 'B': ++curInd; next = registerNode(new NFAWordBoundaryUNode(0)); break; case 'b': ++curInd; next = registerNode(new NFAWordBoundaryUNode(1)); break; case 'G': ++curInd; next = registerNode(new NFAEndOfMatchUNode); break; case 'Z': eoi = 1; case 'z': ++curInd; next = registerNode(new NFAEndOfInputUNode(eoi)); break; default: t = parseEscape(inv, quo); //printf("inv quo classes { %c %c %s }\n", inv ? 't' : 'f', quo ? 't' : 'f', t.c_str()); if (!quo) { if (t.GetLength() > 1 || inv) { if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACIClassUNode(t, inv)); else next = registerNode(new NFAClassUNode(t, inv)); } else next = registerNode(new NFACharUNode(t[0])); } else next = parseQuote(); } } else raiseError(); break; case '[': if ((flags & WCPattern::CASE_INSENSITIVE) == 0) { NFAClassUNode * clazz = new NFAClassUNode(); CMString s = parseClass(); for (int i = 0; i < (int)s.GetLength(); ++i) clazz->vals[s[i]] = 1; next = registerNode(clazz); } else { NFACIClassUNode * clazz = new NFACIClassUNode(); CMString s = parseClass(); for (int i = 0; i < s.GetLength(); ++i) clazz->vals[to_lower(s[i])] = 1; next = registerNode(clazz); } break; case '.': { bool useN = 1, useR = 1; NFAClassUNode * clazz = new NFAClassUNode(1); if ((flags & WCPattern::UNIX_LINE_MODE) != 0) useR = 0; if ((flags & WCPattern::DOT_MATCHES_ALL) != 0) useN = useR = 0; if (useN) clazz->vals['\n'] = 1; if (useR) clazz->vals['\r'] = 1; next = registerNode(clazz); } break; case '(': { NFAUNode *end, *t1, *t2; t1 = parse(1, 0, &end); if (!t1) raiseError(); else if (t1->isGroupHeadNode() && (t2 = quantifyGroup(t1, end, grc)) != NULL) { cur->next = t2; cur = t2->next; } else { cur->next = t1; cur = end; } } break; case ')': if (!inParen) raiseError(); else if (inOr) { --curInd; cur = cur->next = registerNode(new NFAAcceptUNode); flags = oldFlags; return start; } else { if (ahead) { cur = cur->next = registerNode(new NFAAcceptUNode); flags = oldFlags; return *end = registerNode(new NFALookAheadUNode(start, pos)); } else if (indep) { cur = cur->next = registerNode(new NFAAcceptUNode); flags = oldFlags; return *end = registerNode(new NFAPossessiveQuantifierUNode(this, start, 1, 1)); } else { // capping or noncapping, it doesnt matter *end = cur = cur->next = registerNode(new NFAGroupTailUNode(grc)); next = quantifyGroup(start, *end, grc); if (next) { start = next; *end = next->next; } flags = oldFlags; return start; } } break; case '{': // registered pattern cur->next = parseRegisteredWCPattern(&next); if (cur->next) cur = next; break; case '*': case '+': case '?': // case '}': // case ']': raiseError(); break; default: if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACICharUNode(ch)); else next = registerNode(new NFACharUNode(ch)); break; } if (next) cur = cur->next = quantify(next); } if (inParen) raiseError(); else { if (inOr) cur = cur->next = registerNode(new NFAAcceptUNode); if (end) *end = cur; } flags = oldFlags; if (error) return NULL; return start; }
NFAUNode * WCPattern::quantify(NFAUNode * newNode) { if (curInd < pattern.GetLength()) { wchar_t ch = (curInd + 1 >= pattern.GetLength()) ? USHRT_MAX : pattern[curInd + 1]; switch (pattern[curInd]) { case '*': ++curInd; switch (ch) { case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break; case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break; default: newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, MIN_QMATCH, MAX_QMATCH)); break; } break; case '?': ++curInd; switch (ch) { case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break; case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break; default: newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, MIN_QMATCH, 1)); break; } break; case '+': ++curInd; switch (ch) { case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break; case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break; default: newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, 1, MAX_QMATCH)); break; } break; case '{': int s, e; if (quantifyCurly(s, e)) { ch = (curInd < pattern.GetLength()) ? pattern[curInd] : USHRT_MAX; switch (ch) { case '?': ++curInd; newNode = registerNode(new NFALazyQuantifierUNode(this, newNode, s, e)); break; case '+': ++curInd; newNode = registerNode(new NFAPossessiveQuantifierUNode(this, newNode, s, e)); break; default: newNode = registerNode(new NFAGreedyQuantifierUNode(this, newNode, s, e)); break; } } break; } } return newNode; }