diff options
| author | Li Jin <dragon-fly@qq.com> | 2019-09-15 11:03:09 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2019-09-15 11:03:09 +0800 |
| commit | b65798d7960d797f2b7074c4cc47b8c70a9f5270 (patch) | |
| tree | def8a2b75aeaaf1ce488e5cb94b8cf55df1a4910 /MoonParser/moon_parser.cpp | |
| parent | 181c6e40ff8c7579d8c7fdf6c72db13ffc951c81 (diff) | |
| download | yuescript-b65798d7960d797f2b7074c4cc47b8c70a9f5270.tar.gz yuescript-b65798d7960d797f2b7074c4cc47b8c70a9f5270.tar.bz2 yuescript-b65798d7960d797f2b7074c4cc47b8c70a9f5270.zip | |
fixing issues.
Diffstat (limited to 'MoonParser/moon_parser.cpp')
| -rw-r--r-- | MoonParser/moon_parser.cpp | 96 |
1 files changed, 46 insertions, 50 deletions
diff --git a/MoonParser/moon_parser.cpp b/MoonParser/moon_parser.cpp index ae8c53d..3009ee5 100644 --- a/MoonParser/moon_parser.cpp +++ b/MoonParser/moon_parser.cpp | |||
| @@ -43,10 +43,8 @@ rule Seperator = true_(); | |||
| 43 | #define symx(str) expr(str) | 43 | #define symx(str) expr(str) |
| 44 | #define ensure(patt, finally) (((patt) >> (finally)) | ((finally) >> (Cut))) | 44 | #define ensure(patt, finally) (((patt) >> (finally)) | ((finally) >> (Cut))) |
| 45 | #define key(str) (Space >> str >> not_(AlphaNum)) | 45 | #define key(str) (Space >> str >> not_(AlphaNum)) |
| 46 | #define opWord(str) (Space >> str >> not_(AlphaNum)) | ||
| 47 | #define op(str) (Space >> str) | ||
| 48 | 46 | ||
| 49 | rule Name = user(SpaceName, [](const item_t& item) | 47 | rule Name = user(_Name, [](const item_t& item) |
| 50 | { | 48 | { |
| 51 | State* st = reinterpret_cast<State*>(item.user_data); | 49 | State* st = reinterpret_cast<State*>(item.user_data); |
| 52 | for (auto it = item.begin; it != item.end; ++it) st->buffer << static_cast<char>(*it); | 50 | for (auto it = item.begin; it != item.end; ++it) st->buffer << static_cast<char>(*it); |
| @@ -142,11 +140,11 @@ rule InBlock = Advance >> Block >> PopIndent; | |||
| 142 | 140 | ||
| 143 | extern rule NameList; | 141 | extern rule NameList; |
| 144 | 142 | ||
| 145 | rule local_flag = op('*') | op('^'); | 143 | rule local_flag = expr('*') | expr('^'); |
| 146 | rule Local = key("local") >> (local_flag | NameList); | 144 | rule Local = key("local") >> ((Space >> local_flag) | NameList); |
| 147 | 145 | ||
| 148 | rule colon_import_name = sym('\\') >> Name; | 146 | rule colon_import_name = sym('\\') >> Space >> Name; |
| 149 | rule ImportName = colon_import_name | Name; | 147 | rule ImportName = colon_import_name | Space >> Name; |
| 150 | rule ImportNameList = Seperator >> *SpaceBreak >> ImportName >> *((+SpaceBreak | sym(',') >> *SpaceBreak) >> ImportName); | 148 | rule ImportNameList = Seperator >> *SpaceBreak >> ImportName >> *((+SpaceBreak | sym(',') >> *SpaceBreak) >> ImportName); |
| 151 | 149 | ||
| 152 | extern rule Exp; | 150 | extern rule Exp; |
| @@ -185,7 +183,7 @@ rule Unless = key("unless") >> IfCond >> -key("then") >> Body >> Seperator >> *I | |||
| 185 | rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; | 183 | rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; |
| 186 | 184 | ||
| 187 | rule for_step_value = sym(',') >> Exp; | 185 | rule for_step_value = sym(',') >> Exp; |
| 188 | rule for_args = Name >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; | 186 | rule for_args = Space >> Name >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; |
| 189 | 187 | ||
| 190 | rule For = key("for") >> DisableDo >> | 188 | rule For = key("for") >> DisableDo >> |
| 191 | ensure(for_args, PopDo) >> | 189 | ensure(for_args, PopDo) >> |
| @@ -232,7 +230,7 @@ extern rule CompForEach, CompFor, CompClause; | |||
| 232 | rule CompInner = (CompForEach | CompFor) >> Seperator >> *CompClause; | 230 | rule CompInner = (CompForEach | CompFor) >> Seperator >> *CompClause; |
| 233 | rule star_exp = sym('*') >> Exp; | 231 | rule star_exp = sym('*') >> Exp; |
| 234 | rule CompForEach = key("for") >> AssignableNameList >> key("in") >> (star_exp | Exp); | 232 | rule CompForEach = key("for") >> AssignableNameList >> key("in") >> (star_exp | Exp); |
| 235 | rule CompFor = key("for") >> Name >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; | 233 | rule CompFor = key("for") >> Space >> Name >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; |
| 236 | rule CompClause = CompFor | CompForEach | key("when") >> Exp; | 234 | rule CompClause = CompFor | CompForEach | key("when") >> Exp; |
| 237 | 235 | ||
| 238 | extern rule TableBlock; | 236 | extern rule TableBlock; |
| @@ -240,44 +238,42 @@ extern rule TableBlock; | |||
| 240 | rule Assign = sym('=') >> (With | If | Switch | TableBlock | ExpListLow); | 238 | rule Assign = sym('=') >> (With | If | Switch | TableBlock | ExpListLow); |
| 241 | 239 | ||
| 242 | rule update_op = | 240 | rule update_op = |
| 243 | sym("..=") | | 241 | expr("..=") | |
| 244 | sym("+=") | | 242 | expr("+=") | |
| 245 | sym("-=") | | 243 | expr("-=") | |
| 246 | sym("*=") | | 244 | expr("*=") | |
| 247 | sym("/=") | | 245 | expr("/=") | |
| 248 | sym("%=") | | 246 | expr("%=") | |
| 249 | sym("or=") | | 247 | expr("or=") | |
| 250 | sym("and=") | | 248 | expr("and=") | |
| 251 | sym("&=") | | 249 | expr("&=") | |
| 252 | sym("|=") | | 250 | expr("|=") | |
| 253 | sym(">>=") | | 251 | expr(">>=") | |
| 254 | sym("<<="); | 252 | expr("<<="); |
| 255 | 253 | ||
| 256 | rule Update = update_op >> Exp; | 254 | rule Update = Space >> update_op >> Exp; |
| 257 | 255 | ||
| 258 | rule CharOperators = Space >> set("+-*/%^><|&"); | 256 | rule BinaryOperator = |
| 259 | rule WordOperators = | 257 | (expr("or") >> not_(AlphaNum)) | |
| 260 | opWord("or") | | 258 | (expr("and") >> not_(AlphaNum)) | |
| 261 | opWord("and") | | 259 | expr("<=") | |
| 262 | op("<=") | | 260 | expr(">=") | |
| 263 | op(">=") | | 261 | expr("~=") | |
| 264 | op("~=") | | 262 | expr("!=") | |
| 265 | op("!=") | | 263 | expr("==") | |
| 266 | op("==") | | 264 | expr("..") | |
| 267 | op("..") | | 265 | expr("<<") | |
| 268 | op("<<") | | 266 | expr(">>") | |
| 269 | op(">>") | | 267 | expr("//") | |
| 270 | op("//"); | 268 | set("+-*/%^><|&"); |
| 271 | |||
| 272 | rule BinaryOperator = (WordOperators | CharOperators) >> *SpaceBreak; | ||
| 273 | 269 | ||
| 274 | extern rule Chain; | 270 | extern rule Chain; |
| 275 | 271 | ||
| 276 | rule Assignable = Chain | Name | SelfName; | 272 | rule Assignable = Chain | Space >> Name | SelfName; |
| 277 | 273 | ||
| 278 | extern rule Value; | 274 | extern rule Value; |
| 279 | 275 | ||
| 280 | rule exp_op_value = BinaryOperator >> Value; | 276 | rule exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> Value; |
| 281 | rule Exp = Value >> *exp_op_value; | 277 | rule Exp = Value >> *exp_op_value; |
| 282 | 278 | ||
| 283 | extern rule Callable, InvokeArgs; | 279 | extern rule Callable, InvokeArgs; |
| @@ -328,7 +324,7 @@ rule LuaString = user(LuaStringOpen >> -Break >> LuaStringContent >> LuaStringCl | |||
| 328 | }); | 324 | }); |
| 329 | 325 | ||
| 330 | rule Parens = sym('(') >> *SpaceBreak >> Exp >> *SpaceBreak >> sym(')'); | 326 | rule Parens = sym('(') >> *SpaceBreak >> Exp >> *SpaceBreak >> sym(')'); |
| 331 | rule Callable = Name | SelfName | VarArg | Parens; | 327 | rule Callable = Space >> Name | SelfName | VarArg | Parens; |
| 332 | rule FnArgsExpList = Exp >> *((Break | sym(',')) >> White >> Exp); | 328 | rule FnArgsExpList = Exp >> *((Break | sym(',')) >> White >> Exp); |
| 333 | 329 | ||
| 334 | rule FnArgs = Seperator >> | 330 | rule FnArgs = Seperator >> |
| @@ -420,10 +416,10 @@ rule ClassDecl = | |||
| 420 | -ClassBlock; | 416 | -ClassBlock; |
| 421 | 417 | ||
| 422 | rule export_values = NameList >> -(sym('=') >> ExpListLow); | 418 | rule export_values = NameList >> -(sym('=') >> ExpListLow); |
| 423 | rule export_op = op('*') | op('^'); | 419 | rule export_op = expr('*') | expr('^'); |
| 424 | rule Export = key("export") >> (ClassDecl | export_op | export_values); | 420 | rule Export = key("export") >> (ClassDecl | (Space >> export_op) | export_values); |
| 425 | 421 | ||
| 426 | rule variable_pair = sym(':') >> not_(SomeSpace) >> Name; | 422 | rule variable_pair = sym(':') >> not_(SomeSpace) >> Space >> Name; |
| 427 | 423 | ||
| 428 | rule normal_pair = | 424 | rule normal_pair = |
| 429 | ( | 425 | ( |
| @@ -440,7 +436,7 @@ rule KeyValue = variable_pair | normal_pair; | |||
| 440 | rule KeyValueList = KeyValue >> *(sym(',') >> KeyValue); | 436 | rule KeyValueList = KeyValue >> *(sym(',') >> KeyValue); |
| 441 | rule KeyValueLine = CheckIndent >> KeyValueList >> -sym(','); | 437 | rule KeyValueLine = CheckIndent >> KeyValueList >> -sym(','); |
| 442 | 438 | ||
| 443 | rule FnArgDef = (Name | SelfName) >> -(sym('=') >> Exp); | 439 | rule FnArgDef = (Space >> Name | SelfName) >> -(sym('=') >> Exp); |
| 444 | 440 | ||
| 445 | rule FnArgDefList = Seperator >> | 441 | rule FnArgDefList = Seperator >> |
| 446 | ( | 442 | ( |
| @@ -456,11 +452,11 @@ rule FnArgDefList = Seperator >> | |||
| 456 | rule outer_var_shadow = key("using") >> (NameList | Space >> expr("nil")); | 452 | rule outer_var_shadow = key("using") >> (NameList | Space >> expr("nil")); |
| 457 | 453 | ||
| 458 | rule FnArgsDef = sym('(') >> White >> -FnArgDefList >> -outer_var_shadow >> White >> sym(')'); | 454 | rule FnArgsDef = sym('(') >> White >> -FnArgDefList >> -outer_var_shadow >> White >> sym(')'); |
| 459 | rule fn_arrow = sym("->") | sym("=>"); | 455 | rule fn_arrow = expr("->") | expr("=>"); |
| 460 | rule FunLit = -FnArgsDef >> fn_arrow >> -Body; | 456 | rule FunLit = -FnArgsDef >> Space >> fn_arrow >> -Body; |
| 461 | 457 | ||
| 462 | rule NameList = Seperator >> Name >> *(sym(',') >> Name); | 458 | rule NameList = Seperator >> Space >> Name >> *(sym(',') >> Space >> Name); |
| 463 | rule NameOrDestructure = Name | TableLit; | 459 | rule NameOrDestructure = Space >> Name | TableLit; |
| 464 | rule AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> NameOrDestructure); | 460 | rule AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> NameOrDestructure); |
| 465 | 461 | ||
| 466 | rule ExpList = Seperator >> Exp >> *(sym(',') >> Exp); | 462 | rule ExpList = Seperator >> Exp >> *(sym(',') >> Exp); |
