Skip to content

Commit

Permalink
Merge pull request #3 from thamindumk/feature/ast
Browse files Browse the repository at this point in the history
fix issue on a TODO comment of multipartquery grammar
  • Loading branch information
thamindumk authored Aug 28, 2024
2 parents 71f3cbe + 6a86ee4 commit 516cd42
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/query/processor/cypher/astbuilder/ASTBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,30 +301,42 @@ any ASTBuilder::visitOC_SinglePartQuery(CypherParser::OC_SinglePartQueryContext
}


//TODO: try to solve a efficient way

any ASTBuilder::visitOC_MultiPartQuery(CypherParser::OC_MultiPartQueryContext *ctx) {
auto *node = new ASTInternalNode("MULTIPLE_QUERY");
for(CypherParser::OC_WithContext* withElement : ctx->oC_With())
{
size_t const with = withElement->getStart()->getTokenIndex();
for(CypherParser::OC_ReadingClauseContext* element : ctx->oC_ReadingClause())
{
if(element->getStop()->getTokenIndex() < with)
{
node->addElements(any_cast<ASTNode*>(visitOC_ReadingClause(element)));
any ASTBuilder::visitOC_MultiPartQuery(CypherParser::OC_MultiPartQueryContext *ctx) {
auto *node = new ASTInternalNode("MULTI_PART_QUERY");
auto *newNode = new ASTInternalNode("SINGLE_QUERY");

int withIndex = 0;
int readIndex = 0;
int updateIndex = 0;

for (int i = 0; i < ctx->children.size(); i++) {
auto *child = ctx->children[i];
string typeName = typeid(*child).name();
string grammarName = typeName.substr(17);

if (i + 1 < ctx->children.size()) {
auto *nextChild = ctx->children[i + 1];
string nextTypeName = typeid(*nextChild).name();
string nextGrammarName = nextTypeName.substr(17);

if (grammarName == "OC_WithContextE" && nextGrammarName == "OC_SinglePartQueryContextE") {
newNode->addElements(any_cast<ASTNode*>(visitOC_With(ctx->oC_With(withIndex++))));
node->addElements(newNode);
break;
} else if (grammarName == "OC_WithContextE") {
newNode->addElements(any_cast<ASTNode*>(visitOC_With(ctx->oC_With(withIndex++))));
node->addElements(newNode);
newNode = new ASTInternalNode("SINGLE_QUERY");
} else if (grammarName == "OC_ReadingClauseContextE") {
newNode->addElements(any_cast<ASTNode*>(visitOC_ReadingClause(ctx->oC_ReadingClause(readIndex++))));
} else if (grammarName == "OC_UpdatingClauseContextE") {
newNode->addElements(any_cast<ASTNode*>(visitOC_UpdatingClause(ctx->oC_UpdatingClause(updateIndex++))));
}
}
for(CypherParser::OC_UpdatingClauseContext* element : ctx->oC_UpdatingClause())
{
if(element->getStop()->getTokenIndex() < with)
{
node->addElements(any_cast<ASTNode*>(visitOC_UpdatingClause(element)));
}

}
}

node->addElements(any_cast<ASTNode*>(visitOC_SinglePartQuery(ctx->oC_SinglePartQuery())));

return static_cast<ASTNode*>(node);
}

Expand Down

0 comments on commit 516cd42

Please sign in to comment.