diff options
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index dffdbe1..f383275 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -317,7 +317,7 @@ YueParser::YueParser() { | |||
| 317 | with_exp = ExpList >> -(space >> Assign); | 317 | with_exp = ExpList >> -(space >> Assign); |
| 318 | 318 | ||
| 319 | With = key("with") >> -ExistentialOp >> space >> disable_do_chain_arg_table_block_rule(with_exp) >> space >> body_with("do"); | 319 | With = key("with") >> -ExistentialOp >> space >> disable_do_chain_arg_table_block_rule(with_exp) >> space >> body_with("do"); |
| 320 | SwitchCase = key("when") >> disable_chain_rule(disable_arg_table_block_rule(SwitchList)) >> space >> body_with("then"); | 320 | SwitchCase = key("when") >> (disable_chain_rule(disable_arg_table_block_rule(SwitchList)) | space >> In) >> space >> body_with("then"); |
| 321 | switch_else = key("else") >> space >> body; | 321 | switch_else = key("else") >> space >> body; |
| 322 | 322 | ||
| 323 | switch_block = | 323 | switch_block = |
| @@ -454,12 +454,19 @@ YueParser::YueParser() { | |||
| 454 | expo_value = exponential_operator >> *space_break >> space >> Value; | 454 | expo_value = exponential_operator >> *space_break >> space >> Value; |
| 455 | expo_exp = Value >> *(space >> expo_value); | 455 | expo_exp = Value >> *(space >> expo_value); |
| 456 | 456 | ||
| 457 | InRangeOpen = true_(); | ||
| 458 | InRangeClose = true_(); | ||
| 459 | NotIn = true_(); | ||
| 460 | InRange = ('(' >> InRangeOpen | '[' >> InRangeClose) >> space >> Exp >> space >> ',' >> space >> Exp >> space >> (')' >> InRangeOpen | ']' >> InRangeClose); | ||
| 461 | InDiscrete = '{' >> Seperator >> space >> Exp >> *(space >> ',' >> space >> Exp) >> space >> '}'; | ||
| 462 | In = -(key("not") >> NotIn >> space) >> key("in") >> space >> (InRange | InDiscrete); | ||
| 463 | |||
| 457 | UnaryOperator = | 464 | UnaryOperator = |
| 458 | '-' >> not_(set(">=") | space_one) | | 465 | '-' >> not_(set(">=") | space_one) | |
| 459 | '#' | | 466 | '#' | |
| 460 | '~' >> not_('=' | space_one) | | 467 | '~' >> not_('=' | space_one) | |
| 461 | key("not"); | 468 | key("not"); |
| 462 | UnaryExp = *(UnaryOperator >> space) >> expo_exp; | 469 | UnaryExp = *(UnaryOperator >> space) >> expo_exp >> -(space >> In); |
| 463 | 470 | ||
| 464 | pipe_operator = "|>"; | 471 | pipe_operator = "|>"; |
| 465 | pipe_value = pipe_operator >> *space_break >> space >> UnaryExp; | 472 | pipe_value = pipe_operator >> *space_break >> space >> UnaryExp; |
| @@ -916,7 +923,7 @@ ParseInfo YueParser::parse(std::string_view codes, rule& r) { | |||
| 916 | error_list errors; | 923 | error_list errors; |
| 917 | try { | 924 | try { |
| 918 | State state; | 925 | State state; |
| 919 | res.node.set(pl::parse(*(res.codes), r, errors, &state)); | 926 | res.node.set(::yue::parse(*(res.codes), r, errors, &state)); |
| 920 | if (state.exportCount > 0) { | 927 | if (state.exportCount > 0) { |
| 921 | res.moduleName = std::move(state.moduleName); | 928 | res.moduleName = std::move(state.moduleName); |
| 922 | res.exportDefault = state.exportDefault; | 929 | res.exportDefault = state.exportDefault; |
| @@ -952,14 +959,6 @@ std::string YueParser::toString(input::iterator begin, input::iterator end) { | |||
| 952 | return _converter.to_bytes(std::wstring(begin, end)); | 959 | return _converter.to_bytes(std::wstring(begin, end)); |
| 953 | } | 960 | } |
| 954 | 961 | ||
| 955 | input YueParser::encode(std::string_view codes) { | ||
| 956 | return _converter.from_bytes(&codes.front(), &codes.back() + 1); | ||
| 957 | } | ||
| 958 | |||
| 959 | std::string YueParser::decode(const input& codes) { | ||
| 960 | return _converter.to_bytes(codes); | ||
| 961 | } | ||
| 962 | |||
| 963 | namespace Utils { | 962 | namespace Utils { |
| 964 | void replace(std::string& str, std::string_view from, std::string_view to) { | 963 | void replace(std::string& str, std::string_view from, std::string_view to) { |
| 965 | size_t start_pos = 0; | 964 | size_t start_pos = 0; |
