diff --git a/anselme/parser/expression/comment.lua b/anselme/parser/expression/comment.lua index 55ce64d..20c2dc3 100644 --- a/anselme/parser/expression/comment.lua +++ b/anselme/parser/expression/comment.lua @@ -3,20 +3,20 @@ local primary = require("anselme.parser.expression.primary.primary") local comment comment = primary { match = function(self, str) - return str:match("^%(%(") + return str:match("^%/%*") end, parse = function(self, source, str, limit_pattern) - local rem = source:consume(str:match("^(%(%()(.*)$")) + local rem = source:consume(str:match("^(%/%*)(.*)$")) local content_list = {} - while not rem:match("^%)%)") do + while not rem:match("^%*%/") do local content - content, rem = rem:match("^([^%(%)]*)(.-)$") + content, rem = rem:match("^([^%/%*]*)(.-)$") -- cut the text prematurely at limit_pattern if relevant if limit_pattern and content:match(limit_pattern) then local pos = content:match("()"..limit_pattern) -- limit_pattern can contain $, so can't directly extract with captures - content, rem = source:count(content:sub(1, pos-1)), ("))%s%s"):format(content:sub(pos), rem) + content, rem = source:count(content:sub(1, pos-1)), ("*/%s%s"):format(content:sub(pos), rem) source:increment(-2) else source:count(content) @@ -25,30 +25,30 @@ comment = primary { table.insert(content_list, content) -- nested comment - if rem:match("^%(%(") then + if rem:match("^%/%*") then local subcomment subcomment, rem = comment:parse(source, rem, limit_pattern) - table.insert(content_list, "((") + table.insert(content_list, "/*") table.insert(content_list, subcomment) - table.insert(content_list, "))") + table.insert(content_list, "*/") -- no end token after the comment - elseif not rem:match("^%)%)") then - -- single ) or (, keep on commentin' - if rem:match("^[%)%(]") then + elseif not rem:match("^%*%/") then + -- single * or /, keep on commentin' + if rem:match("^[%*%/]") then local s - s, rem = source:count(rem:match("^([%)%(])(.-)$")) + s, rem = source:count(rem:match("^([%*%/])(.-)$")) table.insert(content_list, s) -- anything other than end-of-line elseif rem:match("[^%s]") then error(("unexpected %q at end of comment"):format(rem), 0) -- consumed everything until end-of-line, close your eyes and imagine the text has been closed else - rem = rem .. "))" + rem = rem .. "*/" end end end - rem = source:consume(rem:match("^(%)%))(.*)$")) + rem = source:consume(rem:match("^(%*%/)(.*)$")) return table.concat(content_list, ""), rem end diff --git a/anselme/stdlib/script_script.lua b/anselme/stdlib/script_script.lua index 1c782ac..e4167b8 100644 --- a/anselme/stdlib/script_script.lua +++ b/anselme/stdlib/script_script.lua @@ -51,7 +51,7 @@ return [[ s.current checkpoint = () @s! -((Additionnal helpers)) +/*Additionnal helpers*/ :@$ cycle(l::tuple) :i = 2 i <= l!len ~? diff --git a/test/tests/comment.ans b/test/tests/comment.ans index dd26ad0..a33f92e 100644 --- a/test/tests/comment.ans +++ b/test/tests/comment.ans @@ -1,9 +1,9 @@ -((hey couic + 5)) +/*hey couic + 5*/ -((nested ((comments)) d)) +/*nested /*comments*/ d*/ -2 ((end of line)) +2 /*end of line*/ -((start of line)) 3 +/*start of line*/ 3 -5 + ((middle)) 3 +5 + /*middle*/ 3