diff options
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
-rw-r--r-- | src/yuescript/yue_parser.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
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); |