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 | |
parent | c68e11bc6d7631185749aaf0c8d89147b3ac9cc9 (diff) | |
download | yuescript-90e5ee7ee432f558b3c55d79fba1fcb2a8ce502f.tar.gz yuescript-90e5ee7ee432f558b3c55d79fba1fcb2a8ce502f.tar.bz2 yuescript-90e5ee7ee432f558b3c55d79fba1fcb2a8ce502f.zip |
fix issue #38 with a better solution.
-rw-r--r-- | spec/inputs/export.mp | 3 | ||||
-rw-r--r-- | spec/inputs/syntax.mp | 21 | ||||
-rw-r--r-- | spec/inputs/with.mp | 5 | ||||
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 2 | ||||
-rw-r--r-- | src/MoonP/moon_parser.cpp | 22 | ||||
-rw-r--r-- | 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 | |||
43 | when "better" then 2 | 43 | when "better" then 2 |
44 | when "best" then 3 | 44 | when "best" then 3 |
45 | 45 | ||
46 | export item = 123 | ||
47 | |> func | ||
48 | |||
46 | export x | 49 | export x |
47 | 50 | ||
48 | f if a then b | 51 | 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() | |||
123 | 123 | ||
124 | argon\somethin"200".world(1,2) | 124 | argon\somethin"200".world(1,2) |
125 | 125 | ||
126 | origin | ||
127 | .transform | ||
128 | .root | ||
129 | .gameObject | ||
130 | \Parents! | ||
131 | \Descendants! | ||
132 | \SelectEnable! | ||
133 | \SelectVisible! | ||
134 | \TagEqual "fx" | ||
135 | \Where (x) -> | ||
136 | if x\IsTargeted! | ||
137 | return false | ||
138 | x.name\EndsWith "(Clone)" | ||
139 | \Destroy! | ||
140 | |||
126 | x = -434 | 141 | x = -434 |
127 | 142 | ||
128 | x = -hello world one two | 143 | x = -hello world one two |
@@ -163,6 +178,9 @@ something\hello(what) a,b | |||
163 | something\hello what | 178 | something\hello what |
164 | something.hello\world a,b | 179 | something.hello\world a,b |
165 | something.hello\world(1,2,3) a,b | 180 | something.hello\world(1,2,3) a,b |
181 | something | ||
182 | .hello | ||
183 | \world(1,2,3) a,b | ||
166 | 184 | ||
167 | 185 | ||
168 | x = 1232 | 186 | x = 1232 |
@@ -295,6 +313,9 @@ a /= func "cool" | |||
295 | 313 | ||
296 | x.then = "hello" | 314 | x.then = "hello" |
297 | x.while.true = "hello" | 315 | x.while.true = "hello" |
316 | x | ||
317 | .while | ||
318 | .true = "hello" | ||
298 | 319 | ||
299 | -- | 320 | -- |
300 | 321 | ||
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 | |||
111 | with hi | 111 | with hi |
112 | return .a, .b | 112 | return .a, .b |
113 | 113 | ||
114 | do | ||
115 | with tb | ||
116 | .x = item | ||
117 | .field | ||
118 | \func 123 | ||
114 | 119 | ||
115 | do | 120 | do |
116 | with dad | 121 | 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) { | |||
53 | return std::string(sv); | 53 | return std::string(sv); |
54 | } | 54 | } |
55 | 55 | ||
56 | const std::string_view version = "0.6.0"sv; | 56 | const std::string_view version = "0.6.1"sv; |
57 | const std::string_view extension = "mp"sv; | 57 | const std::string_view extension = "mp"sv; |
58 | 58 | ||
59 | class MoonCompilerImpl { | 59 | 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() { | |||
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; |
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: | |||
78 | std::string buffer; | 78 | std::string buffer; |
79 | std::stack<int> indents; | 79 | std::stack<int> indents; |
80 | std::stack<bool> doStack; | 80 | std::stack<bool> doStack; |
81 | std::stack<bool> chainBlockStack; | ||
81 | }; | 82 | }; |
82 | 83 | ||
83 | template <class T> | 84 | template <class T> |
@@ -155,6 +156,10 @@ private: | |||
155 | rule ColonChain; | 156 | rule ColonChain; |
156 | rule chain_with_colon; | 157 | rule chain_with_colon; |
157 | rule ChainItem; | 158 | rule ChainItem; |
159 | rule chain_line; | ||
160 | rule chain_block; | ||
161 | rule DisableChainBlock; | ||
162 | rule PopChainBlock; | ||
158 | rule Index; | 163 | rule Index; |
159 | rule invoke_chain; | 164 | rule invoke_chain; |
160 | rule TableValue; | 165 | rule TableValue; |