diff options
author | Li Jin <dragon-fly@qq.com> | 2020-09-17 08:47:29 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-09-17 08:47:29 +0800 |
commit | 5440c952f2c73da6fa6a752d8628eaf25015c070 (patch) | |
tree | c57173a695bba128c4bccef78dea581ba4a87bc3 | |
parent | e958b59c9635f0a01e29e3f30c34adecd327cc1f (diff) | |
download | yuescript-5440c952f2c73da6fa6a752d8628eaf25015c070.tar.gz yuescript-5440c952f2c73da6fa6a752d8628eaf25015c070.tar.bz2 yuescript-5440c952f2c73da6fa6a752d8628eaf25015c070.zip |
make simple table and table block appear in the end of function arguments merged.
-rw-r--r-- | spec/inputs/syntax.moon | 4 | ||||
-rw-r--r-- | spec/inputs/tables.moon | 2 | ||||
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 33 |
3 files changed, 35 insertions, 4 deletions
diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon index 99daac5..32d480e 100644 --- a/spec/inputs/syntax.moon +++ b/spec/inputs/syntax.moon | |||
@@ -240,7 +240,7 @@ hello "comma", | |||
240 | something: hello_world | 240 | something: hello_world |
241 | frick: you | 241 | frick: you |
242 | 242 | ||
243 | -- creates two tables | 243 | -- creates one table |
244 | another hello, one, | 244 | another hello, one, |
245 | two, three, four, yeah: man | 245 | two, three, four, yeah: man |
246 | okay: yeah | 246 | okay: yeah |
@@ -252,7 +252,7 @@ another hello, one, two, three, four, | |||
252 | 252 | ||
253 | another hello, one, two, three, four, yeah: man | 253 | another hello, one, two, three, four, yeah: man |
254 | okay: yeah | 254 | okay: yeah |
255 | 255 | ||
256 | -- | 256 | -- |
257 | a += 3 - 5 | 257 | a += 3 - 5 |
258 | a *= 3 + 5 | 258 | a *= 3 + 5 |
diff --git a/spec/inputs/tables.moon b/spec/inputs/tables.moon index 079be35..6375660 100644 --- a/spec/inputs/tables.moon +++ b/spec/inputs/tables.moon | |||
@@ -125,7 +125,7 @@ kam = { | |||
125 | one_thing => | 125 | one_thing => |
126 | } | 126 | } |
127 | 127 | ||
128 | -- TODO: both of these have undesirable output | 128 | -- both of these have desirable output |
129 | keepit going: true, | 129 | keepit going: true, |
130 | okay: "yeah", | 130 | okay: "yeah", |
131 | workd: "okay" | 131 | workd: "okay" |
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 406b412..112cae7 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
@@ -49,7 +49,7 @@ inline std::string s(std::string_view sv) { | |||
49 | } | 49 | } |
50 | 50 | ||
51 | const std::string_view version() { | 51 | const std::string_view version() { |
52 | return "0.4.12"sv; | 52 | return "0.4.14"sv; |
53 | } | 53 | } |
54 | 54 | ||
55 | // name of table stored in lua registry | 55 | // name of table stored in lua registry |
@@ -3603,6 +3603,37 @@ private: | |||
3603 | } | 3603 | } |
3604 | 3604 | ||
3605 | void transformInvokeArgs(InvokeArgs_t* invokeArgs, str_list& out) { | 3605 | void transformInvokeArgs(InvokeArgs_t* invokeArgs, str_list& out) { |
3606 | if (invokeArgs->args.size() > 1) { | ||
3607 | /* merge all the key-value pairs into one table | ||
3608 | from arguments in the end */ | ||
3609 | auto lastArg = invokeArgs->args.back(); | ||
3610 | _ast_list* lastTable = nullptr; | ||
3611 | if (auto tableBlock = ast_cast<TableBlock_t>(lastArg)) { | ||
3612 | lastTable = &tableBlock->values; | ||
3613 | } else if (auto value = singleValueFrom(lastArg)) { | ||
3614 | if (auto simpleTable = ast_cast<simple_table_t>(value->item)) { | ||
3615 | lastTable = &simpleTable->pairs; | ||
3616 | } | ||
3617 | } | ||
3618 | if (lastTable) { | ||
3619 | ast_ptr<false, ast_node> ref(lastArg); | ||
3620 | invokeArgs->args.pop_back(); | ||
3621 | while (!invokeArgs->args.empty()) { | ||
3622 | if (Value_t* value = singleValueFrom(invokeArgs->args.back())) { | ||
3623 | if (auto tb = value->item.as<simple_table_t>()) { | ||
3624 | const auto& ps = tb->pairs.objects(); | ||
3625 | for (auto it = ps.rbegin(); it != ps.rend(); ++it) { | ||
3626 | lastTable->push_front(*it); | ||
3627 | } | ||
3628 | invokeArgs->args.pop_back(); | ||
3629 | continue; | ||
3630 | } | ||
3631 | } | ||
3632 | break; | ||
3633 | } | ||
3634 | invokeArgs->args.push_back(lastArg); | ||
3635 | } | ||
3636 | } | ||
3606 | str_list temp; | 3637 | str_list temp; |
3607 | for (auto arg : invokeArgs->args.objects()) { | 3638 | for (auto arg : invokeArgs->args.objects()) { |
3608 | switch (arg->getId()) { | 3639 | switch (arg->getId()) { |