aboutsummaryrefslogtreecommitdiff
path: root/src/yuescript/yue_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
-rw-r--r--src/yuescript/yue_parser.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 4b865f5..89791d6 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -477,7 +477,7 @@ YueParser::YueParser() {
477 space 477 space
478 ); 478 );
479 479
480 list_lit_lines = space_break >> list_lit_line >> *(-(space >> ',') >> space_break >> list_lit_line) >> -(space >> ','); 480 list_lit_lines = +space_break >> list_lit_line >> *(-(space >> ',') >> space_break >> list_lit_line) >> -(space >> ',');
481 481
482 Comprehension = '[' >> not_('[') >> 482 Comprehension = '[' >> not_('[') >>
483 Seperator >> space >> ( 483 Seperator >> space >> (
@@ -489,7 +489,6 @@ YueParser::YueParser() {
489 white >> ']' >> not_(space >> '=') 489 white >> ']' >> not_(space >> '=')
490 ); 490 );
491 491
492 (space >> disable_for_rule(Exp) >> space >> CompInner >> space >> ']');
493 CompValue = ',' >> space >> Exp; 492 CompValue = ',' >> space >> Exp;
494 TblComprehension = and_('{') >> ('{' >> space >> disable_for_rule(Exp >> space >> -(CompValue >> space)) >> CompInner >> space >> '}' | braces_expression_error); 493 TblComprehension = and_('{') >> ('{' >> space >> disable_for_rule(Exp >> space >> -(CompValue >> space)) >> CompInner >> space >> '}' | braces_expression_error);
495 494
@@ -829,17 +828,26 @@ YueParser::YueParser() {
829 '*' >> space >> (SpreadExp | Exp | TableBlock) 828 '*' >> space >> (SpreadExp | Exp | TableBlock)
830 ); 829 );
831 830
831 fn_arg_def_list = FnArgDef >> *(space >> ',' >> space >> FnArgDef);
832
833 fn_arg_def_lit_line = (
834 push_indent_match >> (space >> fn_arg_def_list >> pop_indent | pop_indent)
835 ) | (
836 space
837 );
838
839 fn_arg_def_lit_lines = fn_arg_def_lit_line >> *(-(space >> ',') >> space_break >> fn_arg_def_lit_line);
840
832 FnArgDef = (Variable | SelfItem >> -ExistentialOp) >> -(space >> '=' >> space >> Exp); 841 FnArgDef = (Variable | SelfItem >> -ExistentialOp) >> -(space >> '=' >> space >> Exp);
833 842
834 FnArgDefList = Seperator >> (( 843 FnArgDefList = Seperator >> (
835 FnArgDef >> 844 fn_arg_def_lit_lines >> -(-(space >> ',') >> white >> VarArg) |
836 *(space >> (',' | line_break) >> white >> FnArgDef) >> 845 white >> VarArg
837 -(space >> (',' | line_break) >> white >> VarArg) 846 );
838 ) | VarArg);
839 847
840 OuterVarShadow = key("using") >> space >> (NameList | key("nil")); 848 OuterVarShadow = key("using") >> space >> (NameList | key("nil"));
841 849
842 FnArgsDef = '(' >> white >> -FnArgDefList >> -(space >> OuterVarShadow) >> white >> ')'; 850 FnArgsDef = '(' >> *space_break >> -FnArgDefList >> -(white >> OuterVarShadow) >> white >> ')';
843 FnArrow = expr("->") | "=>"; 851 FnArrow = expr("->") | "=>";
844 FunLit = -FnArgsDef >> space >> FnArrow >> -(space >> Body); 852 FunLit = -FnArgsDef >> space >> FnArrow >> -(space >> Body);
845 853
@@ -873,8 +881,8 @@ YueParser::YueParser() {
873 881
874 invoke_args_with_table = 882 invoke_args_with_table =
875 ',' >> ( 883 ',' >> (
876 TableBlock | 884 arg_table_block |
877 space_break >> advance_match >> arg_block >> -arg_table_block 885 space_break >> advance_match >> arg_block >> -(-(space >> ',') >> arg_table_block)
878 ) | arg_table_block; 886 ) | arg_table_block;
879 887
880 leading_spaces_error = pl::user(+space_one >> '(' >> space >> Exp >> +(space >> ',' >> space >> Exp) >> space >> ')', [](const item_t& item) { 888 leading_spaces_error = pl::user(+space_one >> '(' >> space >> Exp >> +(space >> ',' >> space >> Exp) >> space >> ')', [](const item_t& item) {
@@ -954,11 +962,10 @@ YueParser::YueParser() {
954 962
955 Body = in_block | Statement; 963 Body = in_block | Statement;
956 964
957 empty_line_break = ( 965 empty_line_break =
958 check_indent >> (multi_line_comment >> space | comment) | 966 check_indent >> (multi_line_comment >> space | comment) >> and_(stop) |
959 advance >> ensure(multi_line_comment >> space | comment, pop_indent) | 967 advance >> ensure(multi_line_comment >> space | comment, pop_indent) >> and_(stop) |
960 plain_space 968 plain_space >> and_(line_break);
961 ) >> and_(stop);
962 969
963 indentation_error = pl::user(not_(pipe_operator | eof()), [](const item_t& item) { 970 indentation_error = pl::user(not_(pipe_operator | eof()), [](const item_t& item) {
964 throw ParserError("unexpected indent"sv, item.begin); 971 throw ParserError("unexpected indent"sv, item.begin);
@@ -1084,6 +1091,11 @@ void trim(std::string& str) {
1084} // namespace Utils 1091} // namespace Utils
1085 1092
1086std::string ParseInfo::errorMessage(std::string_view msg, int errLine, int errCol, int lineOffset) const { 1093std::string ParseInfo::errorMessage(std::string_view msg, int errLine, int errCol, int lineOffset) const {
1094 if (!codes) {
1095 std::ostringstream buf;
1096 buf << errLine + lineOffset << ": "sv << msg;
1097 return buf.str();
1098 }
1087 const int ASCII = 255; 1099 const int ASCII = 255;
1088 int length = errLine; 1100 int length = errLine;
1089 auto begin = codes->begin(); 1101 auto begin = codes->begin();