Skip to content
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
73 changes: 60 additions & 13 deletions ruby/extractor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ruby/extractor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
[dependencies]
tree-sitter = "0.20"
tree-sitter-embedded-template = { git = "https://github.com/tree-sitter/tree-sitter-embedded-template.git", rev = "203f7bd3c1bbfbd98fc19add4b8fcb213c059205" }
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "2edbd437ee901b8fa95861ec538e56efe3ebd127" }
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "4d9ad3f010fdc47a8433adcf9ae30c8eb8475ae7" }
clap = { version = "4.2", features = ["derive"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
Expand Down
5 changes: 5 additions & 0 deletions ruby/ql/lib/change-notes/2024-01-05-division-newline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: minorAnalysis
---
* Parsing of division operators (`/`) at the end of a line has been improved. Before they were wrongly interpreted as the start of a regular expression literal (`/.../`) leading to syntax errors.
* Parsing of `case` statements that are formatted with the value expression on a different line than the `case` keyword has been improved and should no longer lead to syntax errors.
16 changes: 16 additions & 0 deletions ruby/ql/test/library-tests/ast/Ast.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,19 @@ control/cases.rb:
# 162| getKey: [SymbolLiteral] :y
# 162| getComponent: [StringTextComponent] y
# 162| getValue: [IntegerLiteral] 1
# 164| getStmt: [CaseExpr] case ...
# 165| getValue: [LocalVariableAccess] foo
# 166| getBranch: [WhenClause] when ...
# 166| getPattern: [IntegerLiteral] 1
# 166| getBody: [StmtSequence] then ...
# 166| getStmt: [IntegerLiteral] 2
# 169| getStmt: [CaseExpr] case ...
# 170| getValue: [LocalVariableAccess] foo
# 171| getBranch: [InClause] in ... then ...
# 171| getPattern: [IntegerLiteral] 3
# 171| getBody: [StmtSequence] then ...
# 171| getStmt: [StringLiteral] "three"
# 171| getComponent: [StringTextComponent] three
modules/classes.rb:
# 2| [Toplevel] classes.rb
# 3| getStmt: [ClassDeclaration] Foo
Expand Down Expand Up @@ -2888,6 +2901,9 @@ operations/operations.rb:
# 104| getElement: [IntegerLiteral] 1
# 104| getElement: [IntegerLiteral] 2
# 104| getElement: [IntegerLiteral] 3
# 106| getStmt: [DivExpr] ... / ...
# 106| getAnOperand/getLeftOperand/getReceiver: [LocalVariableAccess] foo
# 107| getAnOperand/getArgument/getRightOperand: [IntegerLiteral] 5
params/params.rb:
# 1| [Toplevel] params.rb
# 4| getStmt: [Method] identifier_method_params
Expand Down
28 changes: 28 additions & 0 deletions ruby/ql/test/library-tests/ast/TreeSitter.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2756,6 +2756,30 @@ control/cases.rb:
# 162| 1: [ReservedWord] :
# 162| 2: [Integer] 1
# 162| 4: [ReservedWord] }
# 164| 19: [Case] Case
# 164| 0: [ReservedWord] case
# 165| 1: [Identifier] foo
# 166| 2: [When] When
# 166| 0: [ReservedWord] when
# 166| 1: [Pattern] Pattern
# 166| 0: [Integer] 1
# 166| 2: [Then] Then
# 166| 0: [ReservedWord] then
# 166| 1: [Integer] 2
# 167| 3: [ReservedWord] end
# 169| 20: [CaseMatch] CaseMatch
# 169| 0: [ReservedWord] case
# 170| 1: [Identifier] foo
# 171| 2: [InClause] InClause
# 171| 0: [ReservedWord] in
# 171| 1: [Integer] 3
# 171| 2: [Then] Then
# 171| 0: [ReservedWord] then
# 171| 1: [String] String
# 171| 0: [ReservedWord] "
# 171| 1: [StringContent] three
# 171| 2: [ReservedWord] "
# 172| 3: [ReservedWord] end
# 1| [Comment] # Define some variables used below
# 7| [Comment] # A case expr with a value and an else branch
# 17| [Comment] # A case expr without a value or else branch
Expand Down Expand Up @@ -5636,6 +5660,10 @@ operations/operations.rb:
# 104| 4: [ReservedWord] ,
# 104| 5: [Integer] 3
# 104| 6: [ReservedWord] ]
# 106| 73: [Binary] Binary
# 106| 0: [Identifier] foo
# 106| 1: [ReservedWord] /
# 107| 2: [Integer] 5
# 1| [Comment] # Start with assignments to all the identifiers used below, so that they are
# 2| [Comment] # interpreted as variables.
# 22| [Comment] # Unary operations
Expand Down
14 changes: 14 additions & 0 deletions ruby/ql/test/library-tests/ast/ValueText.expected
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ exprValue
| control/cases.rb:162:10:162:10 | :x | :x | symbol |
| control/cases.rb:162:16:162:16 | :y | :y | symbol |
| control/cases.rb:162:19:162:19 | 1 | 1 | int |
| control/cases.rb:165:3:165:5 | foo | 42 | int |
| control/cases.rb:166:6:166:6 | 1 | 1 | int |
| control/cases.rb:166:13:166:13 | 2 | 2 | int |
| control/cases.rb:170:3:170:5 | foo | 42 | int |
| control/cases.rb:171:4:171:4 | 3 | 3 | int |
| control/cases.rb:171:11:171:17 | "three" | three | string |
| control/conditionals.rb:2:5:2:5 | 0 | 0 | int |
| control/conditionals.rb:3:5:3:5 | 0 | 0 | int |
| control/conditionals.rb:4:5:4:5 | 0 | 0 | int |
Expand Down Expand Up @@ -921,6 +927,7 @@ exprValue
| operations/operations.rb:104:25:104:25 | 1 | 1 | int |
| operations/operations.rb:104:28:104:28 | 2 | 2 | int |
| operations/operations.rb:104:31:104:31 | 3 | 3 | int |
| operations/operations.rb:107:1:107:1 | 5 | 5 | int |
| params/params.rb:41:46:41:46 | 7 | 7 | int |
| params/params.rb:47:19:47:21 | :bar | :bar | symbol |
| params/params.rb:47:24:47:24 | 2 | 2 | int |
Expand Down Expand Up @@ -1184,6 +1191,12 @@ exprCfgNodeValue
| control/cases.rb:160:13:160:13 | 2 | 2 | int |
| control/cases.rb:162:1:162:20 | nil | nil | nil |
| control/cases.rb:162:19:162:19 | 1 | 1 | int |
| control/cases.rb:165:3:165:5 | foo | 42 | int |
| control/cases.rb:166:6:166:6 | 1 | 1 | int |
| control/cases.rb:166:13:166:13 | 2 | 2 | int |
| control/cases.rb:170:3:170:5 | foo | 42 | int |
| control/cases.rb:171:4:171:4 | 3 | 3 | int |
| control/cases.rb:171:11:171:17 | "three" | three | string |
| control/conditionals.rb:2:5:2:5 | 0 | 0 | int |
| control/conditionals.rb:3:5:3:5 | 0 | 0 | int |
| control/conditionals.rb:4:5:4:5 | 0 | 0 | int |
Expand Down Expand Up @@ -1828,6 +1841,7 @@ exprCfgNodeValue
| operations/operations.rb:104:25:104:25 | 1 | 1 | int |
| operations/operations.rb:104:28:104:28 | 2 | 2 | int |
| operations/operations.rb:104:31:104:31 | 3 | 3 | int |
| operations/operations.rb:107:1:107:1 | 5 | 5 | int |
| params/params.rb:41:46:41:46 | 7 | 7 | int |
| params/params.rb:47:19:47:21 | :bar | :bar | symbol |
| params/params.rb:47:24:47:24 | 2 | 2 | int |
Expand Down
7 changes: 7 additions & 0 deletions ruby/ql/test/library-tests/ast/control/CaseExpr.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ caseValues
| cases.rb:154:1:158:3 | case ... | cases.rb:154:6:154:9 | call to expr |
| cases.rb:160:1:160:14 | case ... | cases.rb:160:1:160:4 | call to expr |
| cases.rb:162:1:162:20 | case ... | cases.rb:162:1:162:4 | call to expr |
| cases.rb:164:1:167:3 | case ... | cases.rb:165:3:165:5 | foo |
| cases.rb:169:1:172:3 | case ... | cases.rb:170:3:170:5 | foo |
caseNoValues
| cases.rb:18:1:22:3 | case ... |
caseElseBranches
Expand All @@ -30,13 +32,16 @@ caseNoElseBranches
| cases.rb:147:1:152:3 | case ... |
| cases.rb:154:1:158:3 | case ... |
| cases.rb:162:1:162:20 | case ... |
| cases.rb:164:1:167:3 | case ... |
| cases.rb:169:1:172:3 | case ... |
caseWhenBranches
| cases.rb:8:1:15:3 | case ... | cases.rb:9:1:10:7 | when ... | 0 | cases.rb:9:6:9:6 | b | cases.rb:9:7:10:7 | then ... |
| cases.rb:8:1:15:3 | case ... | cases.rb:11:1:12:7 | when ... | 0 | cases.rb:11:6:11:6 | c | cases.rb:11:10:12:7 | then ... |
| cases.rb:8:1:15:3 | case ... | cases.rb:11:1:12:7 | when ... | 1 | cases.rb:11:9:11:9 | d | cases.rb:11:10:12:7 | then ... |
| cases.rb:18:1:22:3 | case ... | cases.rb:19:1:19:19 | when ... | 0 | cases.rb:19:6:19:10 | ... > ... | cases.rb:19:13:19:19 | then ... |
| cases.rb:18:1:22:3 | case ... | cases.rb:20:1:20:19 | when ... | 0 | cases.rb:20:6:20:11 | ... == ... | cases.rb:20:13:20:19 | then ... |
| cases.rb:18:1:22:3 | case ... | cases.rb:21:1:21:19 | when ... | 0 | cases.rb:21:6:21:10 | ... < ... | cases.rb:21:13:21:19 | then ... |
| cases.rb:164:1:167:3 | case ... | cases.rb:166:1:166:13 | when ... | 0 | cases.rb:166:6:166:6 | 1 | cases.rb:166:8:166:13 | then ... |
caseAllBranches
| cases.rb:8:1:15:3 | case ... | 0 | cases.rb:9:1:10:7 | when ... |
| cases.rb:8:1:15:3 | case ... | 1 | cases.rb:11:1:12:7 | when ... |
Expand Down Expand Up @@ -139,3 +144,5 @@ caseAllBranches
| cases.rb:160:1:160:14 | case ... | 0 | cases.rb:160:1:160:14 | in ... then ... |
| cases.rb:160:1:160:14 | case ... | 1 | cases.rb:160:1:160:14 | else ... |
| cases.rb:162:1:162:20 | case ... | 0 | cases.rb:162:1:162:20 | in ... then ... |
| cases.rb:164:1:167:3 | case ... | 0 | cases.rb:166:1:166:13 | when ... |
| cases.rb:169:1:172:3 | case ... | 0 | cases.rb:171:1:171:17 | in ... then ... |
2 changes: 2 additions & 0 deletions ruby/ql/test/library-tests/ast/control/ControlExpr.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
| cases.rb:154:1:158:3 | case ... | CaseExpr |
| cases.rb:160:1:160:14 | case ... | CaseExpr |
| cases.rb:162:1:162:20 | case ... | CaseExpr |
| cases.rb:164:1:167:3 | case ... | CaseExpr |
| cases.rb:169:1:172:3 | case ... | CaseExpr |
| conditionals.rb:10:1:12:3 | if ... | IfExpr |
| conditionals.rb:15:1:19:3 | if ... | IfExpr |
| conditionals.rb:22:1:30:3 | if ... | IfExpr |
Expand Down
12 changes: 11 additions & 1 deletion ruby/ql/test/library-tests/ast/control/cases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,14 @@

expr in [1, 2]

expr => {x: v, y: 1}
expr => {x: v, y: 1}

case
foo
when 1 then 2
end

case
foo
in 3 then "three"
end
2 changes: 2 additions & 0 deletions ruby/ql/test/library-tests/ast/operations/binary.expected
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ binaryOperations
| operations.rb:101:21:101:23 | ... \|\| ... | \|\| | operations.rb:101:1:101:19 | MemberConstant | operations.rb:101:25:101:25 | 8 | LogicalOrExpr |
| operations.rb:102:27:102:29 | ... \|\| ... | \|\| | operations.rb:102:1:102:25 | OtherConstant | operations.rb:102:31:102:31 | 7 | LogicalOrExpr |
| operations.rb:103:13:103:15 | ... \|\| ... | \|\| | operations.rb:103:1:103:11 | CONSTANT4 | operations.rb:103:17:103:17 | 7 | LogicalOrExpr |
| operations.rb:106:1:107:1 | ... / ... | / | operations.rb:106:1:106:3 | foo | operations.rb:107:1:107:1 | 5 | DivExpr |
binaryArithmeticOperations
| operations.rb:32:1:32:7 | ... + ... | + | operations.rb:32:1:32:1 | w | operations.rb:32:5:32:7 | 234 | AddExpr |
| operations.rb:33:1:33:6 | ... - ... | - | operations.rb:33:1:33:1 | x | operations.rb:33:5:33:6 | 17 | SubExpr |
Expand All @@ -62,6 +63,7 @@ binaryArithmeticOperations
| operations.rb:92:7:92:8 | ... / ... | / | operations.rb:92:3:92:5 | @@y | operations.rb:92:10:92:10 | 4 | DivExpr |
| operations.rb:96:13:96:14 | ... * ... | * | operations.rb:96:1:96:11 | $global_var | operations.rb:96:16:96:16 | 6 | MulExpr |
| operations.rb:99:11:99:12 | ... + ... | + | operations.rb:99:1:99:9 | CONSTANT2 | operations.rb:99:14:99:14 | 6 | AddExpr |
| operations.rb:106:1:107:1 | ... / ... | / | operations.rb:106:1:106:3 | foo | operations.rb:107:1:107:1 | 5 | DivExpr |
binaryLogicalOperations
| operations.rb:40:1:40:10 | ... && ... | && | operations.rb:40:1:40:3 | foo | operations.rb:40:8:40:10 | bar | LogicalAndExpr |
| operations.rb:41:1:41:11 | ... and ... | and | operations.rb:41:1:41:3 | baz | operations.rb:41:9:41:11 | qux | LogicalAndExpr |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,5 @@
| operations.rb:104:24:104:32 | * ... | * | operations.rb:104:24:104:32 | [...] | SplatExpr |
| operations.rb:104:24:104:32 | ... = ... | = | operations.rb:104:24:104:32 | * ... | AssignExpr |
| operations.rb:104:24:104:32 | ... = ... | = | operations.rb:104:24:104:32 | __synth__3 | AssignExpr |
| operations.rb:106:1:107:1 | ... / ... | / | operations.rb:106:1:106:3 | foo | DivExpr |
| operations.rb:106:1:107:1 | ... / ... | / | operations.rb:107:1:107:1 | 5 | DivExpr |
3 changes: 3 additions & 0 deletions ruby/ql/test/library-tests/ast/operations/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ class X
foo(1).bar::OtherConstant ||= 7
::CONSTANT4 ||= 7
FOO, ::BAR, foo::FOO = [1, 2, 3]

foo /
5