src/LexerScanner.h

changeset 115
9be16e1c1e44
parent 112
def56932f938
equal deleted inserted replaced
114:6cbeb9f8350f 115:9be16e1c1e44
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 types: 37 public:
38 struct PositionInfo 38 struct PositionInfo
39 { 39 {
40 char* pos; 40 char* pos;
41 char* line_break_pos;
42 int line; 41 int line;
43 }; 42 };
44 43
45 // Flags for check_string() 44 // Flags for check_string()
46 enum 45 enum
47 { 46 {
48 FCheckWord = (1 << 0), // must be followed by whitespace 47 FCheckWord = (1 << 0), // must be followed by whitespace
49 FCheckPeek = (1 << 1), // don't advance cursor 48 FCheckPeek = (1 << 1), // don't advance cursor
50 }; 49 };
51 50
52 public: 51 static inline bool isSymbolChar (char c, bool allownumbers)
53 static inline bool IsSymbolChar (char c, bool allownumbers)
54 { 52 {
55 if (allownumbers && (c >= '0' && c <= '9')) 53 if (allownumbers && (c >= '0' && c <= '9'))
56 return true; 54 return true;
57 55
58 return (c >= 'a' && c <= 'z') || 56 return (c >= 'a' && c <= 'z') ||
60 (c == '_'); 58 (c == '_');
61 } 59 }
62 60
63 LexerScanner (FILE* fp); 61 LexerScanner (FILE* fp);
64 ~LexerScanner(); 62 ~LexerScanner();
65 bool GetNextToken(); 63 bool getNextToken();
66 String ReadLine(); 64 String readLine();
67 65
68 inline const String& GetTokenText() const 66 inline const String& getTokenText() const
69 { 67 {
70 return mTokenText; 68 return m_tokenText;
71 } 69 }
72 70
73 inline int GetLine() const 71 inline int getLine() const
74 { 72 {
75 return mLine; 73 return m_line;
76 } 74 }
77 75
78 inline int GetColumn() const 76 inline int getColumn() const
79 { 77 {
80 return mPosition - mLineBreakPosition; 78 return m_position - m_lineBreakPosition;
81 } 79 }
82 80
83 inline ETokenType GetTokenType() const 81 inline ETokenType getTokenType() const
84 { 82 {
85 return mTokenType; 83 return m_tokenType;
86 } 84 }
87 85
88 static String GetTokenString (ETokenType a); 86 static String getTokenString (ETokenType a);
89 87
90 private: 88 private:
91 char* mData; 89 char* m_data;
92 char* mPosition; 90 char* m_position;
93 char* mLineBreakPosition; 91 char* m_lineBreakPosition;
94 String mTokenText, 92 String m_tokenText,
95 mLastToken; 93 m_lastToken;
96 ETokenType mTokenType; 94 ETokenType m_tokenType;
97 int mLine; 95 int m_line;
98 96
99 bool CheckString (const char* c, int flags = 0); 97 bool checkString (const char* c, int flags = 0);
100 98
101 // Yields a copy of the current position information. 99 // Yields a copy of the current position information.
102 PositionInfo GetPosition() const; 100 PositionInfo getPosition() const;
103 101
104 // Sets the current position based on given data. 102 // Sets the current position based on given data.
105 void SetPosition (const PositionInfo& a); 103 void setPosition (const PositionInfo& a);
106 104
107 // Skips one character 105 // Skips one character
108 void Skip(); 106 void skip();
109 107
110 // Skips many characters 108 // Skips many characters
111 void Skip (int chars); 109 void skip (int chars);
112 }; 110 };
113 111
114 #endif // BOTC_LEXER_SCANNER_H 112 #endif // BOTC_LEXER_SCANNER_H

mercurial