src/Lexer.h

changeset 91
427eb377d53e
parent 89
029a330a9bef
child 99
44c0c7f31ae8
equal deleted inserted replaced
90:90ab2f2b3dc0 91:427eb377d53e
56 void MustGetNext (EToken tok = tkAny); 56 void MustGetNext (EToken tok = tkAny);
57 void MustGetAnyOf (const List<EToken>& toks); 57 void MustGetAnyOf (const List<EToken>& toks);
58 int GetOneSymbol (const StringList& syms); 58 int GetOneSymbol (const StringList& syms);
59 void TokenMustBe (EToken tok); 59 void TokenMustBe (EToken tok);
60 bool PeekNext (Token* tk = null); 60 bool PeekNext (Token* tk = null);
61 String PeekNextString (int a = 1);
62 String DescribePosition();
63
64 static Lexer* GetCurrentLexer();
61 65
62 inline bool HasValidToken() const 66 inline bool HasValidToken() const
63 { 67 {
64 return (mTokenPosition < mTokens.end() && mTokenPosition >= mTokens.begin()); 68 return (mTokenPosition < mTokens.end() && mTokenPosition >= mTokens.begin());
65 } 69 }
78 inline EToken GetTokenType() const 82 inline EToken GetTokenType() const
79 { 83 {
80 return GetToken()->type; 84 return GetToken()->type;
81 } 85 }
82 86
87 inline void Skip (int a = 1)
88 {
89 mTokenPosition += a;
90 }
91
92 inline int GetPosition()
93 {
94 return mTokenPosition - mTokens.begin();
95 }
96
97 inline void SetPosition (int pos)
98 {
99 mTokenPosition = mTokens.begin() + pos;
100 }
101
83 // If @tok is given, describes the token. If not, describes @tok_type. 102 // If @tok is given, describes the token. If not, describes @tok_type.
84 static inline String DescribeTokenType (EToken toktype) 103 static inline String DescribeTokenType (EToken toktype)
85 { 104 {
86 return DescribeTokenPrivate (toktype, null); 105 return DescribeTokenPrivate (toktype, null);
87 } 106 }
88 107
89 static inline String DescribeToken (Token* tok) 108 static inline String DescribeToken (Token* tok)
90 { 109 {
91 return DescribeTokenPrivate (tok->type, tok); 110 return DescribeTokenPrivate (tok->type, tok);
92 } 111 }
93
94 static Lexer* GetCurrentLexer();
95
96 inline void Skip (int a = 1)
97 {
98 mTokenPosition += a;
99 }
100
101 String PeekNextString (int a = 1);
102 String DescribePosition();
103 112
104 private: 113 private:
105 TokenList mTokens; 114 TokenList mTokens;
106 Iterator mTokenPosition; 115 Iterator mTokenPosition;
107 116

mercurial