From cd827731ca155f198d26b61a0965469560e1bb34 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sun, 19 Nov 2023 04:01:01 +0800 Subject: make function call args a consistent behavior with table list. --- spec/inputs/whitespace.yue | 23 +++++++++++++++++++++++ spec/outputs/whitespace.lua | 12 ++++++++++++ src/yuescript/stacktraceplus.h | 2 +- src/yuescript/yue_compiler.cpp | 2 +- src/yuescript/yue_parser.cpp | 18 ++++++++++++++---- src/yuescript/yue_parser.h | 4 +++- 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/spec/inputs/whitespace.yue b/spec/inputs/whitespace.yue index 329280f..2655961 100644 --- a/spec/inputs/whitespace.yue +++ b/spec/inputs/whitespace.yue @@ -97,6 +97,29 @@ b( c(one, two, three, four) +d( + one -- one + two -- two + three -- three + four -- four +) + +e( + -> + -> + -> +) +e{ + -> + -> + -> +} +e[ + -> + -> + -> +] + -- v = -> diff --git a/spec/outputs/whitespace.lua b/spec/outputs/whitespace.lua index 1bc4503..0251968 100644 --- a/spec/outputs/whitespace.lua +++ b/spec/outputs/whitespace.lua @@ -77,6 +77,18 @@ end a(one, two, three) b(one, two, three) c(one, two, three, four) +d(one, two, three, four) +e(function() end, function() end, function() end) +e({ + function() end, + function() end, + function() end +}) +e({ + function() end, + function() end, + function() end +}) local v v = function() return a, b, c diff --git a/src/yuescript/stacktraceplus.h b/src/yuescript/stacktraceplus.h index 6025daa..3167ba8 100644 --- a/src/yuescript/stacktraceplus.h +++ b/src/yuescript/stacktraceplus.h @@ -345,7 +345,7 @@ local function getYueLineNumber(fname, line) if source then local current, target = 1, tonumber(line) local findLine = line - for lineCode in source:gmatch("[^\n\r]*") do + for lineCode in source:gmatch("([^\r\n]*)\r?\n?") do local num = lineCode:match("--%s*(%d+)%s*$") if num then findLine = num diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 8c4afce..69a028f 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -75,7 +75,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.20.6"sv; +const std::string_view version = "0.20.7"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 11c7627..2206686 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -617,11 +617,21 @@ YueParser::YueParser() { Parens = '(' >> *space_break >> space >> Exp >> *space_break >> space >> ')'; Callable = Variable | SelfItem | MacroName | Parens; - fn_args_exp_list = space >> Exp >> space >> *((line_break | ',') >> white >> Exp); + + fn_args_value_list = Exp >> *(space >> ',' >> space >> Exp); + + fn_args_lit_line = ( + push_indent_match >> (space >> fn_args_value_list >> pop_indent | pop_indent) + ) | ( + space + ); + + fn_args_lit_lines = space_break >> fn_args_lit_line >> *(-(space >> ',') >> space_break >> fn_args_lit_line) >> -(space >> ','); fn_args = - '(' >> *space_break >> -fn_args_exp_list >> *space_break >> space >> ')' | - space >> '!' >> not_('='); + '(' >> -(space >> fn_args_value_list >> -(space >> ',')) >> + -fn_args_lit_lines >> + white >> ')' | space >> '!' >> not_('='); meta_index = Name | index | String; Metatable = '<' >> space >> '>'; @@ -701,7 +711,7 @@ YueParser::YueParser() { table_lit_lines = space_break >> table_lit_line >> *(-(space >> ',') >> space_break >> table_lit_line) >> -(space >> ','); TableLit = - space >> '{' >> Seperator >> + '{' >> Seperator >> -(space >> table_value_list >> -(space >> ',')) >> -table_lit_lines >> white >> '}'; diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index 8156ae2..16b57b2 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h @@ -217,7 +217,9 @@ private: NONE_AST_RULE(double_string_plain); NONE_AST_RULE(lua_string_open); NONE_AST_RULE(lua_string_close); - NONE_AST_RULE(fn_args_exp_list); + NONE_AST_RULE(fn_args_value_list); + NONE_AST_RULE(fn_args_lit_line); + NONE_AST_RULE(fn_args_lit_lines); NONE_AST_RULE(fn_args); NONE_AST_RULE(destruct_def); NONE_AST_RULE(macro_args_def); -- cgit v1.2.3-55-g6feb