diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index 89fafdf28d..d73e6c6ff2 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -152,6 +152,13 @@ module YARP ] end + def test_incomplete_instance_var_string + assert_errors expression('%@#@@#'), '%@#@@#', [ + ["Incomplete instance variable", 4..5], + ["Expected a newline or semicolon after the statement", 4..4] + ] + end + def test_unterminated_s_symbol assert_errors expression("%s[abc"), "%s[abc", [ ["Expected a closing delimiter for the dynamic symbol", 3..3] diff --git a/test/yarp/fixtures/strings.txt b/test/yarp/fixtures/strings.txt index b0df61b938..2ce8b738a3 100644 --- a/test/yarp/fixtures/strings.txt +++ b/test/yarp/fixtures/strings.txt @@ -99,3 +99,7 @@ ?a "a" %Q{abc} + +%^#$^# + +%@#@# diff --git a/test/yarp/snapshots/strings.txt b/test/yarp/snapshots/strings.txt index 747d629930..ef08cb6994 100644 --- a/test/yarp/snapshots/strings.txt +++ b/test/yarp/snapshots/strings.txt @@ -1,8 +1,8 @@ -@ ProgramNode (location: (0...506)) +@ ProgramNode (location: (0...520)) ├── locals: [] └── statements: - @ StatementsNode (location: (0...506)) - └── body: (length: 48) + @ StatementsNode (location: (0...520)) + └── body: (length: 50) ├── @ StringNode (location: (0...6)) │ ├── flags: ∅ │ ├── opening_loc: (0...2) = "%%" @@ -496,9 +496,21 @@ │ ├── content_loc: (495...496) = "a" │ ├── closing_loc: (496...497) = "\"" │ └── unescaped: "a" - └── @ StringNode (location: (499...506)) + ├── @ StringNode (location: (499...506)) + │ ├── flags: ∅ + │ ├── opening_loc: (499...502) = "%Q{" + │ ├── content_loc: (502...505) = "abc" + │ ├── closing_loc: (505...506) = "}" + │ └── unescaped: "abc" + ├── @ StringNode (location: (508...513)) + │ ├── flags: ∅ + │ ├── opening_loc: (508...510) = "%^" + │ ├── content_loc: (510...512) = "\#$" + │ ├── closing_loc: (512...513) = "^" + │ └── unescaped: "\#$" + └── @ StringNode (location: (516...520)) ├── flags: ∅ - ├── opening_loc: (499...502) = "%Q{" - ├── content_loc: (502...505) = "abc" - ├── closing_loc: (505...506) = "}" - └── unescaped: "abc" + ├── opening_loc: (516...518) = "%@" + ├── content_loc: (518...519) = "#" + ├── closing_loc: (519...520) = "@" + └── unescaped: "#" diff --git a/yarp/yarp.c b/yarp/yarp.c index 3eabc55600..cc4d8c52e8 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -5801,7 +5801,7 @@ lex_interpolation(yp_parser_t *parser, const uint8_t *pound) { // If we didn't get an valid interpolation, then this is just regular // string content. This is like if we get "#@-". In this case the caller // should keep lexing. - parser->current.end = variable; + parser->current.end = pound + 1; return YP_TOKEN_NOT_PROVIDED; } case '$':