src/lexer.cc

changeset 81
071715c17296
parent 79
2425fa6a4f21
child 82
841562f5a32f
equal deleted inserted replaced
80:2ed3430fdd08 81:071715c17296
80 tok.file = file_name; 80 tok.file = file_name;
81 tok.line = sc.get_line(); 81 tok.line = sc.get_line();
82 tok.column = sc.get_column(); 82 tok.column = sc.get_column();
83 tok.type = sc.get_token_type(); 83 tok.type = sc.get_token_type();
84 tok.text = sc.get_token_text(); 84 tok.text = sc.get_token_text();
85 // devf ("Token #%1: %2:%3:%4: %5 (%6)\n", m_tokens.size(),
86 // tok.file, tok.line, tok.column, describe_token (&tok), describe_token_type (tok.type));
85 m_tokens << tok; 87 m_tokens << tok;
86 } 88 }
87 } 89 }
88 90
89 m_token_position = m_tokens.begin() - 1; 91 m_token_position = m_tokens.begin() - 1;
98 if (m_tokens.is_empty()) 100 if (m_tokens.is_empty())
99 return false; 101 return false;
100 102
101 m_token_position++; 103 m_token_position++;
102 104
103 if (is_at_end()) 105 if (is_at_end() || (req != tk_any && get_token_type() != req))
104 return false;
105
106 if (req != tk_any && get_token_type() != req)
107 { 106 {
108 m_token_position = pos; 107 m_token_position = pos;
109 return false; 108 return false;
110 } 109 }
111 110
112 return true; 111 return true;
113 } 112 }
114 113
115 // ============================================================================= 114 // =============================================================================
116 // 115 //
117 void lexer::must_get_next (e_token tok) 116 void lexer::must_get_next (e_token tt)
118 { 117 {
119 if (!get_next()) 118 if (!get_next())
120 error ("unexpected EOF"); 119 error ("unexpected EOF");
121 120
122 must_be (tok); 121 if (tt != tk_any)
122 must_be (tt);
123 } 123 }
124 124
125 // ============================================================================= 125 // =============================================================================
126 // eugh.. 126 // eugh..
127 // 127 //

mercurial