From 90e5ee7ee432f558b3c55d79fba1fcb2a8ce502f Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 10 Feb 2021 20:45:46 +0800 Subject: fix issue #38 with a better solution. --- spec/inputs/export.mp | 3 +++ spec/inputs/syntax.mp | 21 +++++++++++++++++++++ spec/inputs/with.mp | 5 +++++ src/MoonP/moon_compiler.cpp | 2 +- src/MoonP/moon_parser.cpp | 22 ++++++++++++++++++++-- src/MoonP/moon_parser.h | 5 +++++ 6 files changed, 55 insertions(+), 3 deletions(-) diff --git a/spec/inputs/export.mp b/spec/inputs/export.mp index 9a494d9..085510e 100644 --- a/spec/inputs/export.mp +++ b/spec/inputs/export.mp @@ -43,6 +43,9 @@ export Constant = switch value when "better" then 2 when "best" then 3 +export item = 123 + |> func + export x f if a then b diff --git a/spec/inputs/syntax.mp b/spec/inputs/syntax.mp index c8ad96d..f3a0a5c 100644 --- a/spec/inputs/syntax.mp +++ b/spec/inputs/syntax.mp @@ -123,6 +123,21 @@ argon\world().something() argon\somethin"200".world(1,2) +origin + .transform + .root + .gameObject + \Parents! + \Descendants! + \SelectEnable! + \SelectVisible! + \TagEqual "fx" + \Where (x) -> + if x\IsTargeted! + return false + x.name\EndsWith "(Clone)" + \Destroy! + x = -434 x = -hello world one two @@ -163,6 +178,9 @@ something\hello(what) a,b something\hello what something.hello\world a,b something.hello\world(1,2,3) a,b +something + .hello + \world(1,2,3) a,b x = 1232 @@ -295,6 +313,9 @@ a /= func "cool" x.then = "hello" x.while.true = "hello" +x + .while + .true = "hello" -- diff --git a/spec/inputs/with.mp b/spec/inputs/with.mp index 704c494..d88e109 100644 --- a/spec/inputs/with.mp +++ b/spec/inputs/with.mp @@ -111,6 +111,11 @@ do with hi return .a, .b +do + with tb + .x = item + .field + \func 123 do with dad diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 11d4ed8..2ed153e 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -53,7 +53,7 @@ inline std::string s(std::string_view sv) { return std::string(sv); } -const std::string_view version = "0.6.0"sv; +const std::string_view version = "0.6.1"sv; const std::string_view extension = "mp"sv; class MoonCompilerImpl { 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() { Return = key("return") >> -ExpListLow; - WithExp = ExpList >> -Assign; + WithExp = DisableChainBlock >> ensure(ExpList >> -Assign, PopChainBlock); With = key("with") >> -existential_op >> DisableDo >> ensure(WithExp, PopDo) >> -key("do") >> Body; SwitchCase = key("when") >> ExpList >> -key("then") >> Body; @@ -338,7 +338,25 @@ MoonParser::MoonParser() { exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> backcall_exp; Exp = Seperator >> backcall_exp >> *exp_op_value; - ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> -InvokeArgs; + DisableChainBlock = pl::user(true_(), [](const item_t& item) { + State* st = reinterpret_cast(item.user_data); + st->chainBlockStack.push(false); + return true; + }); + + PopChainBlock = pl::user(true_(), [](const item_t& item) { + State* st = reinterpret_cast(item.user_data); + st->chainBlockStack.pop(); + return true; + }); + + chain_line = CheckIndent >> (chain_item | Space >> (chain_dot_chain | ColonChain)) >> -InvokeArgs; + chain_block = pl::user(true_(), [](const item_t& item) { + State* st = reinterpret_cast(item.user_data); + return st->chainBlockStack.empty() || st->chainBlockStack.top(); + }) >> +SpaceBreak >> Advance >> ensure( + chain_line >> *(+SpaceBreak >> chain_line), PopIndent); + ChainValue = Seperator >> (Chain | Callable) >> -existential_op >> (chain_block | -InvokeArgs); simple_table = Seperator >> KeyValue >> *(sym(',') >> KeyValue); Value = SimpleValue | simple_table | ChainValue | String; diff --git a/src/MoonP/moon_parser.h b/src/MoonP/moon_parser.h index bee3c9c..66f2cd9 100644 --- a/src/MoonP/moon_parser.h +++ b/src/MoonP/moon_parser.h @@ -78,6 +78,7 @@ protected: std::string buffer; std::stack indents; std::stack doStack; + std::stack chainBlockStack; }; template @@ -155,6 +156,10 @@ private: rule ColonChain; rule chain_with_colon; rule ChainItem; + rule chain_line; + rule chain_block; + rule DisableChainBlock; + rule PopChainBlock; rule Index; rule invoke_chain; rule TableValue; -- cgit v1.2.3-55-g6feb