aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-07-02 16:47:12 +0800
committerLi Jin <dragon-fly@qq.com>2023-07-02 16:47:12 +0800
commit7775f4c5b97dcc0d7e71a2cd8fb132f2b5bc1bd6 (patch)
treeb980a68dfed0139d3e61b1477f52da783c6f610b
parent85a2da5cbbbbfb27f3b65ac67d083dd2443d223d (diff)
downloadyuescript-0.17.5.tar.gz
yuescript-0.17.5.tar.bz2
yuescript-0.17.5.zip
fix issue https://github.com/leafo/moonscript/issues/448v0.17.5
-rw-r--r--spec/inputs/string.yue1
-rw-r--r--spec/outputs/string.lua1
-rw-r--r--src/yuescript/yue_compiler.cpp5
-rw-r--r--src/yuescript/yue_parser.cpp11
-rw-r--r--src/yuescript/yue_parser.h1
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}"
51e = "#{1} #{2} #{3}" 51e = "#{1} #{2} #{3}"
52 52
53f = [[hello #{world} world]] 53f = [[hello #{world} world]]
54g = "\#{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)
29local d = tostring(hello(world)) 29local d = tostring(hello(world))
30local e = tostring(1) .. " " .. tostring(2) .. " " .. tostring(3) 30local e = tostring(1) .. " " .. tostring(2) .. " " .. tostring(3)
31local f = [[hello #{world} world]] 31local f = [[hello #{world} world]]
32local g = "#{hello world}"
32a = 'hello #{hello} hello' 33a = 'hello #{hello} hello'
33b = '#{hello} hello' 34b = '#{hello} hello'
34c = 'hello #{hello}' 35c = '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
75const std::string_view version = "0.17.4"sv; 75const std::string_view version = "0.17.5"sv;
76const std::string_view extension = "yue"sv; 76const std::string_view extension = "yue"sv;
77 77
78class CompileError : public std::logic_error { 78class 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);