Skip to content

Commit

Permalink
Implement RegularExpressionNode
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Jul 8, 2024
1 parent ce531fa commit 4cd787c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/ast_to_prism/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("/(?<var>foo)/")
end

it "tests" do
pending "RegularExpressionNode locations are not supported"

test_code("/(?<var>foo)/o")
end
end

describe "array" do
it "tests" do
test_code("[]")
Expand Down
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4cd787c

Please sign in to comment.