Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse complete SPARQL queries using ANTLR #790

Merged
merged 28 commits into from
Sep 16, 2022

Conversation

Qup42
Copy link
Member

@Qup42 Qup42 commented Sep 15, 2022

Complete the last two pieces of query parsing in ANTLR: ConstructQuery and Query.

TODO:

  • Tests
  • resolve the introduced Todos

src/parser/SparqlParser.cpp Outdated Show resolved Hide resolved
@Qup42
Copy link
Member Author

Qup42 commented Sep 15, 2022

SparqlParser::SparqlParser(const string& query) : lexer_(query), query_(query) {
LOG(DEBUG) << "Parsing " << query << std::endl;
}

The lexer is now only used in SparqlParser::parseFilter and SparqlParser::parseFilter. The creation of the lexer could maybe be postponed to a later time.

Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already looking really nice. I have some suggestions considering the code structure and better comments as usual, but it looks really nice that the old Parser is now almost completely gone.

src/parser/ParsedQuery.cpp Show resolved Hide resolved
src/parser/ParsedQuery.cpp Outdated Show resolved Hide resolved
src/parser/ParsedQuery.cpp Outdated Show resolved Hide resolved
src/parser/SparqlParser.cpp Outdated Show resolved Hide resolved
src/parser/SparqlParser.cpp Outdated Show resolved Hide resolved
src/parser/sparqlParser/SparqlQleverVisitor.cpp Outdated Show resolved Hide resolved
src/parser/sparqlParser/SparqlQleverVisitor.h Show resolved Hide resolved
test/ParseExceptionTest.cpp Show resolved Hide resolved
test/SparqlAntlrParserTest.cpp Show resolved Hide resolved
test/SparqlAntlrParserTest.cpp Show resolved Hide resolved
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor suggestions, and of course the stuff that remains from my last review.

src/parser/ParsedQuery.cpp Outdated Show resolved Hide resolved
src/parser/SparqlParser.cpp Outdated Show resolved Hide resolved
src/parser/SparqlParser.cpp Outdated Show resolved Hide resolved
src/parser/SparqlParser.h Outdated Show resolved Hide resolved
src/parser/SparqlParserHelpers.h Outdated Show resolved Hide resolved
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only very small suggestions remain, this will soon be ready to merge.

src/parser/ParsedQuery.cpp Outdated Show resolved Hide resolved
src/parser/ParsedQuery.cpp Outdated Show resolved Hide resolved
src/parser/ParsedQuery.cpp Show resolved Hide resolved
src/parser/ParsedQuery.h Outdated Show resolved Hide resolved
src/parser/ParsedQuery.h Outdated Show resolved Hide resolved
src/parser/ParsedQuery.h Outdated Show resolved Hide resolved
src/parser/SelectClause.h Show resolved Hide resolved
test/SparqlAntlrParserTest.cpp Outdated Show resolved Hide resolved
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The very last changes, mostly it's about making the e2e tests pass again, then we can still merge this today.

e2e/scientists_queries.yaml Show resolved Hide resolved
Comment on lines +344 to +348
auto addVariable = [&variable](auto& clause) {
clause.addVisibleVariable(variable);
};
std::visit(addVariable, _clause);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto addVariable = [&variable](auto& clause) {
clause.addVisibleVariable(variable);
};
std::visit(addVariable, _clause);
}
std::visit(&parsedQuery::ClauseBase::addvisibleVariable, _clause);
}

I thought I suggested this before, but it seems like I didn't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did but i had to revert it because it does not work. The lambda also captures the variable that is passed to addVisibleVariable.

src/parser/SelectClause.cpp Show resolved Hide resolved
@Qup42
Copy link
Member Author

Qup42 commented Sep 16, 2022

Another thing that may be worth testing for in the future is the visible variables. They are now in every parsed query and use in quite some places. I'm currently trying if that can be done easily.

Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much. I think we can now merge it and move the rest to another PR.

@joka921 joka921 marked this pull request as ready for review September 16, 2022 23:56
@joka921 joka921 changed the title Parse SPARQL QL Queries in ANTLR Parse complete SPARQL queries using ANTLR Sep 16, 2022
@joka921 joka921 merged commit a1e0e78 into ad-freiburg:master Sep 16, 2022
hannahbast pushed a commit that referenced this pull request Sep 18, 2022
The ANTLR based parser now parses the complete query string into a `ParsedQuery`. The only thing that is till done via the old parser are FILTERs. Also add many checks for invariants of a valid SPARQL query into the `ParsedQuery` class and improve the unit tests for the parsing.
@Qup42 Qup42 deleted the ANTLR/constructQuery branch January 23, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants