| e8555c89 Andy McCall |
1 |
#ifndef TCLPARSER_HH |
| 2 |
#define TCLPARSER_HH |
| 3 |
|
| 4 |
#include "tcl.hh" |
| 5 |
|
| 6 |
#include <cstdint> |
| 7 |
#include <span> |
| 8 |
#include <string> |
| 9 |
#include <string_view> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
#define DEBUG_TCLPARSER 0 |
| 13 |
|
| 14 |
class TclParser |
| 15 |
{ |
| 16 |
public: |
| 17 |
|
| 18 |
TclParser(Tcl_Interp* interp, std::string_view input); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
[[nodiscard]] const std::string& getColors() const { return colors; } |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
[[nodiscard]] int getLast() const { return last.back(); } |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
[[nodiscard]] static bool isProc(Tcl_Interp* interp, std::string_view str); |
| 40 |
|
| 41 |
private: |
| 42 |
enum ParseType : uint8_t { COMMAND, EXPRESSION, OTHER }; |
| 43 |
|
| 44 |
void parse(std::string parseStr, int offset, ParseType type); |
| 45 |
void printTokens(std::string_view parseStr, int offset, std::span<const Tcl_Token> tokens); |
| 46 |
[[nodiscard]] static ParseType guessSubType(std::span<const Tcl_Token> tokens, size_t i); |
| 47 |
void setColors(std::string_view parseStr, int offset, const char* p, int size, char c); |
| 48 |
|
| 49 |
private: |
| 50 |
Tcl_Interp* interp; |
| 51 |
std::string colors; |
| 52 |
std::vector<int> last; |
| 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 |