MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / ReadNumeral

Method ReadNumeral

LuaParser/src/Lexer/LuaLexer.cpp:427–458  ·  view source on GitHub ↗

LUA_NUMBER */ ** This function is quite liberal in what it accepts, as 'luaO_str2num' ** will reject ill-formed numerals. Roughly, it accepts the following ** pattern: ** ** %d(%x|%.|([Ee][+-]?))* | 0[Xx](%x|%.|([Pp][+-]?))* ** ** The only tricky part is to accept [+-] only after a valid exponent ** mark, to avoid reading '3-4' or '0xe+1' as a single number. ** ** The caller might have already r

Source from the content-addressed store, hash-verified

425** The caller might have already read an initial dot.
426*/
427LuaTokenKind LuaLexer::ReadNumeral() {
428 int first = _reader.GetCurrentChar();
429 const char *expo = "Ee";
430 _reader.SaveAndNext();
431
432 if (first == '0' && _reader.CheckNext2("xX")) /* hexadecimal? */
433 {
434 expo = "Pp";
435 }
436
437 for (;;) {
438 if (_reader.CheckNext2(expo)) /* exponent mark? */
439 {
440 _reader.CheckNext2("-+"); /* optional exponent sign */
441 } else if (lisxdigit(_reader.GetCurrentChar()) || _reader.GetCurrentChar() == '.') /* '%x|%.' */
442 {
443 _reader.SaveAndNext();
444 } else {
445 break;
446 }
447 }
448
449 // fix bug:这里不能使用lislalpha,否则会错误的解析下一个unicode字符
450 if (std::isalpha(_reader.GetCurrentChar())) /* is numeral touching a letter? */
451 {
452 do {
453 _reader.SaveAndNext();
454 } while (std::isalpha(_reader.GetCurrentChar()));
455 }
456
457 return TK_NUMBER;
458}
459
460/*
461** read a sequence '[=*[' or ']=*]', leaving the last bracket. If

Callers

nothing calls this directly

Calls 3

GetCurrentCharMethod · 0.80
SaveAndNextMethod · 0.80
CheckNext2Method · 0.80

Tested by

no test coverage detected