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