File indexing completed on 2024-05-12 04:39:43

0001 /*
0002     SPDX-FileCopyrightText: 2004 Roberto Raggi <roberto@kdevelop.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef MIPARSER_H
0008 #define MIPARSER_H
0009 
0010 #include <memory>
0011 
0012 #include "mi.h"
0013 #include "milexer.h"
0014 
0015 class QString;
0016 
0017 namespace KDevMI { namespace MI {
0018 
0019 /**
0020 @author Roberto Raggi
0021 */
0022 class MIParser
0023 {
0024 public:
0025     MIParser();
0026     ~MIParser();
0027 
0028     std::unique_ptr<Record> parse(FileSymbol *file);
0029 
0030 protected: // rules
0031     std::unique_ptr<Record> parseResultOrAsyncRecord();
0032     std::unique_ptr<Record> parsePrompt();
0033     std::unique_ptr<Record> parseStreamRecord();
0034 
0035     bool parseResult(Result *&result);
0036     bool parseValue(Value *&value);
0037     bool parseTuple(Value *&value);
0038     bool parseList(Value *&value);
0039 
0040     /** Creates new TupleValue object, writes its address
0041         into *value, parses a comma-separated set of values,
0042         and adds each new value into (*value)->results.
0043         If 'start' and 'end' are not zero, they specify
0044         start and end delimiter of the list.
0045         Parsing stops when we see 'end' character, or, if
0046         'end' is zero, at the end of input.
0047     */
0048     bool parseCSV(TupleValue** value,
0049                   char start = 0, char end = 0);
0050 
0051     /** @overload
0052         Same as above, but writes into existing tuple.
0053     */
0054     bool parseCSV(TupleValue& value,
0055                   char start = 0, char end = 0);
0056 
0057     /** Parses a string literal and returns it. Advances
0058         the lexer past the literal. Processes C escape sequences
0059         in the string.
0060         @pre lex->lookAhead(0) == Token_string_literal
0061     */
0062     QString parseStringLiteral();
0063 
0064 private:
0065     MILexer m_lexer;
0066     TokenStream *m_lex = nullptr;
0067 };
0068 
0069 } // end of namespace MI
0070 } // end of namespace KDevMI
0071 
0072 #endif