32 #include <climits> |
32 #include <climits> |
33 #include "main.h" |
33 #include "main.h" |
34 |
34 |
35 class LexerScanner |
35 class LexerScanner |
36 { |
36 { |
37 public: |
37 public: |
38 struct PositionInfo |
38 struct PositionInfo |
39 { |
39 { |
40 char* pos; |
40 char* pos; |
41 int line; |
41 int line; |
42 }; |
42 }; |
43 |
43 |
44 // Flags for check_string() |
44 // Flags for check_string() |
45 enum |
45 enum |
46 { |
46 { |
47 FCheckWord = (1 << 0), // must be followed by whitespace |
47 FCheckWord = (1 << 0), // must be followed by whitespace |
48 FCheckPeek = (1 << 1), // don't advance cursor |
48 FCheckPeek = (1 << 1), // don't advance cursor |
49 }; |
49 }; |
50 |
50 |
51 static inline bool isSymbolChar (char c, bool allownumbers) |
51 static inline bool isSymbolChar (char c, bool allownumbers) |
52 { |
52 { |
53 if (allownumbers && (c >= '0' && c <= '9')) |
53 if (allownumbers && (c >= '0' && c <= '9')) |
54 return true; |
54 return true; |
55 |
55 |
56 return (c >= 'a' && c <= 'z') || |
56 return (c >= 'a' && c <= 'z') || |
57 (c >= 'A' && c <= 'Z') || |
57 (c >= 'A' && c <= 'Z') || |
58 (c == '_'); |
58 (c == '_'); |
59 } |
59 } |
60 |
60 |
61 LexerScanner (FILE* fp); |
61 LexerScanner (FILE* fp); |
62 ~LexerScanner(); |
62 ~LexerScanner(); |
63 bool getNextToken(); |
63 bool getNextToken(); |
64 String readLine(); |
64 String readLine(); |
65 |
65 |
66 inline const String& getTokenText() const |
66 inline const String& getTokenText() const |
67 { |
67 { |
68 return m_tokenText; |
68 return m_tokenText; |
69 } |
69 } |
70 |
70 |
71 inline int getLine() const |
71 inline int getLine() const |
72 { |
72 { |
73 return m_line; |
73 return m_line; |
74 } |
74 } |
75 |
75 |
76 inline int getColumn() const |
76 inline int getColumn() const |
77 { |
77 { |
78 return m_position - m_lineBreakPosition; |
78 return m_position - m_lineBreakPosition; |
79 } |
79 } |
80 |
80 |
81 inline ETokenType getTokenType() const |
81 inline ETokenType getTokenType() const |
82 { |
82 { |
83 return m_tokenType; |
83 return m_tokenType; |
84 } |
84 } |
85 |
85 |
86 static String getTokenString (ETokenType a); |
86 static String getTokenString (ETokenType a); |
87 |
87 |
88 private: |
88 private: |
89 char* m_data; |
89 char* m_data; |
90 char* m_position; |
90 char* m_position; |
91 char* m_lineBreakPosition; |
91 char* m_lineBreakPosition; |
92 String m_tokenText, |
92 String m_tokenText, |
93 m_lastToken; |
93 m_lastToken; |
94 ETokenType m_tokenType; |
94 ETokenType m_tokenType; |
95 int m_line; |
95 int m_line; |
96 |
96 |
97 bool checkString (const char* c, int flags = 0); |
97 bool checkString (const char* c, int flags = 0); |
98 |
98 |
99 // Yields a copy of the current position information. |
99 // Yields a copy of the current position information. |
100 PositionInfo getPosition() const; |
100 PositionInfo getPosition() const; |
101 |
101 |
102 // Sets the current position based on given data. |
102 // Sets the current position based on given data. |
103 void setPosition (const PositionInfo& a); |
103 void setPosition (const PositionInfo& a); |
104 |
104 |
105 // Skips one character |
105 // Skips one character |
106 void skip(); |
106 void skip(); |
107 |
107 |
108 // Skips many characters |
108 // Skips many characters |
109 void skip (int chars); |
109 void skip (int chars); |
110 }; |
110 }; |
111 |
111 |
112 #endif // BOTC_LEXER_SCANNER_H |
112 #endif // BOTC_LEXER_SCANNER_H |