diff --git a/prism/config.yml b/prism/config.yml index 3b402b617b..ad6ec1b707 100644 --- a/prism/config.yml +++ b/prism/config.yml @@ -1772,7 +1772,6 @@ nodes: type: location - name: content_loc type: location - semantic_field: true # https://github.com/ruby/prism/issues/1452 - name: closing_loc type: location - name: unescaped @@ -2093,7 +2092,6 @@ nodes: type: location - name: content_loc type: location - semantic_field: true # https://github.com/ruby/prism/issues/1452 - name: closing_loc type: location - name: unescaped @@ -2287,10 +2285,8 @@ nodes: kind: StringFlags - name: opening_loc type: location? - semantic_field: true # https://github.com/ruby/prism/issues/1452 - name: content_loc type: location - semantic_field: true # https://github.com/ruby/prism/issues/1452 - name: closing_loc type: location? - name: unescaped diff --git a/prism/prism.c b/prism/prism.c index f3b9404358..ef1fff147a 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -6370,16 +6370,8 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, uint8_t flags) { extra_codepoints_start = unicode_start; } - uint32_t value = escape_unicode(unicode_start, hexadecimal_length); - - if (flags & PM_ESCAPE_FLAG_REGEXP) { - if (codepoints_count == 1) { - pm_buffer_append_bytes(buffer, (const uint8_t *) "\\u{", 3); - } else { - pm_buffer_append_u8(buffer, ' '); - } - pm_buffer_append_bytes(buffer, unicode_start, hexadecimal_length); - } else { + if (!(flags & PM_ESCAPE_FLAG_REGEXP)) { + uint32_t value = escape_unicode(unicode_start, hexadecimal_length); escape_write_unicode(parser, buffer, unicode_start, parser->current.end, value); } @@ -6393,13 +6385,13 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, uint8_t flags) { if (peek(parser) == '}') { parser->current.end++; - - if (flags & PM_ESCAPE_FLAG_REGEXP) { - pm_buffer_append_u8(buffer, '}'); - } } else { pm_parser_err(parser, unicode_codepoints_start, parser->current.end, PM_ERR_ESCAPE_INVALID_UNICODE_TERM); } + + if (flags & PM_ESCAPE_FLAG_REGEXP) { + pm_buffer_append_bytes(buffer, unicode_codepoints_start, (size_t) (parser->current.end - unicode_codepoints_start)); + } } else { pm_parser_err_current(parser, PM_ERR_ESCAPE_INVALID_UNICODE); } @@ -6508,6 +6500,7 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, uint8_t flags) { return; } } + /* fallthrough */ default: { if (parser->current.end < parser->end) { pm_buffer_append_u8(buffer, *parser->current.end++); diff --git a/prism/templates/lib/prism/compiler.rb.erb b/prism/templates/lib/prism/compiler.rb.erb index 03b8dfbb92..2c947f6ed2 100644 --- a/prism/templates/lib/prism/compiler.rb.erb +++ b/prism/templates/lib/prism/compiler.rb.erb @@ -33,7 +33,7 @@ module Prism end <%- nodes.each_with_index do |node, index| -%> - <%= "\n" if index != 0 -%> +<%= "\n" if index != 0 -%> # Compile a <%= node.name %> node alias visit_<%= node.human %> visit_child_nodes <%- end -%> diff --git a/prism/templates/template.rb b/prism/templates/template.rb index b2f6525eec..ac71191d77 100755 --- a/prism/templates/template.rb +++ b/prism/templates/template.rb @@ -136,7 +136,7 @@ module Prism # This represents a field on a node that is a location. class LocationField < Field def semantic_field? - options[:semantic_field] || false + false end def rbs_class @@ -151,7 +151,7 @@ module Prism # This represents a field on a node that is a location that is optional. class OptionalLocationField < Field def semantic_field? - options[:semantic_field] || false + false end def rbs_class diff --git a/test/prism/unescape_test.rb b/test/prism/unescape_test.rb index e645b1dc19..29c2137bdb 100644 --- a/test/prism/unescape_test.rb +++ b/test/prism/unescape_test.rb @@ -131,11 +131,11 @@ module Prism (0...256).each do |ord| # I think this might be a bug in Ruby. next if context.name == "?" && ord == 0xFF - + # We don't currently support scanning for the number of capture groups # to validate backreferences so these are all going to fail. next if (context.name == "//" || context.name.start_with?("%r")) && ord.chr.start_with?(/\d/) - + # \a \b \c ... assert_unescape(context, ord.chr) end @@ -162,8 +162,12 @@ module Prism # \u0000 \u0001 \u0002 ... assert_unescape(context, "u#{["5"].concat(hex.sample(3)).join}") - # \u{00 00} ... - assert_unescape(context, "u{00#{["5"].concat(hex.sample(3)).join} \t\v 00#{["5"].concat(hex.sample(3)).join}}") + # The behavior of whitespace in the middle of these escape sequences + # changed in Ruby 3.3.0, so we only want to test against latest. + if RUBY_VERSION >= "3.3.0" + # \u{00 00} ... + assert_unescape(context, "u{00#{["5"].concat(hex.sample(3)).join} \t\v 00#{["5"].concat(hex.sample(3)).join}}") + end (0...128).each do |ord| chr = ord.chr