From 3963e0e14fe0b29383dbc50272ab7f892166f355 Mon Sep 17 00:00:00 2001 From: Herwin Date: Fri, 28 Jun 2024 11:56:05 +0200 Subject: [PATCH 1/7] Add field documentation for MatchRequiredNode --- config.yml | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/config.yml b/config.yml index 879b1158a34..7fd0c4985e3 100644 --- a/config.yml +++ b/config.yml @@ -2856,10 +2856,64 @@ nodes: fields: - name: value type: node + comment: | + Represents the left-hand side of the operator, and can be any kind of Ruby expression. + + foo => bar + ^^^ - name: pattern type: node + comment: | + Represents the right-hand side of the operator. The type of the node depends on the expression. + + Anything that looks like a local variable name (including `_`) will result in a `LocalVariableTargetNode`. + + foo => a # This is equivalent to writing `a = foo` + ^ + + Using an explicit `Array` or combining expressions with `,` will result in a `ArrayPatternNode`. This can be preceded by a constant. + + foo => [a] + ^^^ + + foo => a, b + ^^^^ + + foo => Bar[a, b] + ^^^^^^^^^ + + If the array pattern contains at least two wildcard matches, a `FindPatternNode` is created instead. + + foo => *, 1, *a + ^^^^^ + + Using an explicit `Hash` or a constant with square brackets and hash keys in the square brackets will result in a `HashPatternNode`. + + foo => { a: 1, b: } + + foo => Bar[a: 1, b:] + + foo => Bar[**] + + To use any variable that needs run time evaluation, pinning is required. This results in a `PinnedVariableNode` + + foo => ^a + ^^ + + Similar, any expression can be used with pinning. This results in a `PinnedExpressionNode`. + + foo => ^(a + 1) + + Anything else will result in the regular node for that expression, for example a `ConstantReadNode`. + + foo => CONST - name: operator_loc type: location + comment: | + The location of the operator. + + foo => bar + ^^ comment: | Represents the use of the `=>` operator. From b07a61661131e7a68acc07de29ce1302d1bdecd5 Mon Sep 17 00:00:00 2001 From: Herwin Date: Fri, 28 Jun 2024 11:58:02 +0200 Subject: [PATCH 2/7] Add pattern match documentation example to LocalVariableTargetNode --- config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config.yml b/config.yml index 7fd0c4985e3..0f8449a91ab 100644 --- a/config.yml +++ b/config.yml @@ -2768,6 +2768,9 @@ nodes: foo, bar = baz ^^^ ^^^ + + foo => baz + ^^^ - name: LocalVariableWriteNode fields: - name: name From 8df13e1216c357f1570e52f2d112075fd1c27c21 Mon Sep 17 00:00:00 2001 From: Herwin Date: Fri, 28 Jun 2024 13:37:05 +0200 Subject: [PATCH 3/7] Add field documentation for ArrayPatternNode --- config.yml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/config.yml b/config.yml index 0f8449a91ab..ea5695293b0 100644 --- a/config.yml +++ b/config.yml @@ -903,16 +903,64 @@ nodes: fields: - name: constant type: node? + kind: + - ConstantPathNode + - ConstantReadNode + comment: | + Represents the optional constant preceding the Array + + foo in Bar[] + ^^^ + + foo in Bar[1, 2, 3] + ^^^ + + foo in Bar::Baz[1, 2, 3] + ^^^^^^^^ - name: requireds type: node[] + comment: | + This represents all the entries in case there is no wildcard, or the entries up to the wildcard in case there is a single wildcard. + + foo in 1, 2, 3 + ^^^^^^^ + + foo in 1, 2, * + ^^^^ - name: rest type: node? + comment: | + This represents the wildcard, which can be unnamed. + + foo in 1, 2, * + ^ + + foo in 1, 2, *a, 3 + ^^ - name: posts type: node[] + comment: | + This represents all the entries after the wildcard. + + foo in *, 1, 2, 3 + ^^^^^^^ + + foo in 1, 2, *, 3, 4 + ^^^^ - name: opening_loc type: location? + comment: | + The location of the opening brace. + + foo = [1, 2] + ^ - name: closing_loc type: location? + comment: | + The location of the closing brace. + + foo = [1, 2] + ^ comment: | Represents an array pattern in pattern matching. From 4917a156bfa50f812708d57a0823948965020804 Mon Sep 17 00:00:00 2001 From: Herwin Date: Fri, 28 Jun 2024 14:07:55 +0200 Subject: [PATCH 4/7] Add field documentation for HashPatternNode --- config.yml | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/config.yml b/config.yml index ea5695293b0..e93f8dfdeab 100644 --- a/config.yml +++ b/config.yml @@ -2160,18 +2160,61 @@ nodes: fields: - name: constant type: node? + kind: + - ConstantPathNode + - ConstantReadNode + comment: | + Represents the optional constant preceding the Hash. + + foo => Bar[a: 1, b: 2] + ^^^ + + foo => Bar::Baz[a: 1, b: 2] + ^^^^^^^^ - name: elements type: node[] kind: AssocNode + comment: | + Represents the explicit named hash keys and values. + + foo => { a: 1, b:, ** } + ^^^^^^^^ - name: rest type: node? kind: - AssocSplatNode - NoKeywordsParameterNode + comment: | + Represents the rest of the Hash keys and values. This can be named, unnamed, or explicitly forbidden via `**nil`, this last one results in a `NoKeywordsParameterNode`. + + foo => { a: 1, b:, **c } + ^^^ + + foo => { a: 1, b:, ** } + ^^ + + foo => { a: 1, b:, **nil } + ^^^^^ - name: opening_loc type: location? + comment: | + The location of the opening brace. + + foo => { a: 1 } + ^ + + foo => Bar[a: 1] + ^ - name: closing_loc type: location? + comment: | + The location of the closing brace. + + foo => { a: 1 } + ^ + + foo => Bar[a: 1] + ^ comment: | Represents a hash pattern in pattern matching. @@ -2180,6 +2223,12 @@ nodes: foo => { a: 1, b: 2, **c } ^^^^^^^^^^^^^^^^^^^ + + foo => Bar[a: 1, b: 2] + ^^^^^^^^^^^^^^^ + + foo in { a: 1, b: 2 } + ^^^^^^^^^^^^^^ - name: IfNode fields: - name: if_keyword_loc From 472f3f5d595bcc61216e9b5acd671bc5b6e3b547 Mon Sep 17 00:00:00 2001 From: Herwin Date: Fri, 28 Jun 2024 14:16:35 +0200 Subject: [PATCH 5/7] Add field documentation for FindPatternNode --- config.yml | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/config.yml b/config.yml index e93f8dfdeab..40b95d4f310 100644 --- a/config.yml +++ b/config.yml @@ -1881,16 +1881,64 @@ nodes: fields: - name: constant type: node? + kind: + - ConstantPathNode + - ConstantReadNode + comment: | + Represents the optional constant preceding the pattern + + foo in Foo(*bar, baz, *qux) + ^^^ - name: left type: node + comment: | + Represents the first wildcard node in the pattern. + + foo in *bar, baz, *qux + ^^^^ + + foo in Foo(*bar, baz, *qux) + ^^^^ - name: requireds type: node[] + comment: | + Represents the nodes in between the wildcards. + + foo in *bar, baz, *qux + ^^^ + + foo in Foo(*bar, baz, 1, *qux) + ^^^^^^ - name: right type: node + comment: | + Represents the second wildcard node in the pattern. + + foo in *bar, baz, *qux + ^^^^ + + foo in Foo(*bar, baz, *qux) + ^^^^ - name: opening_loc type: location? + comment: | + The location of the openingbrace. + + foo in [*bar, baz, *qux] + ^ + + foo in Foo(*bar, baz, *qux) + ^ - name: closing_loc type: location? + comment: | + The location of the closing brace. + + foo in [*bar, baz, *qux] + ^ + + foo in Foo(*bar, baz, *qux) + ^ comment: | Represents a find pattern in pattern matching. @@ -1902,6 +1950,9 @@ nodes: foo in Foo(*bar, baz, *qux) ^^^^^^^^^^^^^^^^^^^^ + + foo => *bar, baz, *qux + ^^^^^^^^^^^^^^^ - name: FlipFlopNode fields: - name: flags From 18906c04acea0370788424be54af099e288b448b Mon Sep 17 00:00:00 2001 From: Herwin Date: Sat, 29 Jun 2024 17:17:16 +0200 Subject: [PATCH 6/7] Add field documentation for PinnedVariableNode --- config.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config.yml b/config.yml index 40b95d4f310..98c88582079 100644 --- a/config.yml +++ b/config.yml @@ -3493,8 +3493,18 @@ nodes: fields: - name: variable type: node + comment: | + The variable used in the pinned expression + + foo in ^bar + ^^^ - name: operator_loc type: location + comment: | + The location of the `^` operator + + foo in ^bar + ^ comment: | Represents the use of the `^` operator for pinning a variable in a pattern matching expression. From cc7fdf5d363272c6257c619754e8f83dcf5dd0e8 Mon Sep 17 00:00:00 2001 From: Herwin Date: Tue, 2 Jul 2024 16:56:38 +0200 Subject: [PATCH 7/7] Add field documentation for PinnedExpressionNode --- config.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/config.yml b/config.yml index 98c88582079..eba22f0adff 100644 --- a/config.yml +++ b/config.yml @@ -3478,12 +3478,32 @@ nodes: fields: - name: expression type: node + comment: | + The expression used in the pinned expression + + foo in ^(bar) + ^^^ - name: operator_loc type: location + comment: | + The location of the `^` operator + + foo in ^(bar) + ^ - name: lparen_loc type: location + comment: | + The location of the opening parenthesis. + + foo in ^(bar) + ^ - name: rparen_loc type: location + comment: | + The location of the closing parenthesis. + + foo in ^(bar) + ^ comment: | Represents the use of the `^` operator for pinning an expression in a pattern matching expression.