MLIR  20.0.0git
QueryParser.h
Go to the documentation of this file.
1 //===--- QueryParser.h - ----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef MLIR_TOOLS_MLIRQUERY_QUERYPARSER_H
10 #define MLIR_TOOLS_MLIRQUERY_QUERYPARSER_H
11 
12 #include "Matcher/Parser.h"
13 #include "mlir/Query/Query.h"
15 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/LineEditor/LineEditor.h"
18 
19 namespace mlir::query {
20 
21 class QuerySession;
22 
23 class QueryParser {
24 public:
25  // Parse line as a query and return a QueryRef representing the query, which
26  // may be an InvalidQuery.
27  static QueryRef parse(llvm::StringRef line, const QuerySession &qs);
28 
29  static std::vector<llvm::LineEditor::Completion>
30  complete(llvm::StringRef line, size_t pos, const QuerySession &qs);
31 
32 private:
33  QueryParser(llvm::StringRef line, const QuerySession &qs)
34  : line(line), completionPos(nullptr), qs(qs) {}
35 
36  llvm::StringRef lexWord();
37 
38  template <typename T>
39  struct LexOrCompleteWord;
40 
41  QueryRef completeMatcherExpression();
42 
43  QueryRef endQuery(QueryRef queryRef);
44 
45  // Parse [begin, end) and returns a reference to the parsed query object,
46  // which may be an InvalidQuery if a parse error occurs.
47  QueryRef doParse();
48 
49  llvm::StringRef line;
50 
51  const char *completionPos;
52  std::vector<llvm::LineEditor::Completion> completions;
53 
54  const QuerySession &qs;
55 };
56 
57 } // namespace mlir::query
58 
59 #endif // MLIR_TOOLS_MLIRQUERY_QUERYPARSER_H
static QueryRef parse(llvm::StringRef line, const QuerySession &qs)
static std::vector< llvm::LineEditor::Completion > complete(llvm::StringRef line, size_t pos, const QuerySession &qs)
llvm::IntrusiveRefCntPtr< Query > QueryRef
Definition: Query.h:36