Skip to content

Commit 5aa6da4

Browse files
committed
Minor parser header cleanup
1 parent 8516a9e commit 5aa6da4

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

mlir/lib/Tools/mlir-query/Matcher/Parser.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ bool Parser::parseMatcherArgs(bool isBuilder, std::vector<ParserValue> &args,
362362

363363
if (!args.empty()) {
364364
// We must find a , token to continue.
365-
// TODO: use a function consumeCommaToken()
366365
TokenInfo commaToken = tokenizer->consumeNextToken();
367366
if (commaToken.kind != TokenInfo::TK_Comma) {
368367
error->addError(commaToken.range, error->ET_ParserNoComma)
@@ -382,15 +381,13 @@ bool Parser::parseMatcherArgs(bool isBuilder, std::vector<ParserValue> &args,
382381
return false;
383382
}
384383

385-
// TODO: use a function consumeIdentToken()
386384
TokenInfo identToken = tokenizer->consumeNextToken();
387385
if (identToken.kind != TokenInfo::TK_Ident) {
388386
error->addError(nameToken.range, error->ET_ParserFailedToBuildMatcher)
389387
<< nameToken.text;
390388
return false;
391389
}
392390

393-
// TODO: set them together with a helper function.
394391
argValue.text = identToken.text;
395392
argValue.range = identToken.range;
396393

@@ -403,7 +400,6 @@ bool Parser::parseMatcherArgs(bool isBuilder, std::vector<ParserValue> &args,
403400
return false;
404401
}
405402
} else {
406-
// TODO: set them together with a helper function.
407403
argValue.text = tokenizer->peekNextToken().text;
408404
argValue.range = tokenizer->peekNextToken().range;
409405
if (!parseExpressionImpl(&argValue.value)) {

mlir/lib/Tools/mlir-query/Matcher/Parser.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
//
99
// Simple matcher expression parser.
1010
//
11-
// The parser understands matcher expressions of the form:
12-
// matcherName(Arg0, Arg1, ..., ArgN)
13-
// as well as simple types like strings.
14-
// The parser does not know how to process the matchers. It delegates this task
15-
// to a Sema object received as an argument.
11+
// This file contains the Parser class, which is responsible for parsing
12+
// expressions in a specific format: matcherName(Arg0, Arg1, ..., ArgN). The
13+
// parser can also interpret simple types, like strings.
1614
//
17-
// Grammar for the expressions supported:
15+
// The actual processing of the matchers is handled by a Sema object that is
16+
// provided to the parser.
17+
//
18+
// The grammar for the supported expressions is as follows:
1819
// <Expression> := <StringLiteral> | <MatcherExpression>
1920
// <StringLiteral> := "quoted string"
2021
// <MatcherExpression> := <MatcherName>(<ArgumentList>)
@@ -54,10 +55,6 @@ class Parser {
5455
Diagnostics *error) = 0;
5556

5657
// Look up a matcher by name in the matcher name found by the parser.
57-
// nameRange is the location of the name in the matcher source, useful for
58-
// error reporting. Returns the matcher constructor, or
59-
// optional<MatcherCtor>() if an error occurred. In that case, error will
60-
// contain a description of the error.
6158
virtual std::optional<MatcherCtor>
6259
lookupMatcherCtor(llvm::StringRef matcherName) = 0;
6360

@@ -76,7 +73,8 @@ class Parser {
7673
getMatcherCompletions(llvm::ArrayRef<ArgKind> acceptedTypes);
7774
};
7875

79-
// Sema implementation that uses the matcher registry to process the tokens.
76+
// RegistrySema class - an implementation of the Sema interface that uses the
77+
// matcher registry to process tokens.
8078
class RegistrySema : public Parser::Sema {
8179
public:
8280
~RegistrySema() override;
@@ -105,8 +103,8 @@ class Parser {
105103

106104
using NamedValueMap = llvm::StringMap<VariantValue>;
107105

108-
// Parse a matcher expression. The caller takes ownership of the DynMatcher
109-
// object returned.
106+
// Methods to parse a matcher expression and return a DynMatcher object,
107+
// transferring ownership to the caller.
110108
static std::optional<DynMatcher>
111109
parseMatcherExpression(llvm::StringRef &matcherCode, Sema *sema,
112110
const NamedValueMap *namedValues, Diagnostics *error);
@@ -120,7 +118,7 @@ class Parser {
120118
return parseMatcherExpression(matcherCode, nullptr, error);
121119
}
122120

123-
/// Parse an expression. Parses any expression supported by this parser.
121+
// Methods to parse any expression supported by this parser.
124122
static bool parseExpression(llvm::StringRef &code, Sema *sema,
125123
const NamedValueMap *namedValues,
126124
VariantValue *value, Diagnostics *error);
@@ -134,7 +132,7 @@ class Parser {
134132
return parseExpression(code, nullptr, value, error);
135133
}
136134

137-
/// Complete an expression at the given offset.
135+
// Methods to complete an expression at a given offset.
138136
static std::vector<MatcherCompletion>
139137
completeExpression(llvm::StringRef &code, unsigned completionOffset,
140138
Sema *sema, const NamedValueMap *namedValues);
@@ -156,8 +154,6 @@ class Parser {
156154
Parser(CodeTokenizer *tokenizer, Sema *sema, const NamedValueMap *namedValues,
157155
Diagnostics *error);
158156

159-
bool parseID(std::string &id);
160-
161157
bool parseExpressionImpl(VariantValue *value);
162158

163159
bool buildAndValidateMatcher(std::vector<ParserValue> &args, MatcherCtor ctor,
@@ -173,6 +169,7 @@ class Parser {
173169
const TokenInfo &openToken,
174170
std::optional<MatcherCtor> ctor,
175171
VariantValue *value);
172+
176173
bool parseIdentifierPrefixImpl(VariantValue *value);
177174

178175
void addCompletion(const TokenInfo &compToken,

0 commit comments

Comments
 (0)