diff options
| -rw-r--r-- | spec/inputs/string.yue | 1 | ||||
| -rw-r--r-- | spec/outputs/string.lua | 1 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 5 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 11 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.h | 1 |
5 files changed, 14 insertions, 5 deletions
diff --git a/spec/inputs/string.yue b/spec/inputs/string.yue index 201e60d..f91383e 100644 --- a/spec/inputs/string.yue +++ b/spec/inputs/string.yue | |||
| @@ -51,6 +51,7 @@ d = "#{hello world}" | |||
| 51 | e = "#{1} #{2} #{3}" | 51 | e = "#{1} #{2} #{3}" |
| 52 | 52 | ||
| 53 | f = [[hello #{world} world]] | 53 | f = [[hello #{world} world]] |
| 54 | g = "\#{hello world}" | ||
| 54 | 55 | ||
| 55 | -- | 56 | -- |
| 56 | 57 | ||
diff --git a/spec/outputs/string.lua b/spec/outputs/string.lua index 87ecf2c..febea62 100644 --- a/spec/outputs/string.lua +++ b/spec/outputs/string.lua | |||
| @@ -29,6 +29,7 @@ local c = "hello " .. tostring(5 + 1) | |||
| 29 | local d = tostring(hello(world)) | 29 | local d = tostring(hello(world)) |
| 30 | local e = tostring(1) .. " " .. tostring(2) .. " " .. tostring(3) | 30 | local e = tostring(1) .. " " .. tostring(2) .. " " .. tostring(3) |
| 31 | local f = [[hello #{world} world]] | 31 | local f = [[hello #{world} world]] |
| 32 | local g = "#{hello world}" | ||
| 32 | a = 'hello #{hello} hello' | 33 | a = 'hello #{hello} hello' |
| 33 | b = '#{hello} hello' | 34 | b = '#{hello} hello' |
| 34 | c = 'hello #{hello}' | 35 | c = 'hello #{hello}' |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 3dc8e19..3353a2a 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -72,7 +72,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
| 72 | "close"s // Lua 5.4 | 72 | "close"s // Lua 5.4 |
| 73 | }; | 73 | }; |
| 74 | 74 | ||
| 75 | const std::string_view version = "0.17.4"sv; | 75 | const std::string_view version = "0.17.5"sv; |
| 76 | const std::string_view extension = "yue"sv; | 76 | const std::string_view extension = "yue"sv; |
| 77 | 77 | ||
| 78 | class CompileError : public std::logic_error { | 78 | class CompileError : public std::logic_error { |
| @@ -6926,8 +6926,9 @@ private: | |||
| 6926 | switch (content->get_id()) { | 6926 | switch (content->get_id()) { |
| 6927 | case id<DoubleStringInner_t>(): { | 6927 | case id<DoubleStringInner_t>(): { |
| 6928 | auto str = _parser.toString(content); | 6928 | auto str = _parser.toString(content); |
| 6929 | Utils::replace(str, "\r\n"sv, "\n"); | 6929 | Utils::replace(str, "\r\n"sv, "\n"sv); |
| 6930 | Utils::replace(str, "\n"sv, "\\n"sv); | 6930 | Utils::replace(str, "\n"sv, "\\n"sv); |
| 6931 | Utils::replace(str, "\\#"sv, "#"sv); | ||
| 6931 | temp.push_back('\"' + str + '\"'); | 6932 | temp.push_back('\"' + str + '\"'); |
| 6932 | break; | 6933 | break; |
| 6933 | } | 6934 | } |
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 294f1e5..66ef373 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -98,6 +98,11 @@ YueParser::YueParser() { | |||
| 98 | return false; | 98 | return false; |
| 99 | }); | 99 | }); |
| 100 | 100 | ||
| 101 | invalid_interpolation_error = pl::user(true_(), [](const item_t& item) { | ||
| 102 | throw ParserError("invalid string interpolation"sv, item.begin); | ||
| 103 | return false; | ||
| 104 | }); | ||
| 105 | |||
| 101 | #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut) | 106 | #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut) |
| 102 | 107 | ||
| 103 | #define key(str) (expr(str) >> not_alpha_num) | 108 | #define key(str) (expr(str) >> not_alpha_num) |
| @@ -529,9 +534,9 @@ YueParser::YueParser() { | |||
| 529 | single_string_inner = '\\' >> set("'\\") | not_('\'') >> any_char; | 534 | single_string_inner = '\\' >> set("'\\") | not_('\'') >> any_char; |
| 530 | SingleString = '\'' >> *single_string_inner >> '\''; | 535 | SingleString = '\'' >> *single_string_inner >> '\''; |
| 531 | 536 | ||
| 532 | interp = "#{" >> space >> Exp >> space >> '}'; | 537 | interp = "#{" >> space >> (Exp >> space >> '}' | invalid_interpolation_error); |
| 533 | double_string_plain = '\\' >> set("\"\\") | not_('"') >> any_char; | 538 | double_string_plain = '\\' >> set("\"\\#") | not_('"') >> any_char; |
| 534 | DoubleStringInner = +(not_(interp) >> double_string_plain); | 539 | DoubleStringInner = +(not_("#{") >> double_string_plain); |
| 535 | DoubleStringContent = DoubleStringInner | interp; | 540 | DoubleStringContent = DoubleStringInner | interp; |
| 536 | DoubleString = '"' >> Seperator >> *DoubleStringContent >> '"'; | 541 | DoubleString = '"' >> Seperator >> *DoubleStringContent >> '"'; |
| 537 | String = DoubleString | SingleString | LuaString; | 542 | String = DoubleString | SingleString | LuaString; |
diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index 9b4adae..ac6524d 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h | |||
| @@ -137,6 +137,7 @@ private: | |||
| 137 | NONE_AST_RULE(braces_expression_error); | 137 | NONE_AST_RULE(braces_expression_error); |
| 138 | NONE_AST_RULE(brackets_expression_error); | 138 | NONE_AST_RULE(brackets_expression_error); |
| 139 | NONE_AST_RULE(export_expression_error); | 139 | NONE_AST_RULE(export_expression_error); |
| 140 | NONE_AST_RULE(invalid_interpolation_error); | ||
| 140 | 141 | ||
| 141 | NONE_AST_RULE(inc_exp_level); | 142 | NONE_AST_RULE(inc_exp_level); |
| 142 | NONE_AST_RULE(dec_exp_level); | 143 | NONE_AST_RULE(dec_exp_level); |
