From ee837757591fb1f5f4eecd324fd2a8fa56d3a8e4 Mon Sep 17 00:00:00 2001 From: Ribhav Jain Date: Wed, 29 Jul 2020 06:47:02 +0000 Subject: SERVER-49831 Add support for base MatchExpression in grammar --- src/mongo/db/cst/bson_lexer.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/mongo/db/cst/bson_lexer.cpp') diff --git a/src/mongo/db/cst/bson_lexer.cpp b/src/mongo/db/cst/bson_lexer.cpp index 6e8c4088615..a5eaebcd9aa 100644 --- a/src/mongo/db/cst/bson_lexer.cpp +++ b/src/mongo/db/cst/bson_lexer.cpp @@ -291,7 +291,27 @@ void BSONLexer::tokenize(BSONElement elem, bool includeFieldName) { } } -BSONLexer::BSONLexer(std::vector pipeline) { +BSONLexer::BSONLexer(BSONObj obj, PipelineParserGen::token_type startingToken) { + + _tokens.emplace_back(startingToken, getNextLoc()); + _tokens.emplace_back(PipelineParserGen::token::START_OBJECT, getNextLoc()); + for (auto&& elem : obj) { + // Include field names in the object. + tokenize(elem, true); + } + _tokens.emplace_back(PipelineParserGen::token::END_OBJECT, getNextLoc()); + + // Final token must indicate EOF. + _tokens.emplace_back(PipelineParserGen::make_END_OF_FILE(getNextLoc())); + + // Reset the position to use in yylex(). + _position = 0; +}; + +BSONLexer::BSONLexer(std::vector pipeline, + PipelineParserGen::token_type startingToken) { + + _tokens.emplace_back(startingToken, getNextLoc()); _tokens.emplace_back(PipelineParserGen::token::START_ARRAY, getNextLoc()); for (auto&& elem : pipeline) { // Don't include field names for stages of the pipeline (aka indexes of the pipeline array). -- cgit v1.2.1