From d59882ac36cdccea057211bd05b700257330f023 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Thu, 5 May 2022 20:44:17 -0400 Subject: [PATCH] Options on regexp Add `options` as a method on `SyntaxTree::RegexpLiteral`, add it to pattern matching, and describe it using the `SyntaxTree::Visitor::FieldVisitor` class. --- lib/syntax_tree/node.rb | 9 +++++++-- lib/syntax_tree/visitor/field_visitor.rb | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index e5aa6b50..7d7e0f87 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -7456,6 +7456,7 @@ def deconstruct_keys(_keys) { beginning: beginning, ending: ending, + options: options, parts: parts, location: location, comments: comments @@ -7490,18 +7491,22 @@ def format(q) end q.text("}") - q.text(ending[1..]) + q.text(options) end else q.group do q.text("/") q.format_each(parts) q.text("/") - q.text(ending[1..]) + q.text(options) end end end + def options + ending[1..] + end + private def include?(pattern) diff --git a/lib/syntax_tree/visitor/field_visitor.rb b/lib/syntax_tree/visitor/field_visitor.rb index 06e8945f..827b4e3a 100644 --- a/lib/syntax_tree/visitor/field_visitor.rb +++ b/lib/syntax_tree/visitor/field_visitor.rb @@ -738,6 +738,7 @@ def visit_regexp_end(node) def visit_regexp_literal(node) node(node, "regexp_literal") do list("parts", node.parts) + field("options", node.options) comments(node) end end