diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2022-04-13 00:55:46 -0400 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2022-04-13 00:55:46 -0400 |
commit | 44355ceb4db780b370d148008c5048a5075b3978 (patch) | |
tree | 0ba89a1b3419063c9dca03c8f85a7efe81674965 /tnslc/parse/token.tnsl | |
parent | 8fea53ab8fa095ff7909b5bfbb0c6e94f2206b52 (diff) |
Numeric literals
Diffstat (limited to 'tnslc/parse/token.tnsl')
-rw-r--r-- | tnslc/parse/token.tnsl | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tnslc/parse/token.tnsl b/tnslc/parse/token.tnsl index 668312b..6c402fd 100644 --- a/tnslc/parse/token.tnsl +++ b/tnslc/parse/token.tnsl @@ -250,6 +250,38 @@ ;return false ;/ +/; is_numeric_literal(~{}charp dat) [bool] + /; if (len dat` == 0) + ;return false + ;/ + + ;bool dec = true, flt = false + + ;int i = 0 + + /; if (len dat` > 1) + /; if (dat`{0} == '0' && !is_digit(dat`{1}) && dat`{1} !== '.') + ;dec = false + ;i = 2 + ;/ + ;/ + + /; loop (i < len dat`) [i++] + /; if (!is_digit(dat`{i}) && dec) + /; if (dat`{i} == '.') + /; if (flt || !dec) + ;return false + ;/ + ;flt = true + ;; else if (dec) + ;return false + ;/ + ;/ + ;/ + + ;return true +;/ + /# Get the token_type value for a given string of character points @@ -257,6 +289,10 @@ /; if (len s` > 1) + /; if (is_numeric_literal(s)) + ;return TOKEN_TYPE.LITERAL + ;/ + /; if (is_in_string_list(~PREWORDS, s)) ;return TOKEN_TYPE.PREWORD ;; else if (is_in_string_list(~KEYTYPES, s)) |