aboutsummaryrefslogtreecommitdiff
path: root/src/yuescript/yue_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/yuescript/yue_parser.cpp49
1 files changed, 18 insertions, 31 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 5a54690..cacfebe 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -1082,48 +1082,35 @@ YueParser::YueParser() {
1082 IfLine = IfType >> space >> IfCond; 1082 IfLine = IfType >> space >> IfCond;
1083 WhileLine = WhileType >> space >> Exp; 1083 WhileLine = WhileType >> space >> Exp;
1084 1084
1085 YueLineComment = *(not_(set("\r\n")) >> any_char);
1086 yue_line_comment = "--" >> YueLineComment >> and_(stop);
1087 MultilineCommentInner = multi_line_content;
1088 YueMultilineComment = multi_line_open >> MultilineCommentInner >> multi_line_close;
1089 yue_comment = check_indent >> (
1090 (
1091 YueMultilineComment >>
1092 *(set(" \t") | YueMultilineComment) >>
1093 -yue_line_comment
1094 ) | yue_line_comment
1095 ) >> and_(line_break);
1096
1097 ChainAssign = Seperator >> Exp >> +(space >> '=' >> space >> Exp >> space >> and_('=')) >> space >> Assign; 1085 ChainAssign = Seperator >> Exp >> +(space >> '=' >> space >> Exp >> space >> and_('=')) >> space >> Assign;
1098 1086
1099 StatementAppendix = (IfLine | WhileLine | CompInner) >> space; 1087 StatementAppendix = (IfLine | WhileLine | CompInner) >> space;
1100 Statement = 1088 Statement =
1101 Seperator >> 1089 (
1102 -(
1103 yue_comment >>
1104 *(line_break >> yue_comment) >>
1105 line_break >>
1106 check_indent_match
1107 ) >>
1108 space >> (
1109 Import | While | Repeat | For | ForEach | 1090 Import | While | Repeat | For | ForEach |
1110 Return | Local | Global | Export | Macro | 1091 Return | Local | Global | Export | Macro |
1111 MacroInPlace | BreakLoop | Label | Goto | ShortTabAppending | 1092 MacroInPlace | BreakLoop | Label | Goto | ShortTabAppending |
1112 LocalAttrib | Backcall | PipeBody | ExpListAssign | ChainAssign | 1093 LocalAttrib | Backcall | PipeBody | ExpListAssign | ChainAssign |
1113 StatementAppendix >> empty_block_error | 1094 StatementAppendix >> empty_block_error |
1114 and_(key("else") | key("elseif") | key("when")) >> dangling_clause_error 1095 and_(key("else") | key("elseif") | key("when")) >> dangling_clause_error
1115 ) >> 1096 ) >> space >>
1116 space >>
1117 -StatementAppendix; 1097 -StatementAppendix;
1118 1098
1119 StatementSep = white >> (set("('\"") | "[[" | "[="); 1099 StatementSep = white >> (set("('\"") | "[[" | "[=");
1120 1100
1121 Body = in_block | Statement; 1101 Body = in_block | Statement;
1122 1102
1123 empty_line_break = 1103 YueLineComment = *(not_(set("\r\n")) >> any_char);
1124 check_indent >> (multi_line_comment >> space | comment) >> and_(stop) | 1104 yue_line_comment = "--" >> YueLineComment >> and_(stop);
1125 advance >> ensure(multi_line_comment >> space | comment, pop_indent) >> and_(stop) | 1105 YueMultilineComment = multi_line_content;
1126 plain_space >> and_(line_break); 1106 yue_multiline_comment = multi_line_open >> YueMultilineComment >> multi_line_close;
1107 comment_line =
1108 yue_multiline_comment >> *(set(" \t") | yue_multiline_comment) >> plain_space >> -yue_line_comment |
1109 yue_line_comment;
1110 YueComment =
1111 check_indent >> comment_line >> and_(stop) |
1112 advance >> ensure(comment_line, pop_indent) >> and_(stop) |
1113 plain_space >> and_(stop);
1127 1114
1128 indentation_error = pl::user(not_(pipe_operator | eof()), [](const item_t& item) { 1115 indentation_error = pl::user(not_(pipe_operator | eof()), [](const item_t& item) {
1129 RaiseError("unexpected indent"sv, item); 1116 RaiseError("unexpected indent"sv, item);
@@ -1131,18 +1118,18 @@ YueParser::YueParser() {
1131 }); 1118 });
1132 1119
1133 line = ( 1120 line = (
1134 check_indent_match >> Statement | 1121 check_indent_match >> space >> Statement |
1135 empty_line_break | 1122 YueComment |
1136 advance_match >> ensure(space >> (indentation_error | Statement), pop_indent) 1123 advance_match >> ensure(space >> (indentation_error | Statement), pop_indent)
1137 ); 1124 );
1138 Block = Seperator >> (pl::user(true_(), [](const item_t& item) { 1125 Block = Seperator >> (pl::user(true_(), [](const item_t& item) {
1139 State* st = reinterpret_cast<State*>(item.user_data); 1126 State* st = reinterpret_cast<State*>(item.user_data);
1140 return st->lax; 1127 return st->lax;
1141 }) >> lax_line >> *(+line_break >> lax_line) | line >> *(+line_break >> line)); 1128 }) >> lax_line >> *(line_break >> lax_line) | line >> *(line_break >> line));
1142 1129
1143 shebang = "#!" >> *(not_(stop) >> any_char); 1130 shebang = "#!" >> *(not_(stop) >> any_char);
1144 BlockEnd = Block >> white >> stop; 1131 BlockEnd = Block >> stop;
1145 File = -shebang >> -Block >> white >> stop; 1132 File = -shebang >> -Block >> stop;
1146 1133
1147 lax_line = advance_match >> ensure(*(not_(stop) >> any()), pop_indent) | line >> and_(stop) | check_indent_match >> *(not_(stop) >> any()); 1134 lax_line = advance_match >> ensure(*(not_(stop) >> any()), pop_indent) | line >> and_(stop) | check_indent_match >> *(not_(stop) >> any());
1148} 1135}