openMSX
TclParser.hh
Go to the documentation of this file.
1#ifndef TCLPARSER_HH
2#define TCLPARSER_HH
3
4#include <span>
5#include <string>
6#include <string_view>
7#include <vector>
8#include <tcl.h>
9
10#define DEBUG_TCLPARSER 0
11
13{
14public:
16 TclParser(Tcl_Interp* interp, std::string_view input);
17
29 [[nodiscard]] const std::string& getColors() const { return colors; }
30
33 [[nodiscard]] int getLast() const { return last.back(); }
34
37 [[nodiscard]] static bool isProc(Tcl_Interp* interp, std::string_view str);
38
39private:
40 enum ParseType { COMMAND, EXPRESSION, OTHER };
41
42 void parse(const char* p, int size, ParseType type);
43 void printTokens(std::span<const Tcl_Token> tokens);
44 [[nodiscard]] static ParseType guessSubType(std::span<const Tcl_Token> tokens, size_t i);
45 void setColors(const char* p, int size, char c);
46
47private:
48 Tcl_Interp* interp;
49 std::string colors;
50 std::string parseStr;
51 std::vector<int> last;
52 int offset = 0;
53
54#if DEBUG_TCLPARSER
55 void DEBUG_PRINT(const std::string& s);
56 int level = 0;
57#else
58 #define DEBUG_PRINT(x)
59#endif
60};
61
62#endif
#define DEBUG_PRINT(x)
Definition TclParser.hh:58
static bool isProc(Tcl_Interp *interp, std::string_view str)
Is the given string a valid Tcl command.
Definition TclParser.cc:228
int getLast() const
Get Start of the last subcommand.
Definition TclParser.hh:33
const std::string & getColors() const
Ouput: a string of equal length of the input command where each character indicates the type of the c...
Definition TclParser.hh:29