8
8
//
9
9
// Simple matcher expression parser.
10
10
//
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.
16
14
//
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:
18
19
// <Expression> := <StringLiteral> | <MatcherExpression>
19
20
// <StringLiteral> := "quoted string"
20
21
// <MatcherExpression> := <MatcherName>(<ArgumentList>)
@@ -54,10 +55,6 @@ class Parser {
54
55
Diagnostics *error) = 0;
55
56
56
57
// 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.
61
58
virtual std::optional<MatcherCtor>
62
59
lookupMatcherCtor (llvm::StringRef matcherName) = 0 ;
63
60
@@ -76,7 +73,8 @@ class Parser {
76
73
getMatcherCompletions (llvm::ArrayRef<ArgKind> acceptedTypes);
77
74
};
78
75
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.
80
78
class RegistrySema : public Parser ::Sema {
81
79
public:
82
80
~RegistrySema () override ;
@@ -105,8 +103,8 @@ class Parser {
105
103
106
104
using NamedValueMap = llvm::StringMap<VariantValue>;
107
105
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 .
110
108
static std::optional<DynMatcher>
111
109
parseMatcherExpression (llvm::StringRef &matcherCode, Sema *sema,
112
110
const NamedValueMap *namedValues, Diagnostics *error);
@@ -120,7 +118,7 @@ class Parser {
120
118
return parseMatcherExpression (matcherCode, nullptr , error);
121
119
}
122
120
123
- // / Parse an expression. Parses any expression supported by this parser.
121
+ // Methods to parse any expression supported by this parser.
124
122
static bool parseExpression (llvm::StringRef &code, Sema *sema,
125
123
const NamedValueMap *namedValues,
126
124
VariantValue *value, Diagnostics *error);
@@ -134,7 +132,7 @@ class Parser {
134
132
return parseExpression (code, nullptr , value, error);
135
133
}
136
134
137
- // / Complete an expression at the given offset.
135
+ // Methods to complete an expression at a given offset.
138
136
static std::vector<MatcherCompletion>
139
137
completeExpression (llvm::StringRef &code, unsigned completionOffset,
140
138
Sema *sema, const NamedValueMap *namedValues);
@@ -156,8 +154,6 @@ class Parser {
156
154
Parser (CodeTokenizer *tokenizer, Sema *sema, const NamedValueMap *namedValues,
157
155
Diagnostics *error);
158
156
159
- bool parseID (std::string &id);
160
-
161
157
bool parseExpressionImpl (VariantValue *value);
162
158
163
159
bool buildAndValidateMatcher (std::vector<ParserValue> &args, MatcherCtor ctor,
@@ -173,6 +169,7 @@ class Parser {
173
169
const TokenInfo &openToken,
174
170
std::optional<MatcherCtor> ctor,
175
171
VariantValue *value);
172
+
176
173
bool parseIdentifierPrefixImpl (VariantValue *value);
177
174
178
175
void addCompletion (const TokenInfo &compToken,
0 commit comments