diff options
author | Li Jin <dragon-fly@qq.com> | 2023-11-19 04:01:01 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-11-19 04:01:01 +0800 |
commit | cd827731ca155f198d26b61a0965469560e1bb34 (patch) | |
tree | 7bf3bc40ab1f09f5c44518370f5c82d0ebbf1709 | |
parent | 9dedf0f5172dd653c1d3f34b303d8bd9f5d427bd (diff) | |
download | yuescript-0.20.7.tar.gz yuescript-0.20.7.tar.bz2 yuescript-0.20.7.zip |
make function call args a consistent behavior with table list.v0.20.7
-rw-r--r-- | spec/inputs/whitespace.yue | 23 | ||||
-rw-r--r-- | spec/outputs/whitespace.lua | 12 | ||||
-rw-r--r-- | src/yuescript/stacktraceplus.h | 2 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 2 | ||||
-rw-r--r-- | src/yuescript/yue_parser.cpp | 18 | ||||
-rw-r--r-- | 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( | |||
97 | c(one, two, | 97 | c(one, two, |
98 | three, four) | 98 | three, four) |
99 | 99 | ||
100 | d( | ||
101 | one -- one | ||
102 | two -- two | ||
103 | three -- three | ||
104 | four -- four | ||
105 | ) | ||
106 | |||
107 | e( | ||
108 | -> | ||
109 | -> | ||
110 | -> | ||
111 | ) | ||
112 | e{ | ||
113 | -> | ||
114 | -> | ||
115 | -> | ||
116 | } | ||
117 | e[ | ||
118 | -> | ||
119 | -> | ||
120 | -> | ||
121 | ] | ||
122 | |||
100 | -- | 123 | -- |
101 | 124 | ||
102 | v = -> | 125 | 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 | |||
77 | a(one, two, three) | 77 | a(one, two, three) |
78 | b(one, two, three) | 78 | b(one, two, three) |
79 | c(one, two, three, four) | 79 | c(one, two, three, four) |
80 | d(one, two, three, four) | ||
81 | e(function() end, function() end, function() end) | ||
82 | e({ | ||
83 | function() end, | ||
84 | function() end, | ||
85 | function() end | ||
86 | }) | ||
87 | e({ | ||
88 | function() end, | ||
89 | function() end, | ||
90 | function() end | ||
91 | }) | ||
80 | local v | 92 | local v |
81 | v = function() | 93 | v = function() |
82 | return a, b, c | 94 | 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) | |||
345 | if source then | 345 | if source then |
346 | local current, target = 1, tonumber(line) | 346 | local current, target = 1, tonumber(line) |
347 | local findLine = line | 347 | local findLine = line |
348 | for lineCode in source:gmatch("[^\n\r]*") do | 348 | for lineCode in source:gmatch("([^\r\n]*)\r?\n?") do |
349 | local num = lineCode:match("--%s*(%d+)%s*$") | 349 | local num = lineCode:match("--%s*(%d+)%s*$") |
350 | if num then | 350 | if num then |
351 | findLine = num | 351 | 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<std::string> Metamethods = { | |||
75 | "close"s // Lua 5.4 | 75 | "close"s // Lua 5.4 |
76 | }; | 76 | }; |
77 | 77 | ||
78 | const std::string_view version = "0.20.6"sv; | 78 | const std::string_view version = "0.20.7"sv; |
79 | const std::string_view extension = "yue"sv; | 79 | const std::string_view extension = "yue"sv; |
80 | 80 | ||
81 | class CompileError : public std::logic_error { | 81 | 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() { | |||
617 | 617 | ||
618 | Parens = '(' >> *space_break >> space >> Exp >> *space_break >> space >> ')'; | 618 | Parens = '(' >> *space_break >> space >> Exp >> *space_break >> space >> ')'; |
619 | Callable = Variable | SelfItem | MacroName | Parens; | 619 | Callable = Variable | SelfItem | MacroName | Parens; |
620 | fn_args_exp_list = space >> Exp >> space >> *((line_break | ',') >> white >> Exp); | 620 | |
621 | fn_args_value_list = Exp >> *(space >> ',' >> space >> Exp); | ||
622 | |||
623 | fn_args_lit_line = ( | ||
624 | push_indent_match >> (space >> fn_args_value_list >> pop_indent | pop_indent) | ||
625 | ) | ( | ||
626 | space | ||
627 | ); | ||
628 | |||
629 | fn_args_lit_lines = space_break >> fn_args_lit_line >> *(-(space >> ',') >> space_break >> fn_args_lit_line) >> -(space >> ','); | ||
621 | 630 | ||
622 | fn_args = | 631 | fn_args = |
623 | '(' >> *space_break >> -fn_args_exp_list >> *space_break >> space >> ')' | | 632 | '(' >> -(space >> fn_args_value_list >> -(space >> ',')) >> |
624 | space >> '!' >> not_('='); | 633 | -fn_args_lit_lines >> |
634 | white >> ')' | space >> '!' >> not_('='); | ||
625 | 635 | ||
626 | meta_index = Name | index | String; | 636 | meta_index = Name | index | String; |
627 | Metatable = '<' >> space >> '>'; | 637 | Metatable = '<' >> space >> '>'; |
@@ -701,7 +711,7 @@ YueParser::YueParser() { | |||
701 | table_lit_lines = space_break >> table_lit_line >> *(-(space >> ',') >> space_break >> table_lit_line) >> -(space >> ','); | 711 | table_lit_lines = space_break >> table_lit_line >> *(-(space >> ',') >> space_break >> table_lit_line) >> -(space >> ','); |
702 | 712 | ||
703 | TableLit = | 713 | TableLit = |
704 | space >> '{' >> Seperator >> | 714 | '{' >> Seperator >> |
705 | -(space >> table_value_list >> -(space >> ',')) >> | 715 | -(space >> table_value_list >> -(space >> ',')) >> |
706 | -table_lit_lines >> | 716 | -table_lit_lines >> |
707 | white >> '}'; | 717 | 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: | |||
217 | NONE_AST_RULE(double_string_plain); | 217 | NONE_AST_RULE(double_string_plain); |
218 | NONE_AST_RULE(lua_string_open); | 218 | NONE_AST_RULE(lua_string_open); |
219 | NONE_AST_RULE(lua_string_close); | 219 | NONE_AST_RULE(lua_string_close); |
220 | NONE_AST_RULE(fn_args_exp_list); | 220 | NONE_AST_RULE(fn_args_value_list); |
221 | NONE_AST_RULE(fn_args_lit_line); | ||
222 | NONE_AST_RULE(fn_args_lit_lines); | ||
221 | NONE_AST_RULE(fn_args); | 223 | NONE_AST_RULE(fn_args); |
222 | NONE_AST_RULE(destruct_def); | 224 | NONE_AST_RULE(destruct_def); |
223 | NONE_AST_RULE(macro_args_def); | 225 | NONE_AST_RULE(macro_args_def); |