summaryrefslogtreecommitdiff
path: root/test/ruby/test_ast.rb
AgeCommit message (Collapse)Author
2025-12-30[Bug #21784] Fix the Proc#source_location start_column for stabby lambdasBenoit Daloze
* Consistent with plain `blocks` and `for` blocks and methods where the source_location covers their entire definition. * Matches the documentation which mentions "where the definition starts/ends". * Partially reverts d357d50f0a74409446f4cccec78593373f5adf2f which was a workaround to be compatible with parse.y.
2025-09-12Suppress warnings when testing RubyVM::AbstractSyntaxTreeÉtienne Barrié
2025-08-30Add NODE SCLASS locationsS-H-GAMELINKS
Add locations to struct `RNode_SCLASS`. memo: ``` @ ProgramNode (location: (1,0)-(1,18)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,18)) +-- body: (length: 1) +-- @ SingletonClassNode (location: (1,0)-(1,18)) +-- locals: [] +-- class_keyword_loc: (1,0)-(1,5) = "class" +-- operator_loc: (1,6)-(1,8) = "<<" +-- expression: | @ SelfNode (location: (1,9)-(1,13)) +-- body: nil +-- end_keyword_loc: (1,15)-(1,18) = "end" ```
2025-08-28Allow to get a NODE_SCOPE node of dummy stack frame of ArgumentErrorYusuke Endoh
Previously, it was not possible to obtain a node of the callee's `Thread::Backtrace::Location` for cases like "wrong number of arguments" by using `RubyVM::AST.of`. This change allows that retrieval. This is preparation for [Feature #21543].
2025-08-28Make `RubyVM::AST.of` return a parent node of NODE_SCOPEYusuke Endoh
This change makes `RubyVM::AST.of` and `.node_id_for_backtrace_location` return a parent node of NODE_SCOPE (such as NODE_DEFN) instead of the NODE_SCOPE node itself. (In future, we may remove NODE_SCOPE, which is a bit hacky AST node.) This is preparation for [Feature #21543].
2025-08-11Add NODE IN locationsS-H-GAMELINKS
Add locations to struct `RNode_IN`. memo: ```bash > ruby -e 'case 1; in 2 then 3; end' --parser=prism --dump=parsetree @ ProgramNode (location: (1,0)-(1,24)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,24)) +-- body: (length: 1) +-- @ CaseMatchNode (location: (1,0)-(1,24)) +-- predicate: | @ IntegerNode (location: (1,5)-(1,6)) | +-- IntegerBaseFlags: decimal | +-- value: 1 +-- conditions: (length: 1) | +-- @ InNode (location: (1,8)-(1,19)) | +-- pattern: | | @ IntegerNode (location: (1,11)-(1,12)) | | +-- IntegerBaseFlags: decimal | | +-- value: 2 | +-- statements: | | @ StatementsNode (location: (1,18)-(1,19)) | | +-- body: (length: 1) | | +-- @ IntegerNode (location: (1,18)-(1,19)) | | +-- IntegerBaseFlags: decimal | | +-- value: 3 | +-- in_loc: (1,8)-(1,10) = "in" | +-- then_loc: (1,13)-(1,17) = "then" +-- else_clause: nil +-- case_keyword_loc: (1,0)-(1,4) = "case" +-- end_keyword_loc: (1,21)-(1,24) = "end" ```
2025-08-07Add MODULE NODE locationsS-H-GAMELINKS
Add `keyword_module` amd `keyword_end` locations to struct `RNode_MODULE`. memo: ``` >ruby --dump=parsetree -e 'module A end' @ ProgramNode (location: (1,0)-(1,12)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,12)) +-- body: (length: 1) +-- @ ModuleNode (location: (1,0)-(1,12)) +-- locals: [] +-- module_keyword_loc: (1,0)-(1,6) = "module" +-- constant_path: | @ ConstantReadNode (location: (1,7)-(1,8)) | +-- name: :A +-- body: nil +-- end_keyword_loc: (1,9)-(1,12) = "end" +-- name: :A ```
2025-07-25Add NODE_DEFINED tests for cases with parentheses to test_ast.rbydah
2025-07-24Add DEFINED NODE locationsS-H-GAMELINKS
Add keyword_defined locations to struct RNode_DEFINED
2025-06-15Implement COLON3 NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11987
2025-06-15Implement COLON2 NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11987
2025-05-29Fix memory leak with invalid yield in prismPeter Zhu
[Bug #21383] The following script leaks memory: 10.times do 20_000.times do eval("class C; yield; end") rescue SyntaxError end puts `ps -o rss= -p #{$$}` end Before: 16464 25536 29424 35904 39552 44576 46736 51600 56096 59824 After: 13488 16160 18240 20528 19760 21808 21680 22272 22064 22336 Notes: Merged: https://github.com/ruby/ruby/pull/13464
2025-04-04Fixed mismatched indentationHiroshi SHIBATA
2025-03-08Implement CLASS NODE locationsydah
The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -e "class A < B; end" @ ProgramNode (location: (1,0)-(1,16)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,16)) +-- body: (length: 1) +-- @ ClassNode (location: (1,0)-(1,16)) +-- locals: [] +-- class_keyword_loc: (1,0)-(1,5) = "class" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- constant_path: | @ ConstantReadNode (location: (1,6)-(1,7)) | +-- name: :A +-- inheritance_operator_loc: (1,8)-(1,9) = "<" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- superclass: | @ ConstantReadNode (location: (1,10)-(1,11)) | +-- name: :B +-- body: nil +-- end_keyword_loc: (1,13)-(1,16) = "end" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- name: :A ```
2025-03-05Add tests for alias locations with special variables $`, $', and $+ydah
Notes: Merged: https://github.com/ruby/ruby/pull/12837
2025-03-03Implement POSTEXE NODE locationsydah
The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -e "END { }" @ ProgramNode (location: (1,0)-(1,8)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,8)) +-- body: (length: 1) +-- @ PostExecutionNode (location: (1,0)-(1,8)) +-- statements: nil +-- keyword_loc: (1,0)-(1,3) = "END" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- opening_loc: (1,4)-(1,5) = "{" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- closing_loc: (1,7)-(1,8) = "}" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ```
2025-01-09Implement FOR NODE locationsydah
The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -e "for a in b do end" @ ProgramNode (location: (1,0)-(1,17)) +-- locals: [:a] +-- statements: @ StatementsNode (location: (1,0)-(1,17)) +-- body: (length: 1) +-- @ ForNode (location: (1,0)-(1,17)) +-- index: | @ LocalVariableTargetNode (location: (1,4)-(1,5)) | +-- name: :a | +-- depth: 0 +-- collection: | @ CallNode (location: (1,9)-(1,10)) | +-- CallNodeFlags: variable_call, ignore_visibility | +-- receiver: nil | +-- call_operator_loc: nil | +-- name: :b | +-- message_loc: (1,9)-(1,10) = "b" | +-- opening_loc: nil | +-- arguments: nil | +-- closing_loc: nil | +-- block: nil +-- statements: nil +-- for_keyword_loc: (1,0)-(1,3) = "for" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- in_keyword_loc: (1,6)-(1,8) = "in" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- do_keyword_loc: (1,11)-(1,13) = "do" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- end_keyword_loc: (1,14)-(1,17) = "end" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ```
2025-01-04Suppress warnings for flip-flop in test_ast.rbPeter Zhu
There are warnings emitted from test_flip2_locations and test_flip3_locations. This commit changes ast_parse to suppress all warnings. warning: integer literal in flip-flop warning: string literal in flip-flop Notes: Merged: https://github.com/ruby/ruby/pull/12509
2025-01-04Implement FLIP3 NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11986
2025-01-04Implement FLIP2 NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11986
2025-01-04Implement DOT3 NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11986
2025-01-04Implement DOT2 NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11986
2025-01-04Implement REGX NODE locationsydah
The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -e '/foo/' @ ProgramNode (location: (1,0)-(1,5)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,5)) +-- body: (length: 1) +-- @ RegularExpressionNode (location: (1,0)-(1,5)) +-- RegularExpressionFlags: forced_us_ascii_encoding +-- opening_loc: (1,0)-(1,1) = "/" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- content_loc: (1,1)-(1,4) = "foo" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- closing_loc: (1,4)-(1,5) = "/" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- unescaped: "foo" ```
2025-01-04Implement LAMBDA NODE locationsydah
The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -e "-> (a, b) do foo end" @ ProgramNode (location: (1,0)-(1,20)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,20)) +-- body: (length: 1) +-- @ LambdaNode (location: (1,0)-(1,20)) +-- locals: [:a, :b] +-- operator_loc: (1,0)-(1,2) = "->" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- opening_loc: (1,10)-(1,12) = "do" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- closing_loc: (1,17)-(1,20) = "end" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ : (snip) ```
2025-01-04Implement YIELD NODE locationsydah
The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -e 'def foo; yield end' @ ProgramNode (location: (1,0)-(1,18)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,18)) +-- body: (length: 1) +-- @ DefNode (location: (1,0)-(1,18)) +-- name: :foo +-- name_loc: (1,4)-(1,7) = "foo" +-- receiver: nil +-- parameters: nil +-- body: | @ StatementsNode (location: (1,9)-(1,14)) | +-- body: (length: 1) | +-- @ YieldNode (location: (1,9)-(1,14)) | +-- keyword_loc: (1,9)-(1,14) = "yield" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +-- lparen_loc: nil ^^^^^^^^^^^^^^^^^^^ | +-- arguments: nil | +-- rparen_loc: nil ^^^^^^^^^^^^^^^^^^^ +-- locals: [] +-- def_keyword_loc: (1,0)-(1,3) = "def" +-- operator_loc: nil +-- lparen_loc: nil +-- rparen_loc: nil +-- equal_loc: nil +-- end_keyword_loc: (1,15)-(1,18) = "end" ```
2025-01-04Implement EVSTR NODE locationsydah
The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -e '"#{foo}"' @ ProgramNode (location: (1,0)-(1,8)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,8)) +-- body: (length: 1) +-- @ InterpolatedStringNode (location: (1,0)-(1,8)) +-- InterpolatedStringNodeFlags: nil +-- opening_loc: (1,0)-(1,1) = "\"" +-- parts: (length: 1) | +-- @ EmbeddedStatementsNode (location: (1,1)-(1,7)) | +-- opening_loc: (1,1)-(1,3) = "\#{" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +-- statements: | | @ StatementsNode (location: (1,3)-(1,6)) | | +-- body: (length: 1) | | +-- @ CallNode (location: (1,3)-(1,6)) | | +-- CallNodeFlags: variable_call, ignore_visibility | | +-- receiver: nil | | +-- call_operator_loc: nil | | +-- name: :foo | | +-- message_loc: (1,3)-(1,6) = "foo" | | +-- opening_loc: nil | | +-- arguments: nil | | +-- closing_loc: nil | | +-- block: nil | +-- closing_loc: (1,6)-(1,7) = "}" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- closing_loc: (1,7)-(1,8) = "\"" ```
2025-01-03Implement SUPER NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11712
2025-01-03Implement IF NODE locationsydah
The following Location information has been added This is the information required for parse.y to be a universal parser: ``` ❯ ruby --parser=prism --dump=parsetree -y -e "if a; elsif b; else end" @ ProgramNode (location: (1,0)-(1,23)) +-- locals: [] +-- statements: @ StatementsNode (location: (1,0)-(1,23)) +-- body: (length: 1) +-- @ IfNode (location: (1,0)-(1,23)) +-- if_keyword_loc: (1,0)-(1,2) = "if" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- predicate: | @ CallNode (location: (1,3)-(1,4)) | +-- CallNodeFlags: variable_call, ignore_visibility | +-- receiver: nil | +-- call_operator_loc: nil | +-- name: :a | +-- message_loc: (1,3)-(1,4) = "a" | +-- opening_loc: nil | +-- arguments: nil | +-- closing_loc: nil | +-- block: nil +-- then_keyword_loc: nil ^^^^^^^^^^^^^^^^^^^^^^^^^ +-- statements: nil +-- subsequent: | @ IfNode (location: (1,6)-(1,23)) | +-- if_keyword_loc: (1,6)-(1,11) = "elsif" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | +-- predicate: | | @ CallNode (location: (1,12)-(1,13)) | | +-- CallNodeFlags: variable_call, ignore_visibility | | +-- receiver: nil | | +-- call_operator_loc: nil | | +-- name: :b | | +-- message_loc: (1,12)-(1,13) = "b" | | +-- opening_loc: nil | | +-- arguments: nil | | +-- closing_loc: nil | | +-- block: nil | +-- then_keyword_loc: nil ^^^^^^^^^^^^^^^^^^^^^^^^^ | +-- statements: nil | +-- subsequent: | | @ ElseNode (location: (1,15)-(1,23)) | | +-- else_keyword_loc: (1,15)-(1,19) = "else" | | +-- statements: nil | | +-- end_keyword_loc: (1,20)-(1,23) = "end" | +-- end_keyword_loc: (1,20)-(1,23) = "end" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- end_keyword_loc: (1,20)-(1,23) = "end" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ```
2024-10-03Update ruby test for colon-style hash inspecttompng
Notes: Merged: https://github.com/ruby/ruby/pull/10924
2024-09-30Implement SPLAT NODE keyword locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11673
2024-09-28Implement OP_ASGN2 NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11702
2024-09-27Implement OP_ASGN1 NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11701
2024-09-25Implement BLOCK_PASS NODE keyword locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11663
2024-09-25Implement RETURN NODE keyword locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11589
2024-09-23Implement CASE3 NODE keyword locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11661
2024-09-23Implement CASE2 NODE keyword locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11661
2024-09-23Implement CASE NODE keyword locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11661
2024-09-17Prevent warnings for RubyVM::AbstractSyntaxTree.parse in test_ast.rbYusuke Endoh
2024-09-12[PRISM] Omit some TestAST tests when Prism is enabledKevin Newton
Notes: Merged: https://github.com/ruby/ruby/pull/11497
2024-09-11Implement BREAK, NEXT and REDO NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11584
2024-09-11Implement WHILE and UNTIL NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11579
2024-09-09Implement WHEN NODE locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11553
2024-09-05Implement AND/OR NODE operator locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11543
2024-09-04Implement VALIAS NODE keyword locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11531
2024-09-03Implement ALIAS NODE keyword locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11530
2024-09-03Implement UNDEF NODE keyword locationsydah
Notes: Merged: https://github.com/ruby/ruby/pull/11523
2024-08-25[Bug #20680] `ensure` block is always void contextNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11451
2024-07-23Implement UNLESS NODE keyword locationsyui-knk
Notes: Merged: https://github.com/ruby/ruby/pull/11227
2024-07-23[Feature #20624] Enhance `RubyVM::AbstractSyntaxTree::Node#locations`yui-knk
This commit introduce `RubyVM::AbstractSyntaxTree::Node#locations` method and `RubyVM::AbstractSyntaxTree::Location` class. Ruby AST node will hold multiple locations information. `RubyVM::AbstractSyntaxTree::Node#locations` provides a way to access these locations information. `RubyVM::AbstractSyntaxTree::Location` is a class which holds these location information: * `#first_lineno` * `#first_column` * `#last_lineno` * `#last_column` Notes: Merged: https://github.com/ruby/ruby/pull/11226
2024-07-18[PRISM] Refactor parser support into its own moduleKevin Newton
Notes: Merged: https://github.com/ruby/ruby/pull/11201