diff options
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
-rwxr-xr-x | src/yuescript/yue_parser.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 153babe..c5cae0b 100755 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -78,8 +78,8 @@ YueParser::YueParser() { | |||
78 | #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut)) | 78 | #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut)) |
79 | #define disable_do_chain_arg_table_block(patt) (DisableDoChainArgTableBlock >> ((patt) >> EnableDoChainArgTableBlock | EnableDoChainArgTableBlock >> Cut)) | 79 | #define disable_do_chain_arg_table_block(patt) (DisableDoChainArgTableBlock >> ((patt) >> EnableDoChainArgTableBlock | EnableDoChainArgTableBlock >> Cut)) |
80 | #define disable_arg_table_block(patt) (DisableArgTableBlock >> ((patt) >> EnableArgTableBlock | EnableArgTableBlock >> Cut)) | 80 | #define disable_arg_table_block(patt) (DisableArgTableBlock >> ((patt) >> EnableArgTableBlock | EnableArgTableBlock >> Cut)) |
81 | #define plain_body_with(str) (-(Space >> key(str)) >> InBlock | Space >> key(str) >> Statement) | 81 | #define plain_body_with(str) (-(Space >> key(str)) >> InBlock | Space >> key(str) >> Space >> Statement) |
82 | #define plain_body (InBlock | Statement) | 82 | #define plain_body (InBlock | Space >> Statement) |
83 | 83 | ||
84 | Variable = pl::user(Name, [](const item_t& item) { | 84 | Variable = pl::user(Name, [](const item_t& item) { |
85 | State* st = reinterpret_cast<State*>(item.user_data); | 85 | State* st = reinterpret_cast<State*>(item.user_data); |
@@ -177,7 +177,7 @@ YueParser::YueParser() { | |||
177 | return true; | 177 | return true; |
178 | }); | 178 | }); |
179 | 179 | ||
180 | InBlock = +SpaceBreak >> Advance >> ensure(Block, PopIndent); | 180 | InBlock = Space >> +(plain_space >> Break) >> Advance >> ensure(Block, PopIndent); |
181 | 181 | ||
182 | local_flag = expr('*') | expr('^'); | 182 | local_flag = expr('*') | expr('^'); |
183 | local_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow)); | 183 | local_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow)); |
@@ -503,7 +503,7 @@ YueParser::YueParser() { | |||
503 | -(+SpaceBreak >> Advance >> ensure(KeyValueList >> -sym(',') >> *(+SpaceBreak >> KeyValueLine), PopIndent))); | 503 | -(+SpaceBreak >> Advance >> ensure(KeyValueList >> -sym(',') >> *(+SpaceBreak >> KeyValueLine), PopIndent))); |
504 | 504 | ||
505 | class_member_list = Seperator >> KeyValue >> *(sym(',') >> KeyValue); | 505 | class_member_list = Seperator >> KeyValue >> *(sym(',') >> KeyValue); |
506 | ClassLine = CheckIndent >> (class_member_list | Statement) >> -sym(','); | 506 | ClassLine = CheckIndent >> (class_member_list | Space >> Statement) >> -sym(','); |
507 | ClassBlock = +SpaceBreak >> Advance >> Seperator >> ClassLine >> *(+SpaceBreak >> ClassLine) >> PopIndent; | 507 | ClassBlock = +SpaceBreak >> Advance >> Seperator >> ClassLine >> *(+SpaceBreak >> ClassLine) >> PopIndent; |
508 | 508 | ||
509 | ClassDecl = | 509 | ClassDecl = |
@@ -641,9 +641,15 @@ YueParser::YueParser() { | |||
641 | 641 | ||
642 | if_line = Space >> IfType >> IfCond; | 642 | if_line = Space >> IfType >> IfCond; |
643 | 643 | ||
644 | YueLineComment = *(not_(set("\r\n")) >> Any); | ||
645 | yue_line_comment = expr("--") >> YueLineComment >> and_(Stop); | ||
646 | YueMultilineComment = multi_line_content; | ||
647 | yue_multiline_comment = multi_line_open >> YueMultilineComment >> multi_line_close; | ||
648 | yue_comment = check_indent >> (yue_multiline_comment >> *(set(" \t") | yue_multiline_comment) >> -yue_line_comment | yue_line_comment) >> and_(Break); | ||
649 | |||
644 | statement_appendix = (if_line | CompInner) >> Space; | 650 | statement_appendix = (if_line | CompInner) >> Space; |
645 | statement_sep = and_(*SpaceBreak >> CheckIndent >> Space >> (set("($'\"") | expr("[[") | expr("[="))); | 651 | statement_sep = and_(*SpaceBreak >> CheckIndent >> Space >> (set("($'\"") | expr("[[") | expr("[="))); |
646 | Statement = Space >> ( | 652 | Statement = Seperator >> -(yue_comment >> *(Break >> yue_comment) >> Break >> CheckIndent) >> Space >> ( |
647 | Import | While | Repeat | For | ForEach | | 653 | Import | While | Repeat | For | ForEach | |
648 | Return | Local | Global | Export | Macro | | 654 | Return | Local | Global | Export | Macro | |
649 | MacroInPlace | BreakLoop | Label | Goto | ShortTabAppending | | 655 | MacroInPlace | BreakLoop | Label | Goto | ShortTabAppending | |
@@ -651,15 +657,22 @@ YueParser::YueParser() { | |||
651 | ) >> Space >> | 657 | ) >> Space >> |
652 | -statement_appendix >> -statement_sep; | 658 | -statement_appendix >> -statement_sep; |
653 | 659 | ||
654 | Body = InBlock | Statement; | 660 | Body = InBlock | Space >> Statement; |
661 | |||
662 | empty_line_stop = ( | ||
663 | check_indent >> (MultiLineComment >> Space | Comment) | | ||
664 | advance >> ensure(MultiLineComment >> Space | Comment, PopIndent) | | ||
665 | plain_space) >> and_(Stop); | ||
655 | 666 | ||
656 | empty_line_stop = Space >> and_(Break); | 667 | Line = |
657 | Line = and_(check_indent >> Space >> not_(PipeOperator)) >> Statement | Advance >> ensure(and_(Space >> PipeOperator) >> Statement, PopIndent) | empty_line_stop; | 668 | CheckIndent >> Statement | |
669 | Advance >> ensure(Space >> and_(PipeOperator) >> Statement, PopIndent) | | ||
670 | empty_line_stop; | ||
658 | Block = Seperator >> Line >> *(+Break >> Line); | 671 | Block = Seperator >> Line >> *(+Break >> Line); |
659 | 672 | ||
660 | Shebang = expr("#!") >> *(not_(Stop) >> Any); | 673 | Shebang = expr("#!") >> *(not_(Stop) >> Any); |
661 | BlockEnd = Block >> -(+Break >> Space >> and_(Stop)) >> Stop; | 674 | BlockEnd = Block >> Stop; |
662 | File = White >> -Shebang >> -Block >> White >> eof(); | 675 | File = -Shebang >> -Block >> Stop; |
663 | } | 676 | } |
664 | // clang-format on | 677 | // clang-format on |
665 | 678 | ||