Project

General

Profile

Actions

Bug #18988

closed

Ripper cannot parse some code that has regexp named capture

Added by tompng (tomoya ishida) over 1 year ago. Updated 10 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.0dev (2022-08-29T15:47:09Z :detached: cd7506593a) [x86_64-linux]
[ruby-core:109798]

Description

Ripper does not seems to recognize regexp named capture defining new local variables, fails to parse some code.

requie 'ripper'

# expect syntax ok, got syntax error
Ripper.sexp("/(?<a>)/ =~ ''; x = a **a, a if false")

# expect syntax error, got syntax ok
Ripper.sexp("/(?<a>)/ =~ ''; x = a **a, **a if false")

# "exit" is a method call, got string_literal
Ripper.sexp("/(?<a>)/ =~ ''; a %(exit)")
Actions #1

Updated by tompng (tomoya ishida) over 1 year ago

  • Subject changed from # Ripper cannot parse some code that has regexp named capture to Ripper cannot parse some code that has regexp named capture

Updated by jeremyevans0 (Jeremy Evans) 6 months ago

It appears that YARP parses all of these correctly:

YARP.parse("/(?<a>)/ =~ ''; x = a **a, a if false").success?
=> true    
  
YARP.parse("/(?<a>)/ =~ ''; x = a **a, **a if false").success?       
=> false    

YARP.parse("/(?<a>)/ =~ ''; a %(exit)")
# includes: ([CallNode(20...24)(nil, nil, (20...24), nil, nil, nil, nil, 2, "exit")])
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0