- Notifications
You must be signed in to change notification settings - Fork 173
Closed
Description
Regardless of whether the regexp options are valid or not, I expected the same AST to be generated. However, the result is that different ASTs are produced as shown below:
Valid regexp options (Expected)
When the regexp options are valid, as in /x/io, a RegularExpressionNode is generated.
$ bundle exec ruby -Ilib -rprism -ve 'p Prism.parse("/x/io")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] #<Prism::ParseResult:0x0000000102f34258 @value=@ ProgramNode (location: (1,0)-(1,5)) ├── locals: [] └── statements: @ StatementsNode (location: (1,0)-(1,5)) └── body: (length: 1) └── @ RegularExpressionNode (location: (1,0)-(1,5)) ├── flags: ignore_case, once, forced_us_ascii_encoding ├── opening_loc: (1,0)-(1,1) = "/" ├── content_loc: (1,1)-(1,2) = "x" ├── closing_loc: (1,2)-(1,5) = "/io" └── unescaped: "x" , @comments=[], @magic_comments=[], @data_loc=nil, @errors=[], @warnings=[], @source=#<Prism::Source:0x0000000102fbf010 @source="/x/io", @start_line=1, @offsets=[0]>>Invalid regexp options (Actual)
When the regexp options are not valid, as in /x/az, not only a RegularExpressionNode is generated, but also an unexpected CallNode is produced. This appears to be invalid syntax, and az should not be treated as a method call, I think.
$ bundle exec ruby -Ilib -rprism -ve 'p Prism.parse("/x/az")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] #<Prism::ParseResult:0x00000001042db9f0 @value=@ ProgramNode (location: (1,0)-(1,5)) ├── locals: [] └── statements: @ StatementsNode (location: (1,0)-(1,5)) └── body: (length: 2) ├── @ RegularExpressionNode (location: (1,0)-(1,3)) │ ├── flags: forced_us_ascii_encoding │ ├── opening_loc: (1,0)-(1,1) = "/" │ ├── content_loc: (1,1)-(1,2) = "x" │ ├── closing_loc: (1,2)-(1,3) = "/" │ └── unescaped: "x" └── @ CallNode (location: (1,3)-(1,5)) ├── flags: variable_call, ignore_visibility ├── receiver: ∅ ├── call_operator_loc: ∅ ├── name: :az ├── message_loc: (1,3)-(1,5) = "az" ├── opening_loc: ∅ ├── arguments: ∅ ├── closing_loc: ∅ └── block: ∅ , @comments=[], @magic_comments=[], @data_loc=nil, @errors=[#<Prism::ParseError @type=:expect_eol_after_statement @message="unexpected local variable or method, expecting end-of-input" @location=#<Prism::Location @start_offset=3 @length=2 start_line=1> @level=:fatal>], @warnings=[], @source=#<Prism::Source:0x000000010435d108 @source="/x/az", @start_line=1, @offsets=[0]>>The same applies to the case of a single invalid regexp option, as in /x/a.
Metadata
Metadata
Assignees
Labels
No labels