From 2ec675a320a8073eedebca60e661ab1e340e3ada Mon Sep 17 00:00:00 2001 From: Slendi Date: Fri, 1 Aug 2025 03:18:14 +0300 Subject: [PATCH] Update lexer to allow ' in numbers Signed-off-by: Slendi --- samples/disks.dcfg | 2 +- src/dcfg.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/disks.dcfg b/samples/disks.dcfg index ebd55ff..c8371e7 100644 --- a/samples/disks.dcfg +++ b/samples/disks.dcfg @@ -8,6 +8,6 @@ fn lib = { partitions = { automount = [ 'boot' 'root' ] swap.enable = true - swap.size = 2g + swap.size = 2_000_000_000 } } diff --git a/src/dcfg.c b/src/dcfg.c index 9c3736d..eaff302 100644 --- a/src/dcfg.c +++ b/src/dcfg.c @@ -76,7 +76,7 @@ int64_t dcfg_strtoll(const char *s, char **end, int base) size_t w = 0; for (size_t r = 0; r < n && s[r]; ++r) - if (s[r] != '_') + if (s[r] != '_' && s[r] != '\'') clean[w++] = s[r]; clean[w] = '\0'; @@ -87,7 +87,7 @@ int64_t dcfg_strtoll(const char *s, char **end, int base) size_t consumed = (size_t)(tmp_end - clean); size_t i = 0, c = 0; while (i < n && c < consumed) { - if (s[i] != '_') + if (s[i] != '_' && s[i] != '\'') ++c; ++i; } @@ -110,7 +110,7 @@ double dcfg_strtod(char const *s, char **end) size_t w = 0; for (size_t r = 0; r < n && s[r]; ++r) - if (s[r] != '_') + if (s[r] != '_' && s[r] != '\'') clean[w++] = s[r]; clean[w] = '\0'; @@ -121,7 +121,7 @@ double dcfg_strtod(char const *s, char **end) size_t consumed = (size_t)(tmp_end - clean); size_t i = 0, c = 0; while (i < n && c < consumed) { - if (s[i] != '_') + if (s[i] != '_' && s[i] != '\'') ++c; ++i; } @@ -573,12 +573,12 @@ static Token lex_number(Lexer *lx) int start = lx->offset; bool real = false; - while (isdigit_cp(lx->ch) || lx->ch == '_') + while (isdigit_cp(lx->ch) || lx->ch == '_' || lx->ch == '\'') lex_advance(lx); if (lx->ch == '.') { real = true; lex_advance(lx); - while (isdigit_cp(lx->ch) || lx->ch == '_') + while (isdigit_cp(lx->ch) || lx->ch == '_' || lx->ch == '\'') lex_advance(lx); } return make_token(