Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RegularExpressionNode #36

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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