From d04344e9ff243bcf71f5b58f61e4bc99c28425cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Thu, 16 May 2024 17:16:01 +0200 Subject: [PATCH] [internal] fix incorrect source tracking when reaching end of multiline expresssion --- anselme/parser/Source.lua | 4 ++-- anselme/parser/expression/primary/init.lua | 3 +++ anselme/parser/expression/secondary/init.lua | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/anselme/parser/Source.lua b/anselme/parser/Source.lua index bedb03e..0b0475a 100644 --- a/anselme/parser/Source.lua +++ b/anselme/parser/Source.lua @@ -12,10 +12,10 @@ Source = class { self.line = line self.position = position end, - increment = function(self, n, ...) + increment = function(self, n) self.position = self.position + n end, - increment_line = function(self, n, ...) + increment_line = function(self, n) self.line = self.line + n end, count = function(self, capture, ...) diff --git a/anselme/parser/expression/primary/init.lua b/anselme/parser/expression/primary/init.lua index c617758..7629713 100644 --- a/anselme/parser/expression/primary/init.lua +++ b/anselme/parser/expression/primary/init.lua @@ -36,6 +36,7 @@ return { -- returns exp, rem if expression found -- returns nil if no expression found search = function(self, source, options, str) + local start_source = source:clone() str = source:consume_leading_whitespace(options, str) -- if there is a comment, restart the parsing after the comment ends local c, c_rem = comment:search(source, options, str) @@ -45,5 +46,7 @@ return { local exp, rem = primary:search(source, options, str) if exp then return exp, rem end end + -- nothing found, revert state change + source:set(start_source) end } diff --git a/anselme/parser/expression/secondary/init.lua b/anselme/parser/expression/secondary/init.lua index a18d647..59a09ff 100644 --- a/anselme/parser/expression/secondary/init.lua +++ b/anselme/parser/expression/secondary/init.lua @@ -51,7 +51,8 @@ return { -- returns exp, rem if expression found -- returns nil if no expression found search = function(self, source, options, str, current_priority, primary) - str = source:consume_leading_whitespace( options,str) + local start_source = source:clone() + str = source:consume_leading_whitespace(options, str) -- if there is a comment, restart the parsing after the comment ends local c, c_rem = comment:search(source, options, str) if c then @@ -64,5 +65,7 @@ return { local exp, rem = secondary:search(source, options, str, current_priority, primary) if exp then return exp, rem end end + -- nothing found, revert state change + source:set(start_source) end }