aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-11-10 00:15:22 +0100
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-11-10 00:15:22 +0100
commit6abc1299927860a3d433119c9632cf780ac79c7b (patch)
tree131b10de1ea60bebace017d9500a31498a61035a /src/parser.c
parent427c9da3281950f3e37011e31b30985332c95345 (diff)
rewrote number parsing: convert only completely parsed numbers
* We are now buffering until the end of the number constant before converting it to an integer or float. * This way, the integer part of a floating point number does not necessarily have to fit into an teco_int_t -- floats can approximate very large numbers. When detecting a floating point number, we're parsing into floats from the very beginning. The behavior has been compared with Lua 5.4 and a test case has been added. * Also, integers constants are now checked for overflows. Otherwise, constants could be arbitrarily long and the result would be unpredictable. Operations on integers are still not checked for overflows, though, since you might want to rely on it, e.g. for overlapping integers. But that might actually be pretty useless, especially with signed integers, so we might want to change that in the future. * Having both overflow checks and increased floating point constant range is the reason we cannot practically immediately parse into a number, not even if we kept both an integer and float accumulator at the same time. * Also fixes a memory corruption issue that existed since 4aa2b717f9e050783b567540d9bb0193d692e3e9. You must emit undo tokens for fields in state machines only if ctx->parent.must_undo, i.e. if the state machine is not temporary as during a macro call. A test case has been added.
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c
index 231ad3e..28f6fd8 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -402,6 +402,7 @@ void
teco_machine_main_clear(teco_machine_main_t *ctx)
{
teco_goto_table_clear(&ctx->goto_table);
+ teco_string_clear(&ctx->number.value);
teco_string_clear(&ctx->expectstring.string);
teco_machine_stringbuilding_clear(&ctx->expectstring.machine);
teco_string_clear(&ctx->goto_label);