diff options
author | Li Jin <dragon-fly@qq.com> | 2023-01-18 15:40:17 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-01-18 15:40:17 +0800 |
commit | 9a31f590ed1557aa180d28c5ab843c39608d0a0a (patch) | |
tree | afdf0144f3371a03fcd441ada15b53a4786a42ab | |
parent | 395d5bac06bba03a863c1bb18464fad8a84cd384 (diff) | |
download | yuescript-9a31f590ed1557aa180d28c5ab843c39608d0a0a.tar.gz yuescript-9a31f590ed1557aa180d28c5ab843c39608d0a0a.tar.bz2 yuescript-9a31f590ed1557aa180d28c5ab843c39608d0a0a.zip |
clean up syntax.
-rw-r--r-- | src/yuescript/yue_parser.cpp | 451 |
1 files changed, 224 insertions, 227 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 821385b..48308a6 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -38,42 +38,42 @@ YueParser::YueParser() { | |||
38 | Stop = Break | eof(); | 38 | Stop = Break | eof(); |
39 | Indent = plain_space; | 39 | Indent = plain_space; |
40 | Comment = "--" >> *(not_(set("\r\n")) >> Any) >> and_(Stop); | 40 | Comment = "--" >> *(not_(set("\r\n")) >> Any) >> and_(Stop); |
41 | multi_line_open = expr("--[["); | 41 | multi_line_open = "--[["; |
42 | multi_line_close = expr("]]"); | 42 | multi_line_close = "]]"; |
43 | multi_line_content = *(not_(multi_line_close) >> Any); | 43 | multi_line_content = *(not_(multi_line_close) >> Any); |
44 | MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; | 44 | MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; |
45 | EscapeNewLine = expr('\\') >> *(set(" \t") | MultiLineComment) >> -Comment >> Break; | 45 | EscapeNewLine = '\\' >> *(set(" \t") | MultiLineComment) >> -Comment >> Break; |
46 | space_one = set(" \t") | and_(set("-\\")) >> (MultiLineComment | EscapeNewLine); | 46 | space_one = set(" \t") | and_(set("-\\")) >> (MultiLineComment | EscapeNewLine); |
47 | Space = -(and_(set(" \t-\\")) >> *space_one >> -Comment); | 47 | Space = -(and_(set(" \t-\\")) >> *space_one >> -Comment); |
48 | SpaceBreak = Space >> Break; | 48 | SpaceBreak = Space >> Break; |
49 | White = Space >> *(Break >> Space); | 49 | White = Space >> *(Break >> Space); |
50 | EmptyLine = SpaceBreak; | 50 | EmptyLine = SpaceBreak; |
51 | AlphaNum = sel({range('a', 'z'), range('A', 'Z'), range('0', '9'), expr('_')}); | 51 | AlphaNum = sel({range('a', 'z'), range('A', 'Z'), range('0', '9'), '_'}); |
52 | Name = sel({range('a', 'z'), range('A', 'Z'), expr('_')}) >> *AlphaNum; | 52 | Name = sel({range('a', 'z'), range('A', 'Z'), '_'}) >> *AlphaNum; |
53 | num_expo = set("eE") >> -set("+-") >> num_char; | 53 | num_expo = set("eE") >> -set("+-") >> num_char; |
54 | num_expo_hex = set("pP") >> -set("+-") >> num_char; | 54 | num_expo_hex = set("pP") >> -set("+-") >> num_char; |
55 | lj_num = -set("uU") >> set("lL") >> set("lL"); | 55 | lj_num = -set("uU") >> set("lL") >> set("lL"); |
56 | num_char = range('0', '9') >> *(range('0', '9') | expr('_') >> and_(range('0', '9'))); | 56 | num_char = range('0', '9') >> *(range('0', '9') | '_' >> and_(range('0', '9'))); |
57 | num_char_hex = sel({range('0', '9'), range('a', 'f'), range('A', 'F')}); | 57 | num_char_hex = sel({range('0', '9'), range('a', 'f'), range('A', 'F')}); |
58 | num_lit = num_char_hex >> *(num_char_hex | expr('_') >> and_(num_char_hex)); | 58 | num_lit = num_char_hex >> *(num_char_hex | '_' >> and_(num_char_hex)); |
59 | Num = sel({ | 59 | Num = sel({ |
60 | expr("0x") >> ( | 60 | "0x" >> ( |
61 | +num_lit >> sel({ | 61 | +num_lit >> sel({ |
62 | seq({expr('.'), +num_lit, -num_expo_hex}), | 62 | seq({'.', +num_lit, -num_expo_hex}), |
63 | num_expo_hex, | 63 | num_expo_hex, |
64 | lj_num, | 64 | lj_num, |
65 | true_() | 65 | true_() |
66 | }) | seq({ | 66 | }) | seq({ |
67 | expr('.'), +num_lit, -num_expo_hex | 67 | '.', +num_lit, -num_expo_hex |
68 | }) | 68 | }) |
69 | ), | 69 | ), |
70 | +num_char >> sel({ | 70 | +num_char >> sel({ |
71 | seq({expr('.'), +num_char, -num_expo}), | 71 | seq({'.', +num_char, -num_expo}), |
72 | num_expo, | 72 | num_expo, |
73 | lj_num, | 73 | lj_num, |
74 | true_() | 74 | true_() |
75 | }), | 75 | }), |
76 | seq({expr('.'), +num_char, -num_expo}) | 76 | seq({'.', +num_char, -num_expo}) |
77 | }); | 77 | }); |
78 | 78 | ||
79 | Cut = false_(); | 79 | Cut = false_(); |
@@ -90,9 +90,9 @@ YueParser::YueParser() { | |||
90 | #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut)) | 90 | #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut)) |
91 | #define disable_do_chain_arg_table_block(patt) (DisableDoChainArgTableBlock >> ((patt) >> EnableDoChainArgTableBlock | EnableDoChainArgTableBlock >> Cut)) | 91 | #define disable_do_chain_arg_table_block(patt) (DisableDoChainArgTableBlock >> ((patt) >> EnableDoChainArgTableBlock | EnableDoChainArgTableBlock >> Cut)) |
92 | #define disable_arg_table_block(patt) (DisableArgTableBlock >> ((patt) >> EnableArgTableBlock | EnableArgTableBlock >> Cut)) | 92 | #define disable_arg_table_block(patt) (DisableArgTableBlock >> ((patt) >> EnableArgTableBlock | EnableArgTableBlock >> Cut)) |
93 | #define body_with(str) (Space >> sel({key(str) >> Space >> (InBlock | Statement), InBlock, empty_block_error})) | 93 | #define body_with(str) (sel({key(str) >> Space >> (InBlock | Statement), InBlock, empty_block_error})) |
94 | #define opt_body_with(str) (Space >> (key(str) >> Space >> (InBlock | Statement) | InBlock)) | 94 | #define opt_body_with(str) (key(str) >> Space >> (InBlock | Statement) | InBlock) |
95 | #define body (Space >> sel({InBlock, Statement, empty_block_error})) | 95 | #define body (sel({InBlock, Statement, empty_block_error})) |
96 | 96 | ||
97 | Variable = pl::user(Name, [](const item_t& item) { | 97 | Variable = pl::user(Name, [](const item_t& item) { |
98 | State* st = reinterpret_cast<State*>(item.user_data); | 98 | State* st = reinterpret_cast<State*>(item.user_data); |
@@ -124,14 +124,14 @@ YueParser::YueParser() { | |||
124 | return it != LuaKeywords.end(); | 124 | return it != LuaKeywords.end(); |
125 | }); | 125 | }); |
126 | 126 | ||
127 | self = expr('@'); | 127 | self = '@'; |
128 | self_name = '@' >> Name; | 128 | self_name = '@' >> Name; |
129 | self_class = expr("@@"); | 129 | self_class = "@@"; |
130 | self_class_name = "@@" >> Name; | 130 | self_class_name = "@@" >> Name; |
131 | 131 | ||
132 | SelfName = sel({self_class_name, self_class, self_name, self}); | 132 | SelfName = sel({self_class_name, self_class, self_name, self}); |
133 | KeyName = SelfName | Name; | 133 | KeyName = SelfName | Name; |
134 | VarArg = expr("..."); | 134 | VarArg = "..."; |
135 | 135 | ||
136 | check_indent = pl::user(Indent, [](const item_t& item) { | 136 | check_indent = pl::user(Indent, [](const item_t& item) { |
137 | int indent = 0; | 137 | int indent = 0; |
@@ -190,122 +190,124 @@ YueParser::YueParser() { | |||
190 | return true; | 190 | return true; |
191 | }); | 191 | }); |
192 | 192 | ||
193 | InBlock = Space >> +(plain_space >> Break) >> Advance >> ensure(Block, PopIndent); | 193 | InBlock = +SpaceBreak >> Advance >> ensure(Block, PopIndent); |
194 | 194 | ||
195 | local_flag = expr('*') | expr('^'); | 195 | local_flag = sel({'*', '^'}); |
196 | local_values = NameList >> -(Space >> expr('=') >> (TableBlock | ExpListLow)); | 196 | local_values = NameList >> -(Space >> '=' >> Space >> (TableBlock | ExpListLow)); |
197 | Local = key("local") >> (Space >> local_flag | local_values); | 197 | Local = key("local") >> Space >> (local_flag | local_values); |
198 | 198 | ||
199 | const_attrib = key("const"); | 199 | const_attrib = key("const"); |
200 | close_attrib = key("close"); | 200 | close_attrib = key("close"); |
201 | local_const_item = sel({Space >> Variable, simple_table, TableLit}); | 201 | local_const_item = sel({Variable, simple_table, TableLit}); |
202 | LocalAttrib = ( | 202 | LocalAttrib = ( |
203 | const_attrib >> Seperator >> local_const_item >> *(Space >> expr(',') >> local_const_item) | | 203 | const_attrib >> Seperator >> Space >> local_const_item >> *(Space >> ',' >> Space >> local_const_item) | |
204 | close_attrib >> Seperator >> Space >> Variable >> *(Space >> expr(',') >> Space >> Variable) | 204 | close_attrib >> Seperator >> Space >> Variable >> *(Space >> ',' >> Space >> Variable) |
205 | ) >> Assign; | 205 | ) >> Space >> Assign; |
206 | 206 | ||
207 | colon_import_name = Space >> expr('\\') >> Space >> Variable; | 207 | colon_import_name = '\\' >> Space >> Variable; |
208 | ImportName = colon_import_name | Space >> Variable; | 208 | ImportName = colon_import_name | Variable; |
209 | ImportNameList = Seperator >> *SpaceBreak >> ImportName >> *((+SpaceBreak | Space >> expr(',') >> *SpaceBreak) >> ImportName); | 209 | ImportNameList = Seperator >> *SpaceBreak >> Space >> ImportName >> *((+SpaceBreak | Space >> ',' >> *SpaceBreak) >> Space >> ImportName); |
210 | ImportFrom = ImportNameList >> *SpaceBreak >> Space >> key("from") >> Exp; | 210 | ImportFrom = ImportNameList >> *SpaceBreak >> Space >> key("from") >> Space >> Exp; |
211 | 211 | ||
212 | import_literal_inner = (range('a', 'z') | range('A', 'Z') | set("_-")) >> *(AlphaNum | '-'); | 212 | import_literal_inner = sel({range('a', 'z'), range('A', 'Z'), set("_-")}) >> *(AlphaNum | '-'); |
213 | import_literal_chain = Seperator >> import_literal_inner >> *(expr('.') >> import_literal_inner); | 213 | import_literal_chain = Seperator >> import_literal_inner >> *('.' >> import_literal_inner); |
214 | ImportLiteral = Space >> expr('\'') >> import_literal_chain >> expr('\'') | Space >> expr('"') >> import_literal_chain >> expr('"'); | 214 | ImportLiteral = sel({ |
215 | '\'' >> import_literal_chain >> '\'', | ||
216 | '"' >> import_literal_chain >> '"' | ||
217 | }); | ||
215 | 218 | ||
216 | macro_name_pair = Space >> MacroName >> Space >> expr(':') >> Space >> MacroName; | 219 | macro_name_pair = MacroName >> ':' >> Space >> MacroName; |
217 | import_all_macro = expr('$'); | 220 | import_all_macro = '$'; |
218 | ImportTabItem = sel({ | 221 | ImportTabItem = sel({ |
219 | variable_pair, | 222 | variable_pair, |
220 | normal_pair, | 223 | normal_pair, |
221 | Space >> expr(':') >> MacroName, | 224 | ':' >> MacroName, |
222 | macro_name_pair, | 225 | macro_name_pair, |
223 | Space >> import_all_macro, | 226 | import_all_macro, |
224 | meta_variable_pair, | 227 | meta_variable_pair, |
225 | meta_normal_pair, | 228 | meta_normal_pair, |
226 | Exp | 229 | Exp |
227 | }); | 230 | }); |
228 | ImportTabList = ImportTabItem >> *(Space >> expr(',') >> ImportTabItem); | 231 | ImportTabList = ImportTabItem >> *(Space >> ',' >> Space >> ImportTabItem); |
229 | ImportTabLine = ( | 232 | ImportTabLine = ( |
230 | PushIndent >> (ImportTabList >> PopIndent | PopIndent) | 233 | PushIndent >> (Space >> ImportTabList >> PopIndent | PopIndent) |
231 | ) | Space; | 234 | ) | Space; |
232 | import_tab_lines = SpaceBreak >> ImportTabLine >> *(-(Space >> expr(',')) >> SpaceBreak >> ImportTabLine) >> -(Space >> expr(',')); | 235 | import_tab_lines = SpaceBreak >> ImportTabLine >> *(-(Space >> ',') >> SpaceBreak >> ImportTabLine) >> -(Space >> ','); |
233 | ImportTabLit = seq({ | 236 | ImportTabLit = seq({ |
234 | Seperator, | 237 | '{', Seperator, |
235 | Space, expr('{'), | 238 | -(Space >> ImportTabList), |
236 | -ImportTabList, | 239 | -(Space >> ','), |
237 | -(Space >> expr(',')), | ||
238 | -import_tab_lines, | 240 | -import_tab_lines, |
239 | White, | 241 | White, |
240 | expr('}') | 242 | '}' |
241 | }) | seq({ | 243 | }) | seq({ |
242 | Seperator, KeyValue, *(Space >> expr(',') >> KeyValue) | 244 | Seperator, KeyValue, *(Space >> ',' >> Space >> KeyValue) |
243 | }); | 245 | }); |
244 | 246 | ||
245 | ImportAs = ImportLiteral >> -(Space >> key("as") >> Space >> (ImportTabLit | Variable | import_all_macro)); | 247 | ImportAs = ImportLiteral >> -(Space >> key("as") >> Space >> sel({ImportTabLit, Variable, import_all_macro})); |
246 | 248 | ||
247 | Import = key("import") >> (ImportAs | ImportFrom); | 249 | Import = key("import") >> Space >> (ImportAs | ImportFrom); |
248 | 250 | ||
249 | Label = expr("::") >> LabelName >> expr("::"); | 251 | Label = "::" >> LabelName >> "::"; |
250 | 252 | ||
251 | Goto = key("goto") >> Space >> LabelName; | 253 | Goto = key("goto") >> Space >> LabelName; |
252 | 254 | ||
253 | ShortTabAppending = expr("[]") >> Assign; | 255 | ShortTabAppending = "[]" >> Space >> Assign; |
254 | 256 | ||
255 | BreakLoop = (expr("break") | expr("continue")) >> not_(AlphaNum); | 257 | BreakLoop = sel({"break", "continue"}) >> not_(AlphaNum); |
256 | 258 | ||
257 | Return = key("return") >> -(TableBlock | ExpListLow); | 259 | Return = key("return") >> -(Space >> (TableBlock | ExpListLow)); |
258 | 260 | ||
259 | WithExp = ExpList >> -Assign; | 261 | WithExp = ExpList >> -(Space >> Assign); |
260 | 262 | ||
261 | With = Space >> key("with") >> -existential_op >> disable_do_chain_arg_table_block(WithExp) >> body_with("do"); | 263 | With = key("with") >> -existential_op >> Space >> disable_do_chain_arg_table_block(WithExp) >> Space >> body_with("do"); |
262 | SwitchCase = Space >> key("when") >> disable_chain(disable_arg_table_block(SwitchList)) >> body_with("then"); | 264 | SwitchCase = key("when") >> disable_chain(disable_arg_table_block(SwitchList)) >> Space >> body_with("then"); |
263 | SwitchElse = Space >> key("else") >> body; | 265 | SwitchElse = key("else") >> Space >> body; |
264 | 266 | ||
265 | SwitchBlock = | 267 | SwitchBlock = |
266 | *(Break >> *EmptyLine >> CheckIndent >> SwitchCase) >> | 268 | *(Break >> *EmptyLine >> CheckIndent >> Space >> SwitchCase) >> |
267 | -(Break >> *EmptyLine >> CheckIndent >> SwitchElse); | 269 | -(Break >> *EmptyLine >> CheckIndent >> Space >> SwitchElse); |
268 | 270 | ||
269 | exp_not_tab = not_(simple_table | TableLit) >> Exp; | 271 | exp_not_tab = not_(simple_table | TableLit) >> Space >> Exp; |
270 | 272 | ||
271 | SwitchList = Seperator >> ( | 273 | SwitchList = Seperator >> ( |
272 | and_(simple_table | TableLit) >> Exp | | 274 | and_(simple_table | TableLit) >> Space >> Exp | |
273 | exp_not_tab >> *(Space >> expr(',') >> exp_not_tab) | 275 | exp_not_tab >> *(Space >> ',' >> exp_not_tab) |
274 | ); | 276 | ); |
275 | Switch = Space >> key("switch") >> Exp >> | 277 | Switch = key("switch") >> Space >> Exp >> |
276 | Seperator >> ( | 278 | Space >> Seperator >> ( |
277 | SwitchCase >> Space >> ( | 279 | SwitchCase >> Space >> ( |
278 | Break >> *EmptyLine >> CheckIndent >> SwitchCase >> SwitchBlock | | 280 | Break >> *EmptyLine >> CheckIndent >> Space >> SwitchCase >> SwitchBlock | |
279 | *SwitchCase >> -SwitchElse | 281 | *(Space >> SwitchCase) >> -(Space >> SwitchElse) |
280 | ) | | 282 | ) | |
281 | SpaceBreak >> *EmptyLine >> Advance >> SwitchCase >> SwitchBlock >> PopIndent | 283 | SpaceBreak >> *EmptyLine >> Advance >> Space >> SwitchCase >> SwitchBlock >> PopIndent |
282 | ) >> SwitchBlock; | 284 | ) >> SwitchBlock; |
283 | 285 | ||
284 | assignment = ExpList >> Assign; | 286 | assignment = ExpList >> Space >> Assign; |
285 | IfCond = disable_chain(disable_arg_table_block(assignment | Exp)); | 287 | IfCond = disable_chain(disable_arg_table_block(assignment | Exp)); |
286 | IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("elseif") >> IfCond >> body_with("then"); | 288 | IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("elseif") >> Space >> IfCond >> Space >> body_with("then"); |
287 | IfElse = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("else") >> body; | 289 | IfElse = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("else") >> Space >> body; |
288 | IfType = (expr("if") | expr("unless")) >> not_(AlphaNum); | 290 | IfType = sel({"if", "unless"}) >> not_(AlphaNum); |
289 | If = seq({Space, IfType, IfCond, opt_body_with("then"), *IfElseIf, -IfElse}); | 291 | If = seq({IfType, Space, IfCond, Space, opt_body_with("then"), *IfElseIf, -IfElse}); |
290 | 292 | ||
291 | WhileType = (expr("while") | expr("until")) >> not_(AlphaNum); | 293 | WhileType = sel({"while", "until"}) >> not_(AlphaNum); |
292 | While = WhileType >> disable_do_chain_arg_table_block(Exp) >> opt_body_with("do"); | 294 | While = WhileType >> Space >> disable_do_chain_arg_table_block(Exp) >> Space >> opt_body_with("do"); |
293 | Repeat = seq({key("repeat"), Body, Break, *EmptyLine, CheckIndent, Space, key("until"), Exp}); | 295 | Repeat = seq({key("repeat"), Space, Body, Break, *EmptyLine, CheckIndent, Space, key("until"), Space, Exp}); |
294 | 296 | ||
295 | for_step_value = Space >> expr(',') >> Exp; | 297 | for_step_value = ',' >> Space >> Exp; |
296 | for_args = Space >> Variable >> Space >> expr('=') >> Exp >> Space >> expr(',') >> Exp >> -for_step_value; | 298 | for_args = Variable >> Space >> '=' >> Space >> Exp >> Space >> ',' >> Space >> Exp >> Space >> -for_step_value; |
297 | 299 | ||
298 | For = key("for") >> disable_do_chain_arg_table_block(for_args) >> opt_body_with("do"); | 300 | For = key("for") >> Space >> disable_do_chain_arg_table_block(for_args) >> Space >> opt_body_with("do"); |
299 | 301 | ||
300 | for_in = star_exp | ExpList; | 302 | for_in = star_exp | ExpList; |
301 | 303 | ||
302 | ForEach = key("for") >> AssignableNameList >> Space >> key("in") >> | 304 | ForEach = key("for") >> Space >> AssignableNameList >> Space >> key("in") >> Space >> |
303 | disable_do_chain_arg_table_block(for_in) >> opt_body_with("do"); | 305 | disable_do_chain_arg_table_block(for_in) >> Space >> opt_body_with("do"); |
304 | 306 | ||
305 | Do = pl::user(Space >> key("do"), [](const item_t& item) { | 307 | Do = pl::user(key("do"), [](const item_t& item) { |
306 | State* st = reinterpret_cast<State*>(item.user_data); | 308 | State* st = reinterpret_cast<State*>(item.user_data); |
307 | return st->noDoStack.empty() || !st->noDoStack.top(); | 309 | return st->noDoStack.empty() || !st->noDoStack.top(); |
308 | }) >> Body; | 310 | }) >> Space >> Body; |
309 | 311 | ||
310 | DisableDo = pl::user(true_(), [](const item_t& item) { | 312 | DisableDo = pl::user(true_(), [](const item_t& item) { |
311 | State* st = reinterpret_cast<State*>(item.user_data); | 313 | State* st = reinterpret_cast<State*>(item.user_data); |
@@ -347,73 +349,61 @@ YueParser::YueParser() { | |||
347 | return true; | 349 | return true; |
348 | }); | 350 | }); |
349 | 351 | ||
350 | catch_block = Break >> *EmptyLine >> CheckIndent >> Space >> key("catch") >> Space >> Variable >> InBlock; | 352 | catch_block = Break >> *EmptyLine >> CheckIndent >> Space >> key("catch") >> Space >> Variable >> Space >> InBlock; |
351 | Try = Space >> key("try") >> (InBlock | Exp) >> -catch_block; | 353 | Try = key("try") >> Space >> (InBlock | Exp) >> -catch_block; |
352 | 354 | ||
353 | Comprehension = Space >> expr('[') >> not_('[') >> Exp >> Space >> CompInner >> Space >> expr(']'); | 355 | Comprehension = '[' >> not_('[') >> Space >> Exp >> Space >> CompInner >> Space >> ']'; |
354 | comp_value = Space >> expr(',') >> Exp; | 356 | comp_value = ',' >> Space >> Exp; |
355 | TblComprehension = Space >> expr('{') >> Exp >> -comp_value >> Space >> CompInner >> Space >> expr('}'); | 357 | TblComprehension = '{' >> Space >> Exp >> Space >> -(comp_value >> Space) >> CompInner >> Space >> '}'; |
356 | 358 | ||
357 | CompInner = Seperator >> (CompForEach | CompFor) >> *CompClause; | 359 | CompInner = Seperator >> (CompForEach | CompFor) >> *(Space >> CompClause); |
358 | star_exp = Space >> expr('*') >> Exp; | 360 | star_exp = '*' >> Space >> Exp; |
359 | CompForEach = key("for") >> AssignableNameList >> Space >> key("in") >> (star_exp | Exp); | 361 | CompForEach = key("for") >> Space >> AssignableNameList >> Space >> key("in") >> Space >> (star_exp | Exp); |
360 | CompFor = key("for") >> Space >> Variable >> Space >> expr('=') >> Exp >> Space >> expr(',') >> Exp >> -for_step_value; | 362 | CompFor = key("for") >> Space >> Variable >> Space >> '=' >> Space >> Exp >> Space >> ',' >> Space >> Exp >> -for_step_value; |
361 | CompClause = Space >> sel({CompFor, CompForEach, key("when") >> Exp}); | 363 | CompClause = sel({CompFor, CompForEach, key("when") >> Space >> Exp}); |
362 | 364 | ||
363 | Assign = Space >> expr('=') >> Seperator >> sel({ | 365 | Assign = '=' >> Space >> Seperator >> sel({ |
364 | With, If, Switch, TableBlock, | 366 | With, If, Switch, TableBlock, |
365 | Exp >> *(Space >> set(",;") >> Exp) | 367 | Exp >> *(Space >> set(",;") >> Space >> Exp) |
366 | }); | 368 | }); |
367 | 369 | ||
368 | update_op = sel({ | 370 | update_op = sel({ |
369 | expr(".."), | 371 | "..", "//", "or", "and", |
370 | expr("//"), | 372 | ">>", "<<", "??", |
371 | expr("or"), | ||
372 | expr("and"), | ||
373 | expr(">>"), | ||
374 | expr("<<"), | ||
375 | expr("??"), | ||
376 | set("+-*/%&|") | 373 | set("+-*/%&|") |
377 | }); | 374 | }); |
378 | 375 | ||
379 | Update = Space >> update_op >> expr("=") >> Exp; | 376 | Update = update_op >> '=' >> Space >> Exp; |
380 | 377 | ||
381 | Assignable = Space >> sel({AssignableChain, Variable, SelfName}); | 378 | Assignable = sel({AssignableChain, Variable, SelfName}); |
382 | 379 | ||
383 | unary_value = +(unary_operator >> Space) >> Value; | 380 | unary_value = +(unary_operator >> Space) >> Value; |
384 | 381 | ||
385 | ExponentialOperator = expr('^'); | 382 | ExponentialOperator = '^'; |
386 | expo_value = seq({Space, ExponentialOperator, *SpaceBreak, Space, Value}); | 383 | expo_value = seq({ExponentialOperator, *SpaceBreak, Space, Value}); |
387 | expo_exp = Value >> *expo_value; | 384 | expo_exp = Value >> *(Space >> expo_value); |
388 | 385 | ||
389 | unary_operator = sel({ | 386 | unary_operator = sel({ |
390 | expr('-') >> not_(set(">=") | space_one), | 387 | '-' >> not_(set(">=") | space_one), |
391 | expr('#'), | 388 | '#', |
392 | expr('~') >> not_(expr('=') | space_one), | 389 | '~' >> not_('=' | space_one), |
393 | expr("not") >> not_(AlphaNum) | 390 | "not" >> not_(AlphaNum) |
394 | }); | 391 | }); |
395 | unary_exp = Space >> *(unary_operator >> Space) >> expo_exp; | 392 | unary_exp = *(unary_operator >> Space) >> expo_exp; |
396 | 393 | ||
397 | PipeOperator = expr("|>"); | 394 | PipeOperator = "|>"; |
398 | pipe_value = seq({Space, PipeOperator, *SpaceBreak, unary_exp}); | 395 | pipe_value = seq({PipeOperator, *SpaceBreak, Space, unary_exp}); |
399 | pipe_exp = unary_exp >> *pipe_value; | 396 | pipe_exp = unary_exp >> *(Space >> pipe_value); |
400 | 397 | ||
401 | BinaryOperator = sel({ | 398 | BinaryOperator = sel({ |
402 | (expr("or") >> not_(AlphaNum)), | 399 | "or" >> not_(AlphaNum), |
403 | (expr("and") >> not_(AlphaNum)), | 400 | "and" >> not_(AlphaNum), |
404 | expr("<="), | 401 | "<=", ">=", "~=", "!=", "==", |
405 | expr(">="), | 402 | "..", "<<", ">>", "//", |
406 | expr("~="), | ||
407 | expr("!="), | ||
408 | expr("=="), | ||
409 | expr(".."), | ||
410 | expr("<<"), | ||
411 | expr(">>"), | ||
412 | expr("//"), | ||
413 | set("+-*/%><|&~") | 403 | set("+-*/%><|&~") |
414 | }); | 404 | }); |
415 | exp_op_value = seq({Space, BinaryOperator, *SpaceBreak, pipe_exp}); | 405 | exp_op_value = seq({BinaryOperator, *SpaceBreak, Space, pipe_exp}); |
416 | Exp = seq({Seperator, pipe_exp, *exp_op_value, -(Space >> expr("??") >> Exp)}); | 406 | Exp = seq({Seperator, pipe_exp, *(Space >> exp_op_value), -(Space >> "??" >> Space >> Exp)}); |
417 | 407 | ||
418 | DisableChain = pl::user(true_(), [](const item_t& item) { | 408 | DisableChain = pl::user(true_(), [](const item_t& item) { |
419 | State* st = reinterpret_cast<State*>(item.user_data); | 409 | State* st = reinterpret_cast<State*>(item.user_data); |
@@ -441,17 +431,17 @@ YueParser::YueParser() { | |||
441 | -table_appending_op | 431 | -table_appending_op |
442 | }); | 432 | }); |
443 | 433 | ||
444 | simple_table = seq({Seperator, KeyValue, *(Space >> expr(',') >> KeyValue)}); | 434 | simple_table = seq({Seperator, KeyValue, *(Space >> ',' >> Space >> KeyValue)}); |
445 | Value = sel({SimpleValue, simple_table, ChainValue, String}); | 435 | Value = sel({SimpleValue, simple_table, ChainValue, String}); |
446 | 436 | ||
447 | single_string_inner = expr('\\') >> set("'\\") | not_(expr('\'')) >> Any; | 437 | single_string_inner = '\\' >> set("'\\") | not_('\'') >> Any; |
448 | SingleString = expr('\'') >> *single_string_inner >> expr('\''); | 438 | SingleString = '\'' >> *single_string_inner >> '\''; |
449 | interp = expr("#{") >> Exp >> Space >> expr('}'); | 439 | interp = "#{" >> Space >> Exp >> Space >> '}'; |
450 | double_string_plain = expr('\\') >> set("\"\\") | not_(expr('"')) >> Any; | 440 | double_string_plain = '\\' >> set("\"\\") | not_('"') >> Any; |
451 | double_string_inner = +(not_(interp) >> double_string_plain); | 441 | double_string_inner = +(not_(interp) >> double_string_plain); |
452 | double_string_content = double_string_inner | interp; | 442 | double_string_content = double_string_inner | interp; |
453 | DoubleString = expr('"') >> Seperator >> *double_string_content >> expr('"'); | 443 | DoubleString = '"' >> Seperator >> *double_string_content >> '"'; |
454 | String = DoubleString | SingleString | LuaString; | 444 | String = sel({DoubleString, SingleString, LuaString}); |
455 | 445 | ||
456 | lua_string_open = '[' >> *expr('=') >> '['; | 446 | lua_string_open = '[' >> *expr('=') >> '['; |
457 | lua_string_close = ']' >> *expr('=') >> ']'; | 447 | lua_string_close = ']' >> *expr('=') >> ']'; |
@@ -473,21 +463,21 @@ YueParser::YueParser() { | |||
473 | 463 | ||
474 | LuaString = LuaStringOpen >> -Break >> LuaStringContent >> LuaStringClose; | 464 | LuaString = LuaStringOpen >> -Break >> LuaStringContent >> LuaStringClose; |
475 | 465 | ||
476 | Parens = pl::user(seq({expr('('), *SpaceBreak, Exp, *SpaceBreak, Space >> expr(')')}), [](const item_t&) { | 466 | Parens = seq({'(', *SpaceBreak, Space, Exp, *SpaceBreak, Space, ')'}); |
477 | return true; | ||
478 | }); | ||
479 | Callable = sel({Variable, SelfName, MacroName, VarArg, Parens}); | 467 | Callable = sel({Variable, SelfName, MacroName, VarArg, Parens}); |
480 | FnArgsExpList = Exp >> *seq({Break | Space >> expr(','), White, Exp}); | 468 | FnArgsExpList = Space >> Exp >> Space >> *seq({Break | ',', White, Exp}); |
481 | 469 | ||
482 | FnArgs = seq({expr('('), *SpaceBreak, -FnArgsExpList, *SpaceBreak, Space, expr(')')}) | | 470 | FnArgs = sel({ |
483 | seq({Space, expr('!'), not_(expr('='))}); | 471 | seq({'(', *SpaceBreak, -FnArgsExpList, *SpaceBreak, Space, ')'}), |
472 | seq({Space, '!', not_('=')}) | ||
473 | }); | ||
484 | 474 | ||
485 | meta_index = sel({Name, Index, String}); | 475 | meta_index = sel({Name, Index, String}); |
486 | Metatable = expr('<') >> Space >> expr('>'); | 476 | Metatable = '<' >> Space >> '>'; |
487 | Metamethod = expr('<') >> Space >> meta_index >> Space >> expr('>'); | 477 | Metamethod = '<' >> Space >> meta_index >> Space >> '>'; |
488 | 478 | ||
489 | existential_op = expr('?') >> not_(expr('?')); | 479 | existential_op = '?' >> not_('?'); |
490 | table_appending_op = expr("[]"); | 480 | table_appending_op = "[]"; |
491 | chain_call = seq({ | 481 | chain_call = seq({ |
492 | Callable, | 482 | Callable, |
493 | -existential_op, | 483 | -existential_op, |
@@ -516,37 +506,37 @@ YueParser::YueParser() { | |||
516 | chain_with_colon = +ChainItem >> -ColonChain; | 506 | chain_with_colon = +ChainItem >> -ColonChain; |
517 | ChainItems = chain_with_colon | ColonChain; | 507 | ChainItems = chain_with_colon | ColonChain; |
518 | 508 | ||
519 | Index = seq({expr('['), not_('['), Exp, Space, expr(']')}); | 509 | Index = seq({'[', not_('['), Space, Exp, Space, ']'}); |
520 | ChainItem = sel({ | 510 | ChainItem = sel({ |
521 | Invoke >> -existential_op, | 511 | Invoke >> -existential_op, |
522 | DotChainItem >> -existential_op, | 512 | DotChainItem >> -existential_op, |
523 | Slice, | 513 | Slice, |
524 | Index >> -existential_op | 514 | Index >> -existential_op |
525 | }); | 515 | }); |
526 | DotChainItem = expr('.') >> sel({Name, Metatable, Metamethod}); | 516 | DotChainItem = '.' >> sel({Name, Metatable, Metamethod}); |
527 | ColonChainItem = (expr('\\') | expr("::")) >> sel({LuaKeyword, Name, Metamethod}); | 517 | ColonChainItem = sel({'\\', "::"}) >> sel({LuaKeyword, Name, Metamethod}); |
528 | invoke_chain = Invoke >> -existential_op >> -ChainItems; | 518 | invoke_chain = Invoke >> -existential_op >> -ChainItems; |
529 | ColonChain = ColonChainItem >> -existential_op >> -invoke_chain; | 519 | ColonChain = ColonChainItem >> -existential_op >> -invoke_chain; |
530 | 520 | ||
531 | default_value = true_(); | 521 | default_value = true_(); |
532 | Slice = seq({ | 522 | Slice = seq({ |
533 | expr('['), not_('['), | 523 | '[', not_('['), |
534 | Exp | default_value, | 524 | Space, Exp | default_value, |
535 | Space, expr(','), | 525 | Space, ',', |
536 | Exp | default_value, | 526 | Space, Exp | default_value, |
537 | Space >> expr(',') >> Exp | default_value, | 527 | Space, ',' >> Space >> Exp | default_value, |
538 | Space, expr(']') | 528 | Space, ']' |
539 | }); | 529 | }); |
540 | 530 | ||
541 | Invoke = Seperator >> sel({ | 531 | Invoke = Seperator >> sel({ |
542 | FnArgs, | 532 | FnArgs, |
543 | SingleString, | 533 | SingleString, |
544 | DoubleString, | 534 | DoubleString, |
545 | and_(expr('[')) >> LuaString, | 535 | and_('[') >> LuaString, |
546 | and_(expr('{')) >> TableLit | 536 | and_('{') >> TableLit |
547 | }); | 537 | }); |
548 | 538 | ||
549 | SpreadExp = Space >> expr("...") >> Exp; | 539 | SpreadExp = "..." >> Space >> Exp; |
550 | 540 | ||
551 | TableValue = sel({ | 541 | TableValue = sel({ |
552 | variable_pair_def, | 542 | variable_pair_def, |
@@ -557,47 +547,47 @@ YueParser::YueParser() { | |||
557 | normal_def | 547 | normal_def |
558 | }); | 548 | }); |
559 | 549 | ||
560 | table_lit_lines = SpaceBreak >> TableLitLine >> *(-(Space >> expr(',')) >> SpaceBreak >> TableLitLine) >> -(Space >> expr(',')); | 550 | table_lit_lines = SpaceBreak >> TableLitLine >> *(-(Space >> ',') >> SpaceBreak >> TableLitLine) >> -(Space >> ','); |
561 | 551 | ||
562 | TableLit = seq({ | 552 | TableLit = seq({ |
563 | Space, expr('{'), Seperator, | 553 | Space, '{', Seperator, |
564 | -TableValueList, | 554 | -(Space >> TableValueList), |
565 | -(Space >> expr(',')), | 555 | -(Space >> ','), |
566 | -table_lit_lines, | 556 | -table_lit_lines, |
567 | White, expr('}') | 557 | White, '}' |
568 | }); | 558 | }); |
569 | 559 | ||
570 | TableValueList = TableValue >> *(Space >> expr(',') >> TableValue); | 560 | TableValueList = TableValue >> *(Space >> ',' >> Space >> TableValue); |
571 | 561 | ||
572 | TableLitLine = ( | 562 | TableLitLine = ( |
573 | PushIndent >> (TableValueList >> PopIndent | PopIndent) | 563 | PushIndent >> (Space >> TableValueList >> PopIndent | PopIndent) |
574 | ) | ( | 564 | ) | ( |
575 | Space | 565 | Space |
576 | ); | 566 | ); |
577 | 567 | ||
578 | TableBlockInner = Seperator >> KeyValueLine >> *(+SpaceBreak >> KeyValueLine); | 568 | TableBlockInner = Seperator >> KeyValueLine >> *(+SpaceBreak >> KeyValueLine); |
579 | TableBlock = +SpaceBreak >> Advance >> ensure(TableBlockInner, PopIndent); | 569 | TableBlock = +SpaceBreak >> Advance >> ensure(TableBlockInner, PopIndent); |
580 | TableBlockIndent = Space >> expr('*') >> Seperator >> disable_arg_table_block( | 570 | TableBlockIndent = '*' >> Seperator >> disable_arg_table_block( |
581 | KeyValueList >> -(Space >> expr(',')) >> | 571 | Space >> KeyValueList >> -(Space >> ',') >> |
582 | -(+SpaceBreak >> Advance >> ensure(KeyValueList >> -(Space >> expr(',')) >> *(+SpaceBreak >> KeyValueLine), PopIndent))); | 572 | -(+SpaceBreak >> Advance >> Space >> ensure(KeyValueList >> -(Space >> ',') >> *(+SpaceBreak >> KeyValueLine), PopIndent))); |
583 | 573 | ||
584 | class_member_list = Seperator >> KeyValue >> *(Space >> expr(',') >> KeyValue); | 574 | class_member_list = Seperator >> KeyValue >> *(Space >> ',' >> Space >> KeyValue); |
585 | ClassLine = CheckIndent >> (class_member_list | Space >> Statement) >> -(Space >> expr(',')); | 575 | ClassLine = CheckIndent >> Space >> (class_member_list | Statement) >> -(Space >> ','); |
586 | ClassBlock = seq({+SpaceBreak, Advance, Seperator, ClassLine, *(+SpaceBreak >> ClassLine), PopIndent}); | 576 | ClassBlock = seq({+SpaceBreak, Advance, Seperator, ClassLine, *(+SpaceBreak >> ClassLine), PopIndent}); |
587 | 577 | ||
588 | ClassDecl = seq({ | 578 | ClassDecl = seq({ |
589 | Space, key("class"), not_(expr(':')), | 579 | key("class"), not_(':'), |
590 | disable_arg_table_block(seq({ | 580 | disable_arg_table_block(seq({ |
591 | -Assignable, | 581 | -(Space >> Assignable), |
592 | -seq({Space, key("extends"), PreventIndent, ensure(Exp, PopIndent)}), | 582 | -seq({Space, key("extends"), PreventIndent, Space, ensure(Exp, PopIndent)}), |
593 | -seq({Space, key("using"), PreventIndent, ensure(ExpList, PopIndent)}) | 583 | -seq({Space, key("using"), PreventIndent, Space, ensure(ExpList, PopIndent)}) |
594 | })), | 584 | })), |
595 | -ClassBlock | 585 | -ClassBlock |
596 | }); | 586 | }); |
597 | 587 | ||
598 | global_values = NameList >> -(Space >> expr('=') >> (TableBlock | ExpListLow)); | 588 | global_values = NameList >> -(Space >> '=' >> Space >> (TableBlock | ExpListLow)); |
599 | global_op = expr('*') | expr('^'); | 589 | global_op = sel({'*', '^'}); |
600 | Global = key("global") >> sel({ClassDecl, Space >> global_op, global_values}); | 590 | Global = key("global") >> Space >> sel({ClassDecl, global_op, global_values}); |
601 | 591 | ||
602 | export_default = key("default"); | 592 | export_default = key("default"); |
603 | 593 | ||
@@ -605,7 +595,7 @@ YueParser::YueParser() { | |||
605 | State* st = reinterpret_cast<State*>(item.user_data); | 595 | State* st = reinterpret_cast<State*>(item.user_data); |
606 | st->exportCount++; | 596 | st->exportCount++; |
607 | return true; | 597 | return true; |
608 | }) >> (pl::user(Space >> export_default >> Exp, [](const item_t& item) { | 598 | }) >> (pl::user(Space >> export_default >> Space >> Exp, [](const item_t& item) { |
609 | State* st = reinterpret_cast<State*>(item.user_data); | 599 | State* st = reinterpret_cast<State*>(item.user_data); |
610 | if (st->exportDefault) { | 600 | if (st->exportDefault) { |
611 | throw ParserError("export default has already been declared", *item.begin, *item.end); | 601 | throw ParserError("export default has already been declared", *item.begin, *item.end); |
@@ -622,32 +612,31 @@ YueParser::YueParser() { | |||
622 | throw ParserError("can not export any more items when 'export default' is declared", *item.begin, *item.end); | 612 | throw ParserError("can not export any more items when 'export default' is declared", *item.begin, *item.end); |
623 | } | 613 | } |
624 | return true; | 614 | return true; |
625 | }) >> ExpList >> -Assign) | 615 | }) >> Space >> ExpList >> -(Space >> Assign)) |
626 | | Space >> pl::user(Macro, [](const item_t& item) { | 616 | | Space >> pl::user(Macro, [](const item_t& item) { |
627 | State* st = reinterpret_cast<State*>(item.user_data); | 617 | State* st = reinterpret_cast<State*>(item.user_data); |
628 | st->exportMacro = true; | 618 | st->exportMacro = true; |
629 | return true; | 619 | return true; |
630 | })) >> not_(Space >> statement_appendix); | 620 | })) >> not_(Space >> statement_appendix); |
631 | 621 | ||
632 | variable_pair = Space >> expr(':') >> Variable; | 622 | variable_pair = ':' >> Variable; |
633 | 623 | ||
634 | normal_pair = seq({ | 624 | normal_pair = seq({ |
635 | Space, | ||
636 | sel({ | 625 | sel({ |
637 | KeyName, | 626 | KeyName, |
638 | seq({expr('['), not_('['), Exp, Space >> expr(']')}), | 627 | seq({'[', not_('['), Space, Exp, Space, ']'}), |
639 | String | 628 | String |
640 | }), | 629 | }), |
641 | expr(':'), not_(':'), | 630 | ':', not_(':'), Space, |
642 | sel({Exp, TableBlock, +SpaceBreak >> Exp}) | 631 | sel({Exp, TableBlock, +SpaceBreak >> Space >> Exp}) |
643 | }); | 632 | }); |
644 | 633 | ||
645 | meta_variable_pair = Space >> expr(":<") >> Space >> Variable >> Space >> expr('>'); | 634 | meta_variable_pair = ":<" >> Space >> Variable >> Space >> '>'; |
646 | 635 | ||
647 | meta_normal_pair = Space >> expr('<') >> Space >> -meta_index >> Space >> expr(">:") >> | 636 | meta_normal_pair = '<' >> Space >> -meta_index >> Space >> ">:" >> Space >> |
648 | sel({Exp, TableBlock, +(SpaceBreak) >> Exp}); | 637 | sel({Exp, TableBlock, +(SpaceBreak) >> Space >> Exp}); |
649 | 638 | ||
650 | destruct_def = -seq({Space, expr('='), Exp}); | 639 | destruct_def = -seq({Space, '=', Space, Exp}); |
651 | variable_pair_def = variable_pair >> destruct_def; | 640 | variable_pair_def = variable_pair >> destruct_def; |
652 | normal_pair_def = normal_pair >> destruct_def; | 641 | normal_pair_def = normal_pair >> destruct_def; |
653 | meta_variable_pair_def = meta_variable_pair >> destruct_def; | 642 | meta_variable_pair_def = meta_variable_pair >> destruct_def; |
@@ -660,55 +649,56 @@ YueParser::YueParser() { | |||
660 | meta_variable_pair, | 649 | meta_variable_pair, |
661 | meta_normal_pair | 650 | meta_normal_pair |
662 | }); | 651 | }); |
663 | KeyValueList = KeyValue >> *(Space >> expr(',') >> KeyValue); | 652 | KeyValueList = KeyValue >> *(Space >> ',' >> Space >> KeyValue); |
664 | KeyValueLine = CheckIndent >> sel({ | 653 | KeyValueLine = CheckIndent >> Space >> sel({ |
665 | KeyValueList >> -(Space >> expr(',')), | 654 | KeyValueList >> -(Space >> ','), |
666 | TableBlockIndent, | 655 | TableBlockIndent, |
667 | Space >> expr('*') >> sel({SpreadExp, Exp, TableBlock}) | 656 | '*' >> Space >> sel({SpreadExp, Exp, TableBlock}) |
668 | }); | 657 | }); |
669 | 658 | ||
670 | FnArgDef = (Variable | SelfName >> -existential_op) >> -(Space >> expr('=') >> Space >> Exp); | 659 | FnArgDef = (Variable | SelfName >> -existential_op) >> -(Space >> '=' >> Space >> Exp); |
671 | 660 | ||
672 | FnArgDefList = Space >> Seperator >> ( | 661 | FnArgDefList = Seperator >> ( |
673 | seq({ | 662 | seq({ |
674 | FnArgDef, | 663 | FnArgDef, |
675 | *seq({(Space >> expr(',') | Break), White, FnArgDef}), | 664 | *seq({Space, ',' | Break, White, FnArgDef}), |
676 | -seq({(Space >> expr(',') | Break), White, VarArg}) | 665 | -seq({Space, ',' | Break, White, VarArg}) |
677 | }) | | 666 | }) | |
678 | VarArg | 667 | VarArg |
679 | ); | 668 | ); |
680 | 669 | ||
681 | outer_var_shadow = Space >> key("using") >> (NameList | Space >> expr("nil")); | 670 | outer_var_shadow = key("using") >> Space >> (NameList | key("nil")); |
682 | 671 | ||
683 | FnArgsDef = seq({Space, expr('('), White, -FnArgDefList, -outer_var_shadow, White, Space, expr(')')}); | 672 | FnArgsDef = seq({'(', White, -FnArgDefList, -(Space >> outer_var_shadow), White, ')'}); |
684 | fn_arrow = expr("->") | expr("=>"); | 673 | fn_arrow = sel({"->", "=>"}); |
685 | FunLit = seq({-FnArgsDef, Space, fn_arrow, -Body}); | 674 | FunLit = seq({-FnArgsDef, Space, fn_arrow, -(Space >> Body)}); |
686 | 675 | ||
687 | MacroName = expr('$') >> Name; | 676 | MacroName = '$' >> Name; |
688 | macro_args_def = Space >> expr('(') >> White >> -FnArgDefList >> White >> Space >> expr(')'); | 677 | macro_args_def = '(' >> White >> -FnArgDefList >> White >> ')'; |
689 | MacroLit = -macro_args_def >> Space >> expr("->") >> Body; | 678 | MacroLit = -(macro_args_def >> Space) >> "->" >> Space >> Body; |
690 | Macro = key("macro") >> Space >> Name >> Space >> expr('=') >> MacroLit; | 679 | Macro = key("macro") >> Space >> Name >> Space >> '=' >> Space >> MacroLit; |
691 | MacroInPlace = expr('$') >> Space >> expr("->") >> Body; | 680 | MacroInPlace = '$' >> Space >> "->" >> Space >> Body; |
692 | 681 | ||
693 | NameList = Seperator >> Space >> Variable >> *(Space >> expr(',') >> Space >> Variable); | 682 | NameList = Seperator >> Variable >> *(Space >> ',' >> Space >> Variable); |
694 | NameOrDestructure = Space >> Variable | TableLit; | 683 | NameOrDestructure = Variable | TableLit; |
695 | AssignableNameList = Seperator >> NameOrDestructure >> *(Space >> expr(',') >> NameOrDestructure); | 684 | AssignableNameList = Seperator >> NameOrDestructure >> *(Space >> ',' >> Space >> NameOrDestructure); |
696 | 685 | ||
697 | fn_arrow_back = expr('<') >> set("-="); | 686 | fn_arrow_back = '<' >> set("-="); |
698 | Backcall = seq({-FnArgsDef, Space, fn_arrow_back, Space, ChainValue}); | 687 | Backcall = seq({-(FnArgsDef >> Space), fn_arrow_back, Space, ChainValue}); |
699 | 688 | ||
700 | PipeBody = seq({ | 689 | PipeBody = seq({ |
701 | Seperator, | 690 | Seperator, |
702 | PipeOperator, | 691 | PipeOperator, |
692 | Space, | ||
703 | unary_exp, | 693 | unary_exp, |
704 | *seq({+SpaceBreak, CheckIndent, Space, PipeOperator, unary_exp}) | 694 | *seq({+SpaceBreak, CheckIndent, Space, PipeOperator, Space, unary_exp}) |
705 | }); | 695 | }); |
706 | 696 | ||
707 | ExpList = Seperator >> Exp >> *(Space >> expr(',') >> Exp); | 697 | ExpList = Seperator >> Exp >> *(Space >> ',' >> Space >> Exp); |
708 | ExpListLow = Seperator >> Exp >> *(Space >> set(",;") >> Exp); | 698 | ExpListLow = Seperator >> Exp >> *(Space >> set(",;") >> Space >> Exp); |
709 | 699 | ||
710 | ArgLine = CheckIndent >> Exp >> *(Space >> expr(',') >> Exp); | 700 | ArgLine = CheckIndent >> Space >> Exp >> *(Space >> ',' >> Space >> Exp); |
711 | ArgBlock = ArgLine >> *(Space >> expr(',') >> SpaceBreak >> ArgLine) >> PopIndent; | 701 | ArgBlock = ArgLine >> *(Space >> ',' >> SpaceBreak >> ArgLine) >> PopIndent; |
712 | 702 | ||
713 | arg_table_block = pl::user(true_(), [](const item_t& item) { | 703 | arg_table_block = pl::user(true_(), [](const item_t& item) { |
714 | State* st = reinterpret_cast<State*>(item.user_data); | 704 | State* st = reinterpret_cast<State*>(item.user_data); |
@@ -716,25 +706,25 @@ YueParser::YueParser() { | |||
716 | }) >> TableBlock; | 706 | }) >> TableBlock; |
717 | 707 | ||
718 | invoke_args_with_table = | 708 | invoke_args_with_table = |
719 | Space >> expr(',') >> ( | 709 | ',' >> ( |
720 | TableBlock | | 710 | TableBlock | |
721 | SpaceBreak >> Advance >> ArgBlock >> -arg_table_block | 711 | SpaceBreak >> Advance >> ArgBlock >> -arg_table_block |
722 | ) | arg_table_block; | 712 | ) | arg_table_block; |
723 | 713 | ||
724 | leading_spaces_error = pl::user(+space_one >> expr('(') >> Exp >> +(Space >> expr(',') >> Exp) >> Space >> expr(')'), [](const item_t& item) { | 714 | leading_spaces_error = pl::user(+space_one >> '(' >> Space >> Exp >> +(Space >> ',' >> Space >> Exp) >> Space >> ')', [](const item_t& item) { |
725 | throw ParserError("write invoke arguments in parentheses without leading spaces or just leading spaces without parentheses", *item.begin, *item.end); | 715 | throw ParserError("write invoke arguments in parentheses without leading spaces or just leading spaces without parentheses", *item.begin, *item.end); |
726 | return false; | 716 | return false; |
727 | }); | 717 | }); |
728 | 718 | ||
729 | InvokeArgs = | 719 | InvokeArgs = |
730 | not_(set("-~")) >> Seperator >> | 720 | not_(set("-~")) >> Space >> Seperator >> |
731 | sel({ | 721 | sel({ |
732 | Exp >> *(Space >> expr(',') >> Exp) >> -invoke_args_with_table, | 722 | Exp >> *(Space >> ',' >> Space >> Exp) >> -(Space >> invoke_args_with_table), |
733 | arg_table_block, | 723 | arg_table_block, |
734 | leading_spaces_error | 724 | leading_spaces_error |
735 | }); | 725 | }); |
736 | 726 | ||
737 | const_value = sel({expr("nil"), expr("true"), expr("false")}) >> not_(AlphaNum); | 727 | const_value = sel({"nil", "true", "false"}) >> not_(AlphaNum); |
738 | 728 | ||
739 | SimpleValue = sel({ | 729 | SimpleValue = sel({ |
740 | TableLit, const_value, If, Switch, Try, With, | 730 | TableLit, const_value, If, Switch, Try, With, |
@@ -743,26 +733,33 @@ YueParser::YueParser() { | |||
743 | FunLit, Num | 733 | FunLit, Num |
744 | }); | 734 | }); |
745 | 735 | ||
746 | ExpListAssign = ExpList >> -(Update | Assign) >> not_(Space >> expr('=')); | 736 | ExpListAssign = ExpList >> -(Space >> (Update | Assign)) >> not_(Space >> '='); |
747 | 737 | ||
748 | if_line = Space >> IfType >> IfCond; | 738 | if_line = IfType >> Space >> IfCond; |
749 | while_line = Space >> WhileType >> Exp; | 739 | while_line = WhileType >> Space >> Exp; |
750 | 740 | ||
751 | YueLineComment = *(not_(set("\r\n")) >> Any); | 741 | YueLineComment = *(not_(set("\r\n")) >> Any); |
752 | yue_line_comment = expr("--") >> YueLineComment >> and_(Stop); | 742 | yue_line_comment = "--" >> YueLineComment >> and_(Stop); |
753 | YueMultilineComment = multi_line_content; | 743 | YueMultilineComment = multi_line_content; |
754 | yue_multiline_comment = multi_line_open >> YueMultilineComment >> multi_line_close; | 744 | yue_multiline_comment = multi_line_open >> YueMultilineComment >> multi_line_close; |
755 | yue_comment = check_indent >> (yue_multiline_comment >> *(set(" \t") | yue_multiline_comment) >> -yue_line_comment | yue_line_comment) >> and_(Break); | 745 | yue_comment = check_indent >> sel({ |
746 | seq({ | ||
747 | yue_multiline_comment, | ||
748 | *(set(" \t") | yue_multiline_comment), | ||
749 | -yue_line_comment | ||
750 | }), | ||
751 | yue_line_comment | ||
752 | }) >> and_(Break); | ||
756 | 753 | ||
757 | ChainAssign = Seperator >> Exp >> +(Space >> expr('=') >> Exp >> Space >> and_('=')) >> Assign; | 754 | ChainAssign = Seperator >> Exp >> +(Space >> '=' >> Space >> Exp >> Space >> and_('=')) >> Space >> Assign; |
758 | 755 | ||
759 | statement_appendix = sel({if_line, while_line, CompInner}) >> Space; | 756 | statement_appendix = sel({if_line, while_line, CompInner}) >> Space; |
760 | statement_sep = and_(seq({ | 757 | statement_sep = and_(seq({ |
761 | *SpaceBreak, CheckIndent, Space, | 758 | *SpaceBreak, CheckIndent, Space, |
762 | sel({ | 759 | sel({ |
763 | set("($'\""), | 760 | set("($'\""), |
764 | expr("[["), | 761 | "[[", |
765 | expr("[=") | 762 | "[=" |
766 | }) | 763 | }) |
767 | })); | 764 | })); |
768 | Statement = seq({ | 765 | Statement = seq({ |
@@ -786,7 +783,7 @@ YueParser::YueParser() { | |||
786 | -statement_sep | 783 | -statement_sep |
787 | }); | 784 | }); |
788 | 785 | ||
789 | Body = InBlock | Space >> Statement; | 786 | Body = InBlock | Statement; |
790 | 787 | ||
791 | empty_line_break = sel({ | 788 | empty_line_break = sel({ |
792 | check_indent >> (MultiLineComment >> Space | Comment), | 789 | check_indent >> (MultiLineComment >> Space | Comment), |
@@ -806,7 +803,7 @@ YueParser::YueParser() { | |||
806 | }); | 803 | }); |
807 | Block = seq({Seperator, Line, *(+Break >> Line)}); | 804 | Block = seq({Seperator, Line, *(+Break >> Line)}); |
808 | 805 | ||
809 | Shebang = expr("#!") >> *(not_(Stop) >> Any); | 806 | Shebang = "#!" >> *(not_(Stop) >> Any); |
810 | BlockEnd = seq({Block, White, Stop}); | 807 | BlockEnd = seq({Block, White, Stop}); |
811 | File = seq({-Shebang, -Block, White, Stop}); | 808 | File = seq({-Shebang, -Block, White, Stop}); |
812 | } | 809 | } |