diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-02-10 20:45:46 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-02-10 20:50:54 +0800 |
| commit | 90e5ee7ee432f558b3c55d79fba1fcb2a8ce502f (patch) | |
| tree | 3b3dd29a627dc16448d6fa628559f65bcd405dac /src/MoonP/moon_parser.cpp | |
| parent | c68e11bc6d7631185749aaf0c8d89147b3ac9cc9 (diff) | |
| download | yuescript-90e5ee7ee432f558b3c55d79fba1fcb2a8ce502f.tar.gz yuescript-90e5ee7ee432f558b3c55d79fba1fcb2a8ce502f.tar.bz2 yuescript-90e5ee7ee432f558b3c55d79fba1fcb2a8ce502f.zip | |
fix issue #38 with a better solution.
Diffstat (limited to 'src/MoonP/moon_parser.cpp')
| -rw-r--r-- | src/MoonP/moon_parser.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index f15492f..aafe730 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp | |||
| @@ -219,7 +219,7 @@ MoonParser::MoonParser() { | |||
| 219 | 219 | ||
| 220 | Return = key("return") >> -ExpListLow; | 220 | Return = key("return") >> -ExpListLow; |
| 221 | 221 | ||
| 222 | WithExp = ExpList >> -Assign; | 222 | WithExp = DisableChainBlock >> ensure(ExpList >> -Assign, PopChainBlock); |
| 223 | 223 | ||
| 224 | With = key("with") >> -existential_op >> DisableDo >> ensure(WithExp, PopDo) >> -key("do") >> Body; | 224 | With = key("with") >> -existential_op >> DisableDo >> ensure(WithExp, PopDo) >> -key("do") >> Body; |
| 225 | SwitchCase = key("when") >> ExpList >> -key("then") >> Body; | 225 | SwitchCase = key("when") >> ExpList >> -key("then") >> Body; |
| @@ -338,7 +338,25 @@ MoonParser::MoonParser() { | |||
| 338 | exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> backcall_exp; | 338 | exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> backcall_exp; |
| 339 | Exp = Seperator >> backcall_exp >> *exp_op_value; | 339 | Exp = Seperator >> backcall_exp >> *exp_op_value; |
| 340 | 340 | ||
| 341 | ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs; | 341 | DisableChainBlock = pl::user(true_(), [](const item_t& item) { |
| 342 | State* st = reinterpret_cast<State*>(item.user_data); | ||
| 343 | st->chainBlockStack.push(false); | ||
| 344 | return true; | ||
| 345 | }); | ||
| 346 | |||
| 347 | PopChainBlock = pl::user(true_(), [](const item_t& item) { | ||
| 348 | State* st = reinterpret_cast<State*>(item.user_data); | ||
| 349 | st->chainBlockStack.pop(); | ||
| 350 | return true; | ||
| 351 | }); | ||
| 352 | |||
| 353 | chain_line = CheckIndent >> (chain_item | Space >> (chain_dot_chain | ColonChain)) >> -InvokeArgs; | ||
| 354 | chain_block = pl::user(true_(), [](const item_t& item) { | ||
| 355 | State* st = reinterpret_cast<State*>(item.user_data); | ||
| 356 | return st->chainBlockStack.empty() || st->chainBlockStack.top(); | ||
| 357 | }) >> +SpaceBreak >> Advance >> ensure( | ||
| 358 | chain_line >> *(+SpaceBreak >> chain_line), PopIndent); | ||
| 359 | ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> (chain_block | -InvokeArgs); | ||
| 342 | 360 | ||
| 343 | simple_table = Seperator >> KeyValue >> *(sym(',') >> KeyValue); | 361 | simple_table = Seperator >> KeyValue >> *(sym(',') >> KeyValue); |
| 344 | Value = SimpleValue | simple_table | ChainValue | String; | 362 | Value = SimpleValue | simple_table | ChainValue | String; |
