openMSX
TclParser.hh
Go to the documentation of this file.
1 #ifndef TCLPARSER_HH
2 #define TCLPARSER_HH
3 
4 #include <string>
5 #include <string_view>
6 #include <vector>
7 #include <tcl.h>
8 
9 #define DEBUG_TCLPARSER 0
10 
11 class TclParser
12 {
13 public:
15  TclParser(Tcl_Interp* interp, std::string_view input);
16 
28  std::string getColors() const { return colors; }
29 
32  int getLast() const { return last.back(); }
33 
36  static bool isProc(Tcl_Interp* interp, std::string_view str);
37 
38 private:
39  enum ParseType { COMMAND, EXPRESSION, OTHER };
40 
41  void parse(const char* p, int size, ParseType type);
42  void printTokens(Tcl_Token* tokens, int numTokens);
43  static ParseType guessSubType(Tcl_Token* tokens, int i);
44  void setColors(const char* p, int size, char c);
45 
46 private:
47  Tcl_Interp* interp;
48  std::string colors;
49  std::string parseStr;
50  std::vector<int> last;
51  int offset;
52 
53 #if DEBUG_TCLPARSER
54  void DEBUG_PRINT(const std::string& s);
55  int level;
56 #else
57  #define DEBUG_PRINT(x)
58 #endif
59 };
60 
61 #endif
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:28
TclParser(Tcl_Interp *interp, std::string_view input)
Input: Tcl interpreter and command to parse.
Definition: TclParser.cc:71
#define DEBUG_PRINT(x)
Definition: TclParser.hh:57
size_t size(std::string_view utf8)
int getLast() const
Get Start of the last subcommand.
Definition: TclParser.hh:32
static bool isProc(Tcl_Interp *interp, std::string_view str)
Is the given string a valid Tcl command.
Definition: TclParser.cc:235