diff options
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
-rwxr-xr-x | src/yuescript/yue_parser.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 258997e..ab9b657 100755 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -75,7 +75,7 @@ YueParser::YueParser() { | |||
75 | #define key(str) (str >> not_(AlphaNum)) | 75 | #define key(str) (str >> not_(AlphaNum)) |
76 | #define disable_do(patt) (DisableDo >> ((patt) >> EnableDo | EnableDo >> Cut)) | 76 | #define disable_do(patt) (DisableDo >> ((patt) >> EnableDo | EnableDo >> Cut)) |
77 | #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut)) | 77 | #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut)) |
78 | #define disable_do_chain(patt) (DisableDoChain >> ((patt) >> EnableDoChain | EnableDoChain >> Cut)) | 78 | #define disable_do_chain_arg_table_block(patt) (DisableDoChainArgTableBlock >> ((patt) >> EnableDoChainArgTableBlock | EnableDoChainArgTableBlock >> Cut)) |
79 | #define disable_arg_table_block(patt) (DisableArgTableBlock >> ((patt) >> EnableArgTableBlock | EnableArgTableBlock >> Cut)) | 79 | #define disable_arg_table_block(patt) (DisableArgTableBlock >> ((patt) >> EnableArgTableBlock | EnableArgTableBlock >> Cut)) |
80 | #define plain_body_with(str) (-(Space >> key(str)) >> InBlock | Space >> key(str) >> Statement) | 80 | #define plain_body_with(str) (-(Space >> key(str)) >> InBlock | Space >> key(str) >> Statement) |
81 | #define plain_body (InBlock | Statement) | 81 | #define plain_body (InBlock | Statement) |
@@ -223,8 +223,8 @@ YueParser::YueParser() { | |||
223 | 223 | ||
224 | WithExp = ExpList >> -Assign; | 224 | WithExp = ExpList >> -Assign; |
225 | 225 | ||
226 | With = Space >> key("with") >> -existential_op >> disable_do_chain(WithExp) >> plain_body_with("do"); | 226 | With = Space >> key("with") >> -existential_op >> disable_do_chain_arg_table_block(WithExp) >> plain_body_with("do"); |
227 | SwitchCase = Space >> key("when") >> disable_chain(ExpList) >> plain_body_with("then"); | 227 | SwitchCase = Space >> key("when") >> disable_chain(disable_arg_table_block(ExpList)) >> plain_body_with("then"); |
228 | SwitchElse = Space >> key("else") >> plain_body; | 228 | SwitchElse = Space >> key("else") >> plain_body; |
229 | 229 | ||
230 | SwitchBlock = *EmptyLine >> | 230 | SwitchBlock = *EmptyLine >> |
@@ -238,54 +238,56 @@ YueParser::YueParser() { | |||
238 | >> -Space >> Break >> SwitchBlock; | 238 | >> -Space >> Break >> SwitchBlock; |
239 | 239 | ||
240 | assignment = ExpList >> Assign; | 240 | assignment = ExpList >> Assign; |
241 | IfCond = disable_do_chain(disable_arg_table_block(assignment | Exp)); | 241 | IfCond = disable_do_chain_arg_table_block(assignment | Exp); |
242 | IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("elseif") >> IfCond >> plain_body_with("then"); | 242 | IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("elseif") >> IfCond >> plain_body_with("then"); |
243 | IfElse = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("else") >> plain_body; | 243 | IfElse = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("else") >> plain_body; |
244 | IfType = (expr("if") | expr("unless")) >> not_(AlphaNum); | 244 | IfType = (expr("if") | expr("unless")) >> not_(AlphaNum); |
245 | If = Space >> IfType >> IfCond >> plain_body_with("then") >> *IfElseIf >> -IfElse; | 245 | If = Space >> IfType >> IfCond >> plain_body_with("then") >> *IfElseIf >> -IfElse; |
246 | 246 | ||
247 | WhileType = (expr("while") | expr("until")) >> not_(AlphaNum); | 247 | WhileType = (expr("while") | expr("until")) >> not_(AlphaNum); |
248 | While = WhileType >> disable_do_chain(Exp) >> plain_body_with("do"); | 248 | While = WhileType >> disable_do_chain_arg_table_block(Exp) >> plain_body_with("do"); |
249 | Repeat = key("repeat") >> Body >> Break >> *EmptyLine >> CheckIndent >> Space >> key("until") >> Exp; | 249 | Repeat = key("repeat") >> Body >> Break >> *EmptyLine >> CheckIndent >> Space >> key("until") >> Exp; |
250 | 250 | ||
251 | for_step_value = sym(',') >> Exp; | 251 | for_step_value = sym(',') >> Exp; |
252 | for_args = Space >> Variable >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; | 252 | for_args = Space >> Variable >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; |
253 | 253 | ||
254 | For = key("for") >> disable_do_chain(for_args) >> plain_body_with("do"); | 254 | For = key("for") >> disable_do_chain_arg_table_block(for_args) >> plain_body_with("do"); |
255 | 255 | ||
256 | for_in = star_exp | ExpList; | 256 | for_in = star_exp | ExpList; |
257 | 257 | ||
258 | ForEach = key("for") >> AssignableNameList >> Space >> key("in") >> | 258 | ForEach = key("for") >> AssignableNameList >> Space >> key("in") >> |
259 | disable_do_chain(for_in) >> plain_body_with("do"); | 259 | disable_do_chain_arg_table_block(for_in) >> plain_body_with("do"); |
260 | 260 | ||
261 | Do = pl::user(Space >> key("do"), [](const item_t& item) { | 261 | Do = pl::user(Space >> key("do"), [](const item_t& item) { |
262 | State* st = reinterpret_cast<State*>(item.user_data); | 262 | State* st = reinterpret_cast<State*>(item.user_data); |
263 | return st->doStack.empty() || st->doStack.top(); | 263 | return st->noDoStack.empty() || !st->noDoStack.top(); |
264 | }) >> Body; | 264 | }) >> Body; |
265 | 265 | ||
266 | DisableDo = pl::user(true_(), [](const item_t& item) { | 266 | DisableDo = pl::user(true_(), [](const item_t& item) { |
267 | State* st = reinterpret_cast<State*>(item.user_data); | 267 | State* st = reinterpret_cast<State*>(item.user_data); |
268 | st->doStack.push(false); | 268 | st->noDoStack.push(true); |
269 | return true; | 269 | return true; |
270 | }); | 270 | }); |
271 | 271 | ||
272 | EnableDo = pl::user(true_(), [](const item_t& item) { | 272 | EnableDo = pl::user(true_(), [](const item_t& item) { |
273 | State* st = reinterpret_cast<State*>(item.user_data); | 273 | State* st = reinterpret_cast<State*>(item.user_data); |
274 | st->doStack.pop(); | 274 | st->noDoStack.pop(); |
275 | return true; | 275 | return true; |
276 | }); | 276 | }); |
277 | 277 | ||
278 | DisableDoChain = pl::user(true_(), [](const item_t& item) { | 278 | DisableDoChainArgTableBlock = pl::user(true_(), [](const item_t& item) { |
279 | State* st = reinterpret_cast<State*>(item.user_data); | 279 | State* st = reinterpret_cast<State*>(item.user_data); |
280 | st->doStack.push(false); | 280 | st->noDoStack.push(true); |
281 | st->chainBlockStack.push(false); | 281 | st->noChainBlockStack.push(true); |
282 | st->noTableBlockStack.push(true); | ||
282 | return true; | 283 | return true; |
283 | }); | 284 | }); |
284 | 285 | ||
285 | EnableDoChain = pl::user(true_(), [](const item_t& item) { | 286 | EnableDoChainArgTableBlock = pl::user(true_(), [](const item_t& item) { |
286 | State* st = reinterpret_cast<State*>(item.user_data); | 287 | State* st = reinterpret_cast<State*>(item.user_data); |
287 | st->doStack.pop(); | 288 | st->noDoStack.pop(); |
288 | st->chainBlockStack.pop(); | 289 | st->noChainBlockStack.pop(); |
290 | st->noTableBlockStack.pop(); | ||
289 | return true; | 291 | return true; |
290 | }); | 292 | }); |
291 | 293 | ||
@@ -370,20 +372,20 @@ YueParser::YueParser() { | |||
370 | 372 | ||
371 | DisableChain = pl::user(true_(), [](const item_t& item) { | 373 | DisableChain = pl::user(true_(), [](const item_t& item) { |
372 | State* st = reinterpret_cast<State*>(item.user_data); | 374 | State* st = reinterpret_cast<State*>(item.user_data); |
373 | st->chainBlockStack.push(false); | 375 | st->noChainBlockStack.push(true); |
374 | return true; | 376 | return true; |
375 | }); | 377 | }); |
376 | 378 | ||
377 | EnableChain = pl::user(true_(), [](const item_t& item) { | 379 | EnableChain = pl::user(true_(), [](const item_t& item) { |
378 | State* st = reinterpret_cast<State*>(item.user_data); | 380 | State* st = reinterpret_cast<State*>(item.user_data); |
379 | st->chainBlockStack.pop(); | 381 | st->noChainBlockStack.pop(); |
380 | return true; | 382 | return true; |
381 | }); | 383 | }); |
382 | 384 | ||
383 | chain_line = CheckIndent >> (chain_item | Space >> (chain_dot_chain | ColonChain)) >> -InvokeArgs; | 385 | chain_line = CheckIndent >> (chain_item | Space >> (chain_dot_chain | ColonChain)) >> -InvokeArgs; |
384 | chain_block = pl::user(true_(), [](const item_t& item) { | 386 | chain_block = pl::user(true_(), [](const item_t& item) { |
385 | State* st = reinterpret_cast<State*>(item.user_data); | 387 | State* st = reinterpret_cast<State*>(item.user_data); |
386 | return st->chainBlockStack.empty() || st->chainBlockStack.top(); | 388 | return st->noChainBlockStack.empty() || !st->noChainBlockStack.top(); |
387 | }) >> +SpaceBreak >> Advance >> ensure( | 389 | }) >> +SpaceBreak >> Advance >> ensure( |
388 | chain_line >> *(+SpaceBreak >> chain_line), PopIndent); | 390 | chain_line >> *(+SpaceBreak >> chain_line), PopIndent); |
389 | ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -(InvokeArgs | chain_block) >> -table_appending_op; | 391 | ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -(InvokeArgs | chain_block) >> -table_appending_op; |