diff --git a/lib/ast_to_prism/parser.rb b/lib/ast_to_prism/parser.rb index c67f303..23daaeb 100644 --- a/lib/ast_to_prism/parser.rb +++ b/lib/ast_to_prism/parser.rb @@ -1673,7 +1673,19 @@ def convert_node(node, block: nil) location(node) # location ) when :REGX - not_supported(node) + regx, = node.children + # TODO: RubyVM::AST needs to export `options` + flags = 0 + + Prism::RegularExpressionNode.new( + source, # source + flags, # flags + null_location, # opening_loc + null_location, # content_loc + null_location, # closing_loc + regx.source, # unescaped + location(node) # location + ) when :ONCE not_supported(node) when :DSTR diff --git a/spec/basic_spec.rb b/spec/basic_spec.rb index cb5cacd..75138b9 100644 --- a/spec/basic_spec.rb +++ b/spec/basic_spec.rb @@ -203,6 +203,32 @@ def test_code(code) end end + describe "regex" do + it "tests" do + pending "RegularExpressionNode locations are not supported" + + test_code("/foo/") + end + + it "tests" do + pending "RegularExpressionNode locations are not supported" + + test_code("/foo/o") + end + + it "tests" do + pending "RegularExpressionNode locations are not supported" + + test_code("/(?foo)/") + end + + it "tests" do + pending "RegularExpressionNode locations are not supported" + + test_code("/(?foo)/o") + end + end + describe "array" do it "tests" do test_code("[]") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 96cf959..2781cbf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,6 +44,18 @@ def ===(other) } end + class RegularExpressionNode + prepend Module.new { + def ===(other) + super(other) && + self.location == other.location && + self.opening_loc == other.opening_loc && + self.content_loc == other.content_loc && + self.closing_loc == other.closing_loc + end + } + end + class IfNode prepend Module.new { def ===(other)