diff options
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
-rw-r--r-- | src/yuescript/yue_parser.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index f383275..f72407d 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -853,13 +853,6 @@ YueParser::YueParser() { | |||
853 | ChainAssign = Seperator >> Exp >> +(space >> '=' >> space >> Exp >> space >> and_('=')) >> space >> Assign; | 853 | ChainAssign = Seperator >> Exp >> +(space >> '=' >> space >> Exp >> space >> and_('=')) >> space >> Assign; |
854 | 854 | ||
855 | StatementAppendix = (IfLine | WhileLine | CompInner) >> space; | 855 | StatementAppendix = (IfLine | WhileLine | CompInner) >> space; |
856 | StatementSep = and_( | ||
857 | *space_break >> check_indent_match >> space >> ( | ||
858 | set("($'\"") | | ||
859 | "[[" | | ||
860 | "[=" | ||
861 | ) | ||
862 | ); | ||
863 | Statement = | 856 | Statement = |
864 | Seperator >> | 857 | Seperator >> |
865 | -( | 858 | -( |
@@ -876,8 +869,9 @@ YueParser::YueParser() { | |||
876 | StatementAppendix >> empty_block_error | 869 | StatementAppendix >> empty_block_error |
877 | ) >> | 870 | ) >> |
878 | space >> | 871 | space >> |
879 | -StatementAppendix >> | 872 | -StatementAppendix; |
880 | -StatementSep; | 873 | |
874 | StatementSep = white >> (set("('\"") | "[[" | "[="); | ||
881 | 875 | ||
882 | Body = in_block | Statement; | 876 | Body = in_block | Statement; |
883 | 877 | ||
@@ -905,6 +899,32 @@ YueParser::YueParser() { | |||
905 | } | 899 | } |
906 | // clang-format on | 900 | // clang-format on |
907 | 901 | ||
902 | bool YueParser::startWith(std::string_view codes, rule& r) { | ||
903 | std::unique_ptr<input> converted; | ||
904 | if (codes.substr(0, 3) == "\xEF\xBB\xBF"sv) { | ||
905 | codes = codes.substr(3); | ||
906 | } | ||
907 | try { | ||
908 | if (!codes.empty()) { | ||
909 | converted = std::make_unique<input>(_converter.from_bytes(&codes.front(), &codes.back() + 1)); | ||
910 | } else { | ||
911 | converted = std::make_unique<input>(); | ||
912 | } | ||
913 | } catch (const std::range_error&) { | ||
914 | return false; | ||
915 | } | ||
916 | error_list errors; | ||
917 | try { | ||
918 | State state; | ||
919 | return ::yue::start_with(*converted, r, errors, &state); | ||
920 | } catch (const ParserError&) { | ||
921 | return false; | ||
922 | } catch (const std::logic_error&) { | ||
923 | return false; | ||
924 | } | ||
925 | return true; | ||
926 | } | ||
927 | |||
908 | ParseInfo YueParser::parse(std::string_view codes, rule& r) { | 928 | ParseInfo YueParser::parse(std::string_view codes, rule& r) { |
909 | ParseInfo res; | 929 | ParseInfo res; |
910 | if (codes.substr(0, 3) == "\xEF\xBB\xBF"sv) { | 930 | if (codes.substr(0, 3) == "\xEF\xBB\xBF"sv) { |