From ee76cb5b64d86b0edfc556191e6706c6ba4844af Mon Sep 17 00:00:00 2001 From: Kevin Brubeck Unhammer Date: Mon, 28 Aug 2023 14:37:21 +0200 Subject: [PATCH] reparse individual non-parsed words after full sentence mitigates #80 --- src/rtx_processor.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/rtx_processor.cc b/src/rtx_processor.cc index 65532b4..0ff2d61 100644 --- a/src/rtx_processor.cc +++ b/src/rtx_processor.cc @@ -1798,6 +1798,32 @@ RTXProcessor::processGLR(UFILE *out) currentBranch = parseGraph[0]; parseGraph[0]->getChunks(outputQueue, parseGraph[0]->length-1); parseGraph.clear(); + + // We have now parsed input into a tree, and are ready to run + // output rules and do the output. But first: For every chunk + // that didn't get a parse, reparse it disregarding context, so + // we can at least use single-word rules on them. + + for(auto it = outputQueue.begin(); it != outputQueue.end(); ++it) { + Chunk* ch = *it; + if(ch->rule == -1 && !ch->isBlank) { // -1 means didn't get a parse + ParseNode* temp = parsePool.next(); + temp->init(mx, ch); + temp->id = ++newBranchId; + temp->stringVars = variables; + temp->wblankVars = wblank_variables; + temp->chunkVars = vector(varCount, NULL); + checkForReduce(parseGraph, temp); + + list outputQueueReparsed; + parseGraph[0]->getChunks(outputQueueReparsed, parseGraph[0]->length-1); + for(Chunk* ch2 : outputQueueReparsed) { // should be at most one + *it = ch2; + } + parseGraph.clear(); + } + } + outputAll(out); variables = currentBranch->stringVars; wblank_variables = currentBranch->wblankVars;