aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-04-19 20:56:05 +0800
committerLi Jin <dragon-fly@qq.com>2021-04-19 20:56:05 +0800
commitea82666506b57d6e905b7f2e5fe78498fe5a7abd (patch)
treeef5eb47f849090f225567b67070a90aeeee49d95
parent7ac784e73b026ce7e17babb2f0b819864fd898b0 (diff)
downloadyuescript-ea82666506b57d6e905b7f2e5fe78498fe5a7abd.tar.gz
yuescript-ea82666506b57d6e905b7f2e5fe78498fe5a7abd.tar.bz2
yuescript-ea82666506b57d6e905b7f2e5fe78498fe5a7abd.zip
fix issue #49 and issue #50.
-rw-r--r--spec/inputs/tables.yue18
-rw-r--r--src/yuescript/yue_compiler.cpp4
-rw-r--r--src/yuescript/yue_parser.cpp34
-rw-r--r--src/yuescript/yue_parser.h4
4 files changed, 50 insertions, 10 deletions
diff --git a/spec/inputs/tables.yue b/spec/inputs/tables.yue
index 2c6dff9..4cd9b4d 100644
--- a/spec/inputs/tables.yue
+++ b/spec/inputs/tables.yue
@@ -219,5 +219,23 @@ items =
219 name: "necklace" 219 name: "necklace"
220 amount: 1 220 amount: 1
221 221
222menus =
223 * text: "Save"
224 sub:
225 * text: "Slot 1: " .. (slots[1].name or "None")
226 click: ->
227 * text: {"Slot 2"}
228 click: ->
229 * text: [[Slot 3]]
230 click: ->
231 * text: ("Slot 4")\name!
232 click: ->
233 * text: ({{"slot5"}})[1]\name!
234 click: ->
235 [6]: {
236 text: ("Slot 6")
237 click: ->
238 }
239
222nil 240nil
223 241
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 85744d5..bc55eb3 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -59,7 +59,7 @@ inline std::string s(std::string_view sv) {
59 return std::string(sv); 59 return std::string(sv);
60} 60}
61 61
62const std::string_view version = "0.7.7"sv; 62const std::string_view version = "0.7.8"sv;
63const std::string_view extension = "yue"sv; 63const std::string_view extension = "yue"sv;
64 64
65class YueCompilerImpl { 65class YueCompilerImpl {
@@ -4111,7 +4111,7 @@ private:
4111 transformExp(star_exp->value, temp, ExpUsage::Closure); 4111 transformExp(star_exp->value, temp, ExpUsage::Closure);
4112 if (newListVal) _buf << indent() << "local "sv << listVar << " = "sv << temp.back() << nll(nameList); 4112 if (newListVal) _buf << indent() << "local "sv << listVar << " = "sv << temp.back() << nll(nameList);
4113 _buf << indent() << "for "sv << indexVar << " = 1, #"sv << listVar << " do"sv << nlr(loopTarget); 4113 _buf << indent() << "for "sv << indexVar << " = 1, #"sv << listVar << " do"sv << nlr(loopTarget);
4114 _buf << indent(1) << "local "sv << join(vars) << " = "sv << listVar << "["sv << indexVar << "]"sv << nll(nameList); 4114 _buf << indent(1) << "local "sv << join(vars, ", "sv) << " = "sv << listVar << "["sv << indexVar << "]"sv << nll(nameList);
4115 out.push_back(clearBuf()); 4115 out.push_back(clearBuf());
4116 } 4116 }
4117 break; 4117 break;
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 30c5598..185d54b 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -75,6 +75,7 @@ YueParser::YueParser() {
75 #define disable_do(patt) (DisableDo >> ((patt) >> EnableDo | EnableDo >> Cut)) 75 #define disable_do(patt) (DisableDo >> ((patt) >> EnableDo | EnableDo >> Cut))
76 #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut)) 76 #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut))
77 #define disable_do_chain(patt) (DisableDoChain >> ((patt) >> EnableDoChain | EnableDoChain >> Cut)) 77 #define disable_do_chain(patt) (DisableDoChain >> ((patt) >> EnableDoChain | EnableDoChain >> Cut))
78 #define disable_arg_table_block(patt) (DisableArgTableBlock >> ((patt) >> EnableArgTableBlock | EnableArgTableBlock >> Cut))
78 #define plain_body_with(str) (-key(str) >> InBlock | key(str) >> Statement) 79 #define plain_body_with(str) (-key(str) >> InBlock | key(str) >> Statement)
79 #define plain_body (InBlock | Statement) 80 #define plain_body (InBlock | Statement)
80 81
@@ -290,6 +291,18 @@ YueParser::YueParser() {
290 return true; 291 return true;
291 }); 292 });
292 293
294 DisableArgTableBlock = pl::user(true_(), [](const item_t& item) {
295 State* st = reinterpret_cast<State*>(item.user_data);
296 st->noTableBlockStack.push(true);
297 return true;
298 });
299
300 EnableArgTableBlock = pl::user(true_(), [](const item_t& item) {
301 State* st = reinterpret_cast<State*>(item.user_data);
302 st->noTableBlockStack.pop();
303 return true;
304 });
305
293 Comprehension = sym('[') >> Exp >> CompInner >> sym(']'); 306 Comprehension = sym('[') >> Exp >> CompInner >> sym(']');
294 comp_value = sym(',') >> Exp; 307 comp_value = sym(',') >> Exp;
295 TblComprehension = sym('{') >> Exp >> -comp_value >> CompInner >> sym('}'); 308 TblComprehension = sym('{') >> Exp >> -comp_value >> CompInner >> sym('}');
@@ -472,8 +485,9 @@ YueParser::YueParser() {
472 485
473 TableBlockInner = Seperator >> KeyValueLine >> *(+SpaceBreak >> KeyValueLine); 486 TableBlockInner = Seperator >> KeyValueLine >> *(+SpaceBreak >> KeyValueLine);
474 TableBlock = +SpaceBreak >> Advance >> ensure(TableBlockInner, PopIndent); 487 TableBlock = +SpaceBreak >> Advance >> ensure(TableBlockInner, PopIndent);
475 TableBlockIndent = sym('*') >> Seperator >> KeyValueList >> -sym(',') >> 488 TableBlockIndent = sym('*') >> Seperator >> disable_arg_table_block(
476 -(+SpaceBreak >> Advance >> ensure(KeyValueList >> -sym(',') >> *(+SpaceBreak >> KeyValueLine), PopIndent)); 489 KeyValueList >> -sym(',') >>
490 -(+SpaceBreak >> Advance >> ensure(KeyValueList >> -sym(',') >> *(+SpaceBreak >> KeyValueLine), PopIndent)));
477 491
478 class_member_list = Seperator >> KeyValue >> *(sym(',') >> KeyValue); 492 class_member_list = Seperator >> KeyValue >> *(sym(',') >> KeyValue);
479 ClassLine = CheckIndent >> (class_member_list | Statement) >> -sym(','); 493 ClassLine = CheckIndent >> (class_member_list | Statement) >> -sym(',');
@@ -571,18 +585,22 @@ YueParser::YueParser() {
571 ArgLine = CheckIndent >> Exp >> *(sym(',') >> Exp); 585 ArgLine = CheckIndent >> Exp >> *(sym(',') >> Exp);
572 ArgBlock = ArgLine >> *(sym(',') >> SpaceBreak >> ArgLine) >> PopIndent; 586 ArgBlock = ArgLine >> *(sym(',') >> SpaceBreak >> ArgLine) >> PopIndent;
573 587
588 arg_table_block = pl::user(true_(), [](const item_t& item) {
589 State* st = reinterpret_cast<State*>(item.user_data);
590 return st->noTableBlockStack.empty() || !st->noTableBlockStack.top();
591 }) >> TableBlock;
592
574 invoke_args_with_table = 593 invoke_args_with_table =
575 sym(',') >> 594 sym(',') >> (
576 (
577 TableBlock | 595 TableBlock |
578 SpaceBreak >> Advance >> ArgBlock >> -TableBlock 596 SpaceBreak >> Advance >> ArgBlock >> -arg_table_block
579 ); 597 ) | arg_table_block;
580 598
581 InvokeArgs = 599 InvokeArgs =
582 not_(set("-~")) >> Seperator >> 600 not_(set("-~")) >> Seperator >>
583 ( 601 (
584 Exp >> *(sym(',') >> Exp) >> -(invoke_args_with_table | TableBlock) | 602 (Exp >> *(sym(',') >> Exp) >> -invoke_args_with_table) |
585 TableBlock 603 arg_table_block
586 ); 604 );
587 605
588 const_value = (expr("nil") | expr("true") | expr("false")) >> not_(AlphaNum); 606 const_value = (expr("nil") | expr("true") | expr("false")) >> not_(AlphaNum);
diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h
index cb9cfba..b3c311a 100644
--- a/src/yuescript/yue_parser.h
+++ b/src/yuescript/yue_parser.h
@@ -79,6 +79,7 @@ protected:
79 std::stack<int> indents; 79 std::stack<int> indents;
80 std::stack<bool> doStack; 80 std::stack<bool> doStack;
81 std::stack<bool> chainBlockStack; 81 std::stack<bool> chainBlockStack;
82 std::stack<bool> noTableBlockStack;
82 }; 83 };
83 84
84 template <class T> 85 template <class T>
@@ -136,6 +137,8 @@ private:
136 rule EnableChain; 137 rule EnableChain;
137 rule DisableDoChain; 138 rule DisableDoChain;
138 rule EnableDoChain; 139 rule EnableDoChain;
140 rule DisableArgTableBlock;
141 rule EnableArgTableBlock;
139 rule SwitchElse; 142 rule SwitchElse;
140 rule SwitchBlock; 143 rule SwitchBlock;
141 rule IfElseIf; 144 rule IfElseIf;
@@ -175,6 +178,7 @@ private:
175 rule ArgLine; 178 rule ArgLine;
176 rule ArgBlock; 179 rule ArgBlock;
177 rule invoke_args_with_table; 180 rule invoke_args_with_table;
181 rule arg_table_block;
178 rule PipeOperator; 182 rule PipeOperator;
179 rule ExponentialOperator; 183 rule ExponentialOperator;
180 rule pipe_value; 184 rule pipe_value;