mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 15:36:16 +02:00
[ruby/yarp] Introduce MatchWriteNode
This rarely used node holds information about the local variables
that need to get written in the case a regular expression is used on
the left-hand side of a =~ operator and it has named capture groups.
Note that we already "handled" these nodes by adding locals to the
AST, but we didn't actually expose this information, making it
difficult to compile.
The general idea behind this node is that it maintains the ability
for consumers to find all of the call nodes in the tree easily so
it's not flattening down. However, it should be okay because you
hopefully don't need any information in the call node to determine
what to compile because the locals list is on the top level.
e136e7f9a8
This commit is contained in:
parent
9d2549ac31
commit
0a8f3670d1
5 changed files with 109 additions and 59 deletions
|
@ -545,6 +545,10 @@ module YARP
|
|||
assert_location(MatchRequiredNode, "foo => bar")
|
||||
end
|
||||
|
||||
def test_MatchWriteNode
|
||||
assert_location(MatchWriteNode, "/(?<foo>)/ =~ foo")
|
||||
end
|
||||
|
||||
def test_ModuleNode
|
||||
assert_location(ModuleNode, "module Foo end")
|
||||
end
|
||||
|
|
|
@ -84,34 +84,37 @@
|
|||
│ └── flags: ∅
|
||||
├── @ ArrayNode (location: (59...86))
|
||||
│ ├── elements: (length: 2)
|
||||
│ │ ├── @ CallNode (location: (60...80))
|
||||
│ │ │ ├── receiver:
|
||||
│ │ │ │ @ RegularExpressionNode (location: (60...73))
|
||||
│ │ │ │ ├── opening_loc: (60...61) = "/"
|
||||
│ │ │ │ ├── content_loc: (61...72) = "(?<foo>bar)"
|
||||
│ │ │ │ ├── closing_loc: (72...73) = "/"
|
||||
│ │ │ │ ├── unescaped: "(?<foo>bar)"
|
||||
│ │ │ │ └── flags: ∅
|
||||
│ │ │ ├── call_operator_loc: ∅
|
||||
│ │ │ ├── message_loc: (74...76) = "=~"
|
||||
│ │ │ ├── opening_loc: ∅
|
||||
│ │ │ ├── arguments:
|
||||
│ │ │ │ @ ArgumentsNode (location: (77...80))
|
||||
│ │ │ │ └── arguments: (length: 1)
|
||||
│ │ │ │ └── @ CallNode (location: (77...80))
|
||||
│ │ │ │ ├── receiver: ∅
|
||||
│ │ │ │ ├── call_operator_loc: ∅
|
||||
│ │ │ │ ├── message_loc: (77...80) = "baz"
|
||||
│ │ │ │ ├── opening_loc: ∅
|
||||
│ │ │ │ ├── arguments: ∅
|
||||
│ │ │ │ ├── closing_loc: ∅
|
||||
│ │ │ │ ├── block: ∅
|
||||
│ │ │ │ ├── flags: variable_call
|
||||
│ │ │ │ └── name: "baz"
|
||||
│ │ │ ├── closing_loc: ∅
|
||||
│ │ │ ├── block: ∅
|
||||
│ │ │ ├── flags: ∅
|
||||
│ │ │ └── name: "=~"
|
||||
│ │ ├── @ MatchWriteNode (location: (60...80))
|
||||
│ │ │ ├── call:
|
||||
│ │ │ │ @ CallNode (location: (60...80))
|
||||
│ │ │ │ ├── receiver:
|
||||
│ │ │ │ │ @ RegularExpressionNode (location: (60...73))
|
||||
│ │ │ │ │ ├── opening_loc: (60...61) = "/"
|
||||
│ │ │ │ │ ├── content_loc: (61...72) = "(?<foo>bar)"
|
||||
│ │ │ │ │ ├── closing_loc: (72...73) = "/"
|
||||
│ │ │ │ │ ├── unescaped: "(?<foo>bar)"
|
||||
│ │ │ │ │ └── flags: ∅
|
||||
│ │ │ │ ├── call_operator_loc: ∅
|
||||
│ │ │ │ ├── message_loc: (74...76) = "=~"
|
||||
│ │ │ │ ├── opening_loc: ∅
|
||||
│ │ │ │ ├── arguments:
|
||||
│ │ │ │ │ @ ArgumentsNode (location: (77...80))
|
||||
│ │ │ │ │ └── arguments: (length: 1)
|
||||
│ │ │ │ │ └── @ CallNode (location: (77...80))
|
||||
│ │ │ │ │ ├── receiver: ∅
|
||||
│ │ │ │ │ ├── call_operator_loc: ∅
|
||||
│ │ │ │ │ ├── message_loc: (77...80) = "baz"
|
||||
│ │ │ │ │ ├── opening_loc: ∅
|
||||
│ │ │ │ │ ├── arguments: ∅
|
||||
│ │ │ │ │ ├── closing_loc: ∅
|
||||
│ │ │ │ │ ├── block: ∅
|
||||
│ │ │ │ │ ├── flags: variable_call
|
||||
│ │ │ │ │ └── name: "baz"
|
||||
│ │ │ │ ├── closing_loc: ∅
|
||||
│ │ │ │ ├── block: ∅
|
||||
│ │ │ │ ├── flags: ∅
|
||||
│ │ │ │ └── name: "=~"
|
||||
│ │ │ └── locals: [:foo]
|
||||
│ │ └── @ LocalVariableReadNode (location: (82...85))
|
||||
│ │ ├── name: :foo
|
||||
│ │ └── depth: 0
|
||||
|
|
|
@ -3,30 +3,33 @@
|
|||
└── statements:
|
||||
@ StatementsNode (location: (0...31))
|
||||
└── body: (length: 2)
|
||||
├── @ CallNode (location: (0...24))
|
||||
│ ├── receiver:
|
||||
│ │ @ RegularExpressionNode (location: (0...15))
|
||||
│ │ ├── opening_loc: (0...1) = "/"
|
||||
│ │ ├── content_loc: (1...14) = "(?<match>bar)"
|
||||
│ │ ├── closing_loc: (14...15) = "/"
|
||||
│ │ ├── unescaped: "(?<match>bar)"
|
||||
│ │ └── flags: ∅
|
||||
│ ├── call_operator_loc: ∅
|
||||
│ ├── message_loc: (16...18) = "=~"
|
||||
│ ├── opening_loc: ∅
|
||||
│ ├── arguments:
|
||||
│ │ @ ArgumentsNode (location: (19...24))
|
||||
│ │ └── arguments: (length: 1)
|
||||
│ │ └── @ StringNode (location: (19...24))
|
||||
│ │ ├── flags: ∅
|
||||
│ │ ├── opening_loc: (19...20) = "'"
|
||||
│ │ ├── content_loc: (20...23) = "bar"
|
||||
│ │ ├── closing_loc: (23...24) = "'"
|
||||
│ │ └── unescaped: "bar"
|
||||
│ ├── closing_loc: ∅
|
||||
│ ├── block: ∅
|
||||
│ ├── flags: ∅
|
||||
│ └── name: "=~"
|
||||
├── @ MatchWriteNode (location: (0...24))
|
||||
│ ├── call:
|
||||
│ │ @ CallNode (location: (0...24))
|
||||
│ │ ├── receiver:
|
||||
│ │ │ @ RegularExpressionNode (location: (0...15))
|
||||
│ │ │ ├── opening_loc: (0...1) = "/"
|
||||
│ │ │ ├── content_loc: (1...14) = "(?<match>bar)"
|
||||
│ │ │ ├── closing_loc: (14...15) = "/"
|
||||
│ │ │ ├── unescaped: "(?<match>bar)"
|
||||
│ │ │ └── flags: ∅
|
||||
│ │ ├── call_operator_loc: ∅
|
||||
│ │ ├── message_loc: (16...18) = "=~"
|
||||
│ │ ├── opening_loc: ∅
|
||||
│ │ ├── arguments:
|
||||
│ │ │ @ ArgumentsNode (location: (19...24))
|
||||
│ │ │ └── arguments: (length: 1)
|
||||
│ │ │ └── @ StringNode (location: (19...24))
|
||||
│ │ │ ├── flags: ∅
|
||||
│ │ │ ├── opening_loc: (19...20) = "'"
|
||||
│ │ │ ├── content_loc: (20...23) = "bar"
|
||||
│ │ │ ├── closing_loc: (23...24) = "'"
|
||||
│ │ │ └── unescaped: "bar"
|
||||
│ │ ├── closing_loc: ∅
|
||||
│ │ ├── block: ∅
|
||||
│ │ ├── flags: ∅
|
||||
│ │ └── name: "=~"
|
||||
│ └── locals: [:match]
|
||||
└── @ LocalVariableReadNode (location: (26...31))
|
||||
├── name: :match
|
||||
└── depth: 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue