@@ -134,29 +134,44 @@ bool DILLexer::Is_Word(std::string::iterator start, uint32_t& length) {
134134 return false ;
135135}
136136
137+ void DILLexer::ConsumeNumberBody (uint32_t &length, char &prev_ch) {
138+ while (m_cur_pos != m_expr.end () &&
139+ (Is_Digit (*m_cur_pos) || Is_Letter (*m_cur_pos) || *m_cur_pos == ' _' )) {
140+ prev_ch = *m_cur_pos;
141+ length++;
142+ m_cur_pos++;
143+ }
144+ }
145+
137146bool DILLexer::Is_Number (std::string::iterator start, uint32_t & length,
138147 dil::NumberKind& kind) {
139-
140- if (Is_Digit (*start)) {
141- while (m_cur_pos != m_expr.end () && Is_Digit (*m_cur_pos)) {
148+ char prev_ch = 0 ;
149+ kind = dil::NumberKind::eInteger;
150+ if (*start == ' .' ) {
151+ auto next_pos = start + 1 ;
152+ if (next_pos == m_expr.end () || !Is_Digit (*next_pos))
153+ return false ;
154+ }
155+ if (Is_Digit (*start) || *start == ' .' ) {
156+ ConsumeNumberBody (length, prev_ch);
157+ // We're not at the end of the string, and we should be looking at a '.'
158+ if (*m_cur_pos == ' .' ) {
159+ kind = dil::NumberKind::eFloat;
160+ prev_ch = *m_cur_pos;
142161 length++;
143162 m_cur_pos++;
163+ ConsumeNumberBody (length, prev_ch);
144164 }
145- if (m_cur_pos == m_expr.end () || (*m_cur_pos != ' .' )) {
146- kind = dil::NumberKind::eInteger;
147- return true ;
148- }
149- // We're not at the end of the string, and we should be looking at a '.'
150- if (*m_cur_pos == ' .' ) {
165+ // Check the exponent part
166+ if ((*m_cur_pos == ' -' || *m_cur_pos == ' +' ) &&
167+ (prev_ch == ' E' || prev_ch == ' e' || prev_ch == ' P' ||
168+ prev_ch == ' p' )) {
169+ prev_ch = *m_cur_pos;
151170 length++;
152171 m_cur_pos++;
153- while (m_cur_pos != m_expr.end () && Is_Digit (*m_cur_pos)) {
154- length++;
155- m_cur_pos++;
156- }
157- kind = dil::NumberKind::eFloat;
158- return true ;
172+ ConsumeNumberBody (length, prev_ch);
159173 }
174+ return true ;
160175 }
161176 return false ;
162177}
0 commit comments