### Heredoc Content Starting with a Dot Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates a Ruby heredoc where the content begins with a dot, and its corresponding Tree-sitter parse tree, showing how the parser handles such specific content. ```ruby -> { select(<<-SQL) . SQL } ``` ```tree-sitter-s-expression (program (lambda (block (block_body (call (identifier) (argument_list (heredoc_beginning))) (heredoc_body (heredoc_content) (heredoc_end)))))) ``` -------------------------------- ### Define Installation Rules for tree-sitter-ruby Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/CMakeLists.txt This snippet defines the installation rules for the `tree-sitter-ruby` project. It configures and installs the pkg-config file, header files, and the compiled library, ensuring they are placed in standard system directories for easy integration with other projects. ```CMake configure_file(bindings/c/tree-sitter-ruby.pc.in "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-ruby.pc" @ONLY) include(GNUInstallDirs) install(FILES bindings/c/tree-sitter-ruby.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-ruby.pc" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") install(TARGETS tree-sitter-ruby LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") ``` -------------------------------- ### Tree-sitter Ruby AST for Method Calls with Splat/Hash Splat Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Provides various Tree-sitter Abstract Syntax Tree (AST) examples illustrating the parsing of Ruby method calls that include splat (`*args`) and hash splat (`**kwargs`) arguments, both with and without other arguments. ```Tree-sitter AST (splat_argument (call (identifier) (identifier))))) (call (identifier) (argument_list (hash_splat_argument (identifier)))) (call (identifier) (argument_list (hash_splat_argument (identifier)) (identifier))) (call (identifier) (argument_list (splat_argument))) (call (identifier) (argument_list (identifier) (splat_argument))) (call (identifier) (argument_list (hash_splat_argument))) (call (identifier) (argument_list (identifier) (hash_splat_argument)))) ``` -------------------------------- ### Advanced Ruby Method Calls with Splat and Double Splat Arguments and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Provides a comprehensive set of examples for Ruby method calls utilizing both single (`*`) and double (`**`) splat arguments, illustrating their diverse usage patterns and corresponding Tree-sitter parse tree structures. ```Ruby foo(*bar) foo(*[bar, baz].quoz) foo(x, *bar) foo(*bar.baz) foo(**baz) foo **bar, baz foo(*) foo(x, *) foo(**) foo x, ** ``` ```Tree-sitter Grammar (program (call (identifier) (argument_list (splat_argument (identifier)))) (call (identifier) (argument_list (splat_argument (call (array (identifier) (identifier)) (identifier))))) (call (identifier) (argument_list (identifier) (splat_argument (identifier)))) (call (identifier) (argument_list ``` -------------------------------- ### Ruby Basic Heredoc Literals Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Provides examples of various Ruby heredoc syntaxes, including standard, indented (`<<-`), squiggly (`<<~`), and quoted heredocs, demonstrating their structure and Tree-sitter parse tree. ```Ruby < $_ $0 $* $$ $? $: $" $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $0 $10 $stdin $stdout $stderr $DEBUG $FILENAME $LOAD_PATH $VERBOSE ``` ```Tree-sitter (program (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable) (global_variable)) ``` -------------------------------- ### Ruby Unbalanced Percent `w` String Array Delimiters Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows an example of a `%w` string array using unbalanced delimiters (`/`), and its Tree-sitter parse, demonstrating parser robustness. ```ruby %w/one two/ ``` ```tree-sitter-s-expression (program (string_array (bare_string (string_content)) (bare_string (string_content)))) ``` -------------------------------- ### Ruby Unbalanced Percent `i` Symbol Array Delimiters Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows an example of a `%i` symbol array using unbalanced delimiters (`/`), and its Tree-sitter parse, demonstrating parser robustness. ```ruby %i/one two/ ``` ```tree-sitter-s-expression (program (symbol_array (bare_symbol (string_content)) (bare_symbol (string_content)))) ``` -------------------------------- ### Ruby Array Method Call with Block Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows an example of calling a method on an array object with a block, demonstrating object-oriented array usage and its Tree-sitter parse, including the structure of the block. ```ruby [1, 2].any? { |i| i > 1 } ``` ```tree-sitter-s-expression (program (call receiver: (array (integer) (integer)) method: (identifier) block: (block parameters: (block_parameters (identifier)) body: (block_body (binary left: (identifier) right: (integer)))))) ``` -------------------------------- ### Ruby Integer Literals and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Simple example of an integer literal in Ruby and its parsing as an `integer` node by Tree-sitter. ```Ruby 1234 ``` ```Tree-sitter (program (integer)) ``` -------------------------------- ### Ruby Method Calls with Curly Brace Blocks Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates Ruby method calls using curly brace (`{}`) blocks, showing examples with parameters, nested calls, and multiple arguments. The AST highlights the structure of these inline blocks. ```Ruby foo { |i| foo } foo items.any? { |i| i > 0 } foo(bar, baz) { quux } ``` ```Tree-sitter AST (program (call method: (identifier) block: (block parameters: (block_parameters (identifier)) body: (block_body (identifier)))) (call method: (identifier) arguments: (argument_list (call receiver: (identifier) method: (identifier) block: (block parameters: (block_parameters (identifier)) body: (block_body (binary left: (identifier) right: (integer))))))) (call method: (identifier) arguments: (argument_list (identifier) (identifier)) block: (block body: (block_body (identifier))))) ``` -------------------------------- ### Ruby Octal Integers with Prefix and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Examples of Ruby octal integers using `0` or `0o` prefixes, parsed as `integer` nodes by Tree-sitter. ```Ruby 01234567 0o1234567 ``` ```Tree-sitter (program (integer) (integer)) ``` -------------------------------- ### Ruby Bitwise AND Operator Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the bitwise AND operator in Ruby, showing its basic usage and the corresponding Tree-sitter parse tree structure for a binary expression. ```Ruby a & b ``` ```Tree-sitter Parse Tree (program (binary (identifier) (identifier))) ``` -------------------------------- ### Un-terminated Heredocs Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows an example of an un-terminated Ruby heredoc and its Tree-sitter parse, highlighting how the parser represents incomplete or malformed constructs. ```ruby <<-ONE ``` ```tree-sitter-s-expression (program (heredoc_beginning) (heredoc_body (heredoc_content) (heredoc_end))) ``` -------------------------------- ### Ruby Operator Combinations: Minus, Call, Exponential, Range Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Comprehensive examples demonstrating various forms of the minus operator (binary and unary), method calls, exponential operations, and range expressions in Ruby, highlighting how Tree-sitter parses these complex combinations. ```Ruby a - 1 a-1 a -1 a- 1 (-1.foo) a - b a-b a -b a- b (-b.foo) -2**10 -x**10 1..-1 1 .. -1 1.. -1 1 ..-1 ``` ```Tree-sitter Parse Tree (program (binary left: (identifier) right: (integer)) (binary left: (identifier) right: (integer)) (call method: (identifier) arguments: (argument_list (unary operand: (integer)))) (binary left: (identifier) right: (integer)) (parenthesized_statements (call receiver: (unary operand: (integer)) method: (identifier))) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (call method: (identifier) arguments: (argument_list (unary operand: (identifier)))) (binary left: (identifier) right: (identifier)) (parenthesized_statements (unary operand: (call receiver: (identifier) method: (identifier)))) (unary operand: (binary left: (integer) right: (integer))) (unary operand: (binary left: (identifier) right: (integer))) (range begin: (integer) end: (unary operand: (integer))) (range begin: (integer) end: (unary operand: (integer))) (range begin: (integer) end: (unary operand: (integer))) (range begin: (integer) end: (unary operand: (integer)))) ``` -------------------------------- ### Bitwise XOR Operator in Ruby Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates the Ruby bitwise XOR operator ('^') between two identifiers. The provided input is truncated, showing only the start of the parse tree. ```Ruby a ^ b ``` ```Tree-sitter (program (binary ``` -------------------------------- ### Ruby Percent `w` String Array Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates the `%w()` syntax for creating an array of strings in Ruby, and its Tree-sitter parse, showing a common use case for this shorthand. ```ruby %w(word word) ``` ```tree-sitter-s-expression (program (string_array (bare_string (string_content)) (bare_string (string_content)))) ``` -------------------------------- ### Ruby Method Call with Capitalized Name Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows a Ruby method call where the method name starts with a capital letter, which is typically interpreted as a constant. The Tree-sitter AST reflects this by parsing `GET` as a `constant` node. ```Ruby request.GET ``` ```Tree-sitter AST (program (call (identifier) (constant))) ``` -------------------------------- ### Ruby Decimal Integers with Prefix and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Examples of Ruby decimal integers explicitly defined with `0d` or `0D` prefixes, parsed as `integer` nodes by Tree-sitter. ```Ruby 0d1_234 0D1_234 ``` ```Tree-sitter (program (integer) (integer)) ``` -------------------------------- ### Ruby Heredoc in Method Call with Dot Content Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates a Ruby heredoc used as an argument to a method call, where the heredoc content starts with a dot, and its Tree-sitter parse tree. ```Ruby def foo select(<<-SQL) . SQL end ``` ```Tree-sitter (program (method (identifier) (body_statement (call (identifier) (argument_list (heredoc_beginning))) (heredoc_body (heredoc_content) (heredoc_end))))) ``` -------------------------------- ### Ruby Multi-line Method Call Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates a Ruby method call with arguments spread across multiple lines, showing how Tree-sitter correctly groups them into a single argument list. ```Ruby foo a, b, c ``` ```Tree-sitter Parse Tree (program (call method: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))) ``` -------------------------------- ### Ruby Binary Integers with Prefix and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates Ruby binary integers using `0b` or `0B` prefixes, parsed as `integer` nodes by Tree-sitter. ```Ruby 0b1_0 0B1_0 ``` ```Tree-sitter (program (integer) (integer)) ``` -------------------------------- ### Ruby For Loop Examples Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/control-flow.txt Presents various `for` loop constructs in Ruby, including simple iteration, iteration with multiple assignment patterns (e.g., `x,`, `x, *y`), and destructuring assignments. Examples include loops with and without the `do` keyword, alongside their Tree-sitter parse tree representations. ```Ruby for x in y do f end for x, in y f end for x, *y in z do f end for (k, v) in y do f end for x in y f end ``` ```Tree-sitter (program (for pattern: (identifier) value: (in (identifier)) body: (do (identifier))) (for pattern: (left_assignment_list (identifier)) value: (in (identifier)) body: (do (identifier))) (for pattern: (left_assignment_list (identifier) (rest_assignment (identifier))) value: (in (identifier)) body: (do (identifier))) (for pattern: (left_assignment_list (destructured_left_assignment (identifier) (identifier))) value: (in (identifier)) body: (do (identifier)))) (program (for pattern: (identifier) value: (in (identifier)) body: (do (identifier)))) ``` -------------------------------- ### Ruby Until Modifier Example Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/statements.txt Presents the 'until' keyword as a statement modifier in Ruby, where the preceding expression is executed repeatedly until the condition becomes true. Displays a straightforward example. ```Ruby foo until bar ``` ```Tree-sitter Grammar (program (until_modifier (identifier) (identifier))) ``` -------------------------------- ### Ruby Float Literals and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Examples of Ruby floating-point numbers, including those with exponents and underscores, and their parsing as `float` nodes by Tree-sitter. ```Ruby 1.234_5e678_90 1E30 1.0e+6 1.0e-6 ``` ```Tree-sitter (program (float) (float) (float) (float)) ``` -------------------------------- ### Ruby Conditional Modifier Examples Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/statements.txt Demonstrates the use of 'if' as a statement modifier in Ruby, showing how it affects the execution of the preceding expression based on a condition. Includes examples with simple identifiers, return statements, and method calls. ```Ruby foo if bar return if false return true if foo bar return nil if foo ``` ```Tree-sitter Grammar (program (if_modifier (identifier) (identifier)) (if_modifier (return) (false)) (if_modifier (return (argument_list (true))) (call (identifier) (argument_list (identifier)))) (if_modifier (return (argument_list (nil))) (identifier))) ``` -------------------------------- ### Ruby Hash with Keyword and String Keys and Tree-sitter Parse Tree Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows various forms of Ruby hash definitions using keyword (symbol) keys and string keys, including examples with line breaks and missing values. The Tree-sitter parse tree illustrates how these different key types and structures are represented. ```Ruby { a: 1, b: 2, "c": 3 } {a: 1, B:2, "c":3 } { a:, B: } ``` ```Tree-sitter (program (hash (pair (hash_key_symbol) (integer)) (pair (hash_key_symbol) (integer)) (pair (string (string_content)) (integer))) (hash (pair (hash_key_symbol) (integer)) (pair (hash_key_symbol) (integer)) (pair (string (string_content)) (integer))) (hash (pair (hash_key_symbol)) (pair (hash_key_symbol)))) ``` -------------------------------- ### Ruby Percent Symbols with Unbalanced Delimiters and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Examples of Ruby percent symbols using unbalanced delimiters and how Tree-sitter parses them as `delimited_symbol` nodes. ```Ruby %s/a/ %s\a\ %s#a# ``` ```Tree-sitter (program (delimited_symbol (string_content)) (delimited_symbol (string_content)) (delimited_symbol (string_content))) ``` -------------------------------- ### Ruby Method Call with Positional and Keyword Hash Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates Ruby method calls using a positional string argument combined with a keyword argument whose value is a hash, including empty and populated hashes. ```Ruby render "foo/bars/show", locals: { } render "foo/bars/show", locals: { display_text: dt, safe_text: "hello" } ``` ```Tree-sitter (program (call (identifier) (argument_list (string (string_content)) (pair (hash_key_symbol) (hash)))) (call (identifier) (argument_list (string (string_content)) (pair (hash_key_symbol) (hash (pair (hash_key_symbol) (identifier)) (pair (hash_key_symbol) (string (string_content)))))))) ``` -------------------------------- ### Ruby Undef Statement Examples Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/statements.txt Illustrates the 'undef' keyword in Ruby, which removes a method definition from a class or module. Examples show undefining methods by symbol, identifier, operator, and multiple methods at once. ```Ruby undef :foo undef foo undef + undef :foo, :bar ``` ```Tree-sitter Grammar (program (undef (simple_symbol)) (undef (identifier)) (undef (operator)) (undef (simple_symbol) (simple_symbol))) ``` -------------------------------- ### Ruby While Modifier Example Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/statements.txt Illustrates the 'while' keyword used as a statement modifier in Ruby, where the preceding expression is executed repeatedly as long as the condition remains true. Shows a basic example of its structure. ```Ruby foo while bar ``` ```Tree-sitter Grammar (program (while_modifier body: (identifier) condition: (identifier))) ``` -------------------------------- ### Ruby Alias Statement Examples Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/statements.txt Demonstrates the 'alias' keyword in Ruby, used to create an alternative name for a method, global variable, or operator. Examples include aliasing symbols, identifiers, global variables, and operators. ```Ruby alias :foo :bar alias foo bar alias $FOO $& alias foo + ``` ```Tree-sitter Grammar (program (alias (simple_symbol) (simple_symbol)) (alias (identifier) (identifier)) (alias (global_variable) (global_variable)) (alias (identifier) (operator))) ``` -------------------------------- ### Ruby While Loop Examples Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/control-flow.txt Demonstrates various forms of the `while` loop in Ruby, including empty loops, loops without the `do` keyword, and loops with a body. Each example is paired with its Tree-sitter parse tree representation, highlighting the structural components like condition and body. ```Ruby while foo do end while foo end while foo do bar end ``` ```Tree-sitter (program (while condition: (identifier) body: (do))) (program (while condition: (identifier) body: (do))) (program (while condition: (identifier) body: (do (identifier)))) ``` -------------------------------- ### Ruby Exponential Operator Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the exponential operator ('**') in Ruby, showing its usage and the corresponding Tree-sitter parse tree as a binary expression. ```Ruby a ** b ``` ```Tree-sitter Parse Tree (program (binary (identifier) (identifier))) ``` -------------------------------- ### Ruby Element Reference with Block Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows how to use element references with associated blocks in Ruby, demonstrating both curly brace and `do...end` block syntaxes. ```Ruby foo[:bar] { |baz| baz } foo[:bar] do |baz| baz end ``` ```Tree-sitter (program (element_reference (identifier) (simple_symbol) (block (block_parameters (identifier)) (block_body (identifier)))) (element_reference (identifier) (simple_symbol) (do_block (block_parameters (identifier)) (body_statement (identifier))))) ``` -------------------------------- ### Ruby Nested Module, Class, and Method Definitions with Parse Tree Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Comprehensive example of a Ruby module containing a class with inheritance, mixins, attribute readers, instance methods, and singleton methods, along with its detailed Tree-sitter parse tree. ```Ruby module A class B < C include D::E.f.g attr_reader :h # i def j k end def self.l end end end ``` ```Tree-sitter Parse Tree (program (module (constant) (body_statement (class (constant) (superclass (constant)) (body_statement (call (identifier) (argument_list (call (call (scope_resolution (constant) (constant)) (identifier)) (identifier)))) (call (identifier) (argument_list (simple_symbol))) (comment) (method (identifier) (body_statement (identifier))) (singleton_method (self) (identifier))))))) ``` -------------------------------- ### Ruby Logical AND/OR Associativity Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the associativity rules between `or` and `and` operators in Ruby, showing how expressions are grouped, and its Tree-sitter parse tree. ```Ruby a or b and c ``` ```Tree-sitter S-expression (program (binary (binary (identifier) (identifier)) (identifier))) ``` -------------------------------- ### Ruby Percent `i` Symbol Array Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates the `%i()` syntax for creating an array of symbols in Ruby, and its Tree-sitter parse, showing a common use case for this shorthand. ```ruby %i(word word) ``` ```tree-sitter-s-expression (program (symbol_array (bare_symbol (string_content)) (bare_symbol (string_content)))) ``` -------------------------------- ### Ruby Yield with Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the `yield` keyword used with single or multiple arguments, and with arguments enclosed in parentheses, and their Tree-sitter parse tree representations. ```Ruby yield foo yield foo, bar yield(baz) ``` ```Tree-sitter S-expression (program (yield (argument_list (identifier))) (yield (argument_list (identifier) (identifier))) (yield (argument_list (identifier)))) ``` -------------------------------- ### Ruby Empty `BEGIN` Block and Parse Tree Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Illustrates an empty `BEGIN` block in Ruby, which executes code before the program starts, and its Tree-sitter parse tree. ```Ruby BEGIN { } ``` ```Tree-sitter Parse Tree (program (begin_block)) ``` -------------------------------- ### Ruby Method Call with Multi-line Keyword Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates Ruby method calls where keyword arguments span multiple lines, including chained string literals and nested hash values, demonstrating complex argument parsing. ```Ruby render :show_details, 5, description: "Some long " \ "piece of text.", dark_mode: false render "/foo/bar", params: { id: 3, title: "Hello world" }, headers: { Accept: "text/html" } render "/foo/bar", params: { id: 3, title: "Hello world" } ``` ```Tree-sitter (program (call method: (identifier) arguments: (argument_list (simple_symbol) (integer) (pair key: (hash_key_symbol) value: (chained_string (string (string_content)) (string (string_content))))) (pair key: (hash_key_symbol) value: (false)))) (call method: (identifier) arguments: (argument_list (string (string_content)) (pair key: (hash_key_symbol) value: (hash (pair key: (hash_key_symbol) value: (integer)) (pair key: (hash_key_symbol) value: (string (string_content))))) (pair key: (hash_key_symbol) value: (hash (pair)))))) ``` -------------------------------- ### Ruby Method Calls with Lambda and Do Block Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates the Tree-sitter parse tree for a Ruby method call that includes both a lambda argument and a `do` block, demonstrating their combined structural representation. ```Ruby foo :bar, -> (a) { 1 } do end ``` ```Tree-sitter Grammar (program (call (identifier) (argument_list (simple_symbol) (lambda (lambda_parameters (identifier)) (block (block_body (integer))))) (do_block))) ``` -------------------------------- ### Ruby Logical OR Operator Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates the `or` keyword for logical disjunction, and its representation as a binary operation in the Tree-sitter parse tree. ```Ruby foo or bar ``` ```Tree-sitter S-expression (program (binary (identifier) (identifier))) ``` -------------------------------- ### Ruby Chained String Literals Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows examples of Ruby string chaining, where multiple string literals are implicitly concatenated, and their representation in the Tree-sitter parse tree. ```Ruby %q(a) "b" "c" "d" "e" ``` ```Tree-sitter (program (chained_string (string (string_content)) (string (string_content)) (string (string_content))) (chained_string (string (string_content)) (string (string_content)))) ``` -------------------------------- ### Ruby Method Call with Array and Block Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates method calls that combine an array argument with a block, showcasing both curly brace and `do...end` block styles. ```Ruby fun [0] { |x| x } fun [0] do puts 1 end ``` ```Tree-sitter (program (call (identifier) (argument_list (array (integer))) (block (block_parameters (identifier)) (block_body (identifier)))) (call (identifier) (argument_list (array (integer))) (do_block (body_statement (call (identifier) (argument_list (integer))))))) ``` -------------------------------- ### Ruby Element Assignment Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows how to assign a value to an element accessed via an element reference, and its representation in the Tree-sitter parse tree. ```Ruby foo[bar] = 1 ``` ```Tree-sitter S-expression (program (assignment left: (element_reference object: (identifier) (identifier)) right: (integer))) ``` -------------------------------- ### Ruby Scope Resolution Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates different ways to resolve scope in Ruby, including class-level and global scope, and their corresponding Tree-sitter parse tree structures. ```Ruby Foo::Bar ::Bar puts ::Foo::Bar ``` ```Tree-sitter S-expression (program (scope_resolution scope: (constant) name: (constant)) (scope_resolution name: (constant)) (call method: (identifier) arguments: (argument_list (scope_resolution scope: (scope_resolution name: (constant)) name: (constant))))) ``` -------------------------------- ### Ruby Percent R Regular Expression with Delimiters and Tree-sitter Parse Tree Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows examples of Ruby's `%r` syntax for regular expressions using different delimiters like `/`, `\`, and `#`. The Tree-sitter parse tree represents these as `regex` nodes. ```Ruby %r/a/ %r\a\ %r#a# ``` ```Tree-sitter (program (regex ``` -------------------------------- ### Ruby Method Call Syntax Variations Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Examples of various Ruby method call syntaxes, including calls with and without parentheses, arguments, bang methods, and method calls as part of 'if' modifiers, along with their Tree-sitter parse tree structures. ```Ruby foo foo() print "hello" print("hello") exit! exit!() include? include?("hello") include? "hello" exit! if done exit!() if done ``` ```Tree-sitter Parse Tree (program (identifier) (call method: (identifier) arguments: (argument_list)) (call method: (identifier) arguments: (argument_list (string (string_content)))) (call method: (identifier) arguments: (argument_list (string (string_content)))) (call method: (identifier)) (call method: (identifier) arguments: (argument_list)) (call method: (identifier)) (call method: (identifier) arguments: (argument_list (string (string_content)))) (call method: (identifier) arguments: (argument_list (string (string_content)))) (if_modifier body: (call method: (identifier)) condition: (identifier)) (if_modifier body: (call method: (identifier) arguments: (argument_list)) condition: (identifier))) ``` -------------------------------- ### Ruby Heredoc with Suffix Dot Method Continuation Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates a Ruby heredoc followed by a method call on the same line, showing how Tree-sitter parses the chained method calls and the heredoc content. ```Ruby joins(<<~SQL). `foo` SQL where("a") ``` ```Tree-sitter (program (call receiver: (call method: (identifier) arguments: (argument_list (heredoc_beginning))) (heredoc_body (heredoc_content) (heredoc_end)) method: (identifier) arguments: (argument_list (string (string_content))))) ``` -------------------------------- ### Ruby Single Quoted Symbols and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows examples of Ruby symbols defined with single quotes, including empty and interpolated forms, and their `delimited_symbol` Tree-sitter representation. ```Ruby :'' :'foo bar' :'#{' ``` ```Tree-sitter (program (delimited_symbol) (delimited_symbol (string_content)) (delimited_symbol (string_content))) ``` -------------------------------- ### Ruby Element Reference and Method Calls with Array Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates various ways to use array arguments with method calls and element references in Ruby, including empty arrays, arrays with single elements, and direct element access. ```Ruby foo [] foo [1] foo[1] ``` ```Tree-sitter (program (call method: (identifier) arguments: (argument_list (array))) (call method: (identifier) arguments: (argument_list (array (integer)))) (element_reference object: (identifier) (integer))) ``` -------------------------------- ### Ruby Logical AND Operator Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows the `and` keyword for logical conjunction, and its representation as a binary operation in the Tree-sitter parse tree. ```Ruby foo and bar ``` ```Tree-sitter S-expression (program (binary (identifier) (identifier))) ``` -------------------------------- ### Ruby Operator Symbols and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates common Ruby operator symbols and how they are parsed as `simple_symbol` nodes by Tree-sitter. ```Ruby :+ :- :+@ :-@ :[] :[]= :& :! :` :^ :| :~ :/ :% :* :** :== :=== :=~ :> :>= :>> :< :<= :<< :<=> :!= :!~ ``` ```Tree-sitter (program (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol)) ``` -------------------------------- ### Ruby Method Calls with Lambda Arguments and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows how Tree-sitter parses Ruby method calls where a lambda is passed as an argument, including lambdas with simple returns and those containing method calls. ```Ruby foo :bar, -> (a) { 1 } foo :bar, -> (a) { where(:c => b) } ``` ```Tree-sitter Grammar (program (call (identifier) (argument_list (simple_symbol) (lambda (lambda_parameters (identifier)) (block (block_body (integer)))))) (call (identifier) (argument_list (simple_symbol) (lambda (lambda_parameters (identifier)) (block (block_body (call (identifier) (argument_list (pair (simple_symbol) (identifier)))))))))) ``` -------------------------------- ### Ruby Multiple Heredocs with Chained Method Calls Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates the use of multiple heredocs chained with method calls on a single line, and how Tree-sitter captures the nested call structure and multiple heredoc bodies. ```Ruby joins(<<~SQL).where(<<~SQL). `one` SQL `two` SQL group("b") ``` ```Tree-sitter (program (call receiver: (call receiver: (call method: (identifier) arguments: (argument_list (heredoc_beginning))) method: (identifier) arguments: (argument_list (heredoc_beginning))) (heredoc_body (heredoc_content) (heredoc_end)) (heredoc_body (heredoc_content) (heredoc_end)) method: (identifier) arguments: (argument_list (string (string_content))))) ``` -------------------------------- ### Parse Tree for Regex as Method Parameter Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates how Tree-sitter parses a regular expression when it is passed as an argument to a method call. ```Ruby foo /bar/ ``` ```Tree-sitter Ruby Parse Tree (program (call (identifier) (argument_list (regex (string_content))))) ``` -------------------------------- ### Ruby Empty Percent `i` Symbol Array Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates the `%i()` syntax for creating an empty array of symbols in Ruby, and its Tree-sitter parse, showing the shorthand for symbol arrays. ```ruby %i() ``` ```tree-sitter-s-expression (program (symbol_array)) ``` -------------------------------- ### Ruby Multiplicative Operator Variations Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Examples of the multiplication operator ('*') in Ruby, demonstrating various spacing conventions and their consistent parsing as binary expressions by Tree-sitter, along with an unrelated call node present in the provided parse tree. ```Ruby a * b a*b a *b a* b ``` ```Tree-sitter Parse Tree (program (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (call method: (identifier) arguments: (argument_list (splat_argument (identifier)))) (binary left: (identifier) right: (identifier))) ``` -------------------------------- ### Ruby Simple Assignment Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows basic variable assignments, including splat arguments and assignments to constants like `FALSE`, `TRUE`, and `NIL`, and their Tree-sitter parse tree structures. ```Ruby x = y x = *args FALSE = "false" TRUE = "true" NIL = "nil" ``` ```Tree-sitter S-expression (program (assignment (identifier) (identifier)) (assignment (identifier) (splat_argument (identifier))) (assignment (constant) (string (string_content))) (assignment (constant) (string (string_content))) (assignment (constant) (string (string_content)))) ``` -------------------------------- ### Ruby Hexadecimal Integers with Prefix and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates Ruby hexadecimal integers using the `0x` prefix, parsed as `integer` nodes by Tree-sitter. ```Ruby 0xa_bcd_ef0_123_456_789 ``` ```Tree-sitter (program (integer)) ``` -------------------------------- ### Ruby Empty Percent `w` String Array Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates the `%w()` syntax for creating an empty array of strings in Ruby, and its Tree-sitter parse, highlighting this shorthand for string arrays. ```ruby %w() ``` ```tree-sitter-s-expression (program (string_array)) ``` -------------------------------- ### Parse Tree for Lambda and Proc Assignments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows how Tree-sitter parses the assignment of Proc objects and lambda expressions to variables in Ruby. ```Ruby proc = Proc.new lambda = lambda {} proc = proc {} ``` ```Tree-sitter Ruby Parse Tree (program (assignment (identifier) (call (constant) (identifier))) (assignment (identifier) (call (identifier) (block))) (assignment (identifier) (call (identifier) (block)))) ``` -------------------------------- ### Ruby Empty Module Definitions and Parse Trees Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Examples of defining empty modules in Ruby, including top-level and nested modules, and their Tree-sitter parse tree outputs. ```Ruby module Foo end module Foo::Bar end ``` ```Tree-sitter Parse Tree (program (module (constant)) (module (scope_resolution (constant) (constant)))) ``` -------------------------------- ### Ruby `defined?` Keyword Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates various uses of the `defined?` keyword to check if a variable, method, or constant is defined, and its Tree-sitter parse tree representation. ```Ruby defined? foo defined? Foo.bar defined?(foo) defined?($foo) defined?(@foo) defined?(@äö).should be_true ``` ```Tree-sitter S-expression (program (unary operand: (identifier)) (unary operand: (call receiver: (constant) method: (identifier))) (unary operand: (parenthesized_statements (identifier))) (unary operand: (parenthesized_statements (global_variable))) (unary operand: (parenthesized_statements (instance_variable))) (call receiver: (unary operand: (parenthesized_statements (instance_variable))) method: (identifier) arguments: (argument_list (identifier)))) ``` -------------------------------- ### Parse Tree for Multiline Regex Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the Tree-sitter parse tree for a regular expression that spans multiple lines. ```Ruby / a b/ ``` ```Tree-sitter Ruby Parse Tree (program (regex)) ``` -------------------------------- ### Ruby Integer Literals with Underscores and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows how Ruby integers can include underscores for readability, and how Tree-sitter still parses them as a single `integer` node. ```Ruby 1_234 ``` ```Tree-sitter (program (integer)) ``` -------------------------------- ### Parse Tree for Basic Division Operations Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates the Tree-sitter parse tree for basic division operations in Ruby, including integer and variable division, and multi-line expressions. ```Ruby 10 / 5 x / y x / 5 ``` ```Tree-sitter Ruby Parse Tree (program (binary (integer) (integer)) (binary (identifier) (identifier)) (binary (identifier) (integer))) ``` -------------------------------- ### Ruby Element Reference with String Literal Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates accessing an element using a string literal as the key or index, and its corresponding Tree-sitter parse tree structure. ```Ruby foo["bar"] ``` ```Tree-sitter S-expression (program (element_reference (identifier) (string (string_content)))) ``` -------------------------------- ### Ruby Empty Hash Literal Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates the syntax for an empty hash literal in Ruby and its corresponding Tree-sitter parse, showing the simplest hash structure. ```ruby {} ``` ```tree-sitter-s-expression (program (hash)) ``` -------------------------------- ### Ruby String Formatting with Newline Continuation Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates Ruby's string formatting using the `%` operator, where the format string and arguments are split across lines, and its Tree-sitter parse tree. ```Ruby foo("%s '%s' " % [a, b]) ``` ```Tree-sitter (program (call (identifier) (argument_list (binary (string (string_content)) (array (identifier) (identifier)))))) ``` -------------------------------- ### Ruby Percent `W` String Array with Interpolations Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates the `%W()` syntax for creating an array of strings that allows interpolation in Ruby, and its Tree-sitter parse, highlighting the difference from `%w()`. ```ruby %W(a #{b} c) ``` ```tree-sitter-s-expression (program (string_array (bare_string (string_content)) (bare_string (interpolation (identifier))) (bare_string (string_content)))) ``` -------------------------------- ### Parse Tree for Lambda Expression with Multiple Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the Tree-sitter parse tree for a Ruby lambda expression that accepts multiple arguments and has a multi-line body. ```Ruby lambda { |a, b, c| 1 2 } ``` ```Tree-sitter Ruby Parse Tree (program (call (identifier) (block (block_parameters (identifier) (identifier) (identifier)) (block_body (integer) (integer))))) ``` -------------------------------- ### Ruby Element Reference with Symbol Literal Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates accessing an element using a symbol literal as the key or index, and its corresponding Tree-sitter parse tree structure. ```Ruby foo[:bar] ``` ```Tree-sitter S-expression (program (element_reference (identifier) (simple_symbol))) ``` -------------------------------- ### Ruby Empty Statement Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates an empty statement represented by a semicolon, and its corresponding Tree-sitter parse tree structure. ```Ruby ; ``` ```Tree-sitter S-expression (program (empty_statement)) ``` -------------------------------- ### Comparison Operators in Ruby Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows standard comparison operators ('<', '<=', '>', '>=') between two identifiers. The parse tree consistently identifies these as 'binary' operations. ```Ruby a < b a <= b a > b a >= b ``` ```Tree-sitter (program (binary (identifier) (identifier)) (binary (identifier) (identifier)) (binary (identifier) (identifier)) (binary (identifier) (identifier))) ``` -------------------------------- ### Ruby Backticks Subshell Execution Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates the use of backticks in Ruby for executing subshell commands and capturing their output, along with its Tree-sitter parse. ```ruby `/usr/bin/env test blah blah` ``` ```tree-sitter-s-expression (program (subshell (string_content))) ``` -------------------------------- ### Ruby Additive Operator Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows the addition operator ('+') in Ruby and its corresponding Tree-sitter parse tree, identifying it as a binary expression. ```Ruby a + b ``` ```Tree-sitter Parse Tree (program (binary (identifier) (identifier))) ``` -------------------------------- ### Ruby Method with Keyword Parameters and Tree-sitter Grammar Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Illustrates the Tree-sitter grammar for Ruby methods using keyword parameters, including optional and required keyword arguments. ```Ruby def foo(bar: nil, baz:) end ``` ```Tree-sitter S-expression (program (method (identifier) (method_parameters (keyword_parameter (identifier) (nil)) (keyword_parameter (identifier))))) ``` -------------------------------- ### Ruby Percent Symbols with Balanced Delimiters and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows Ruby percent symbols with various balanced delimiters and their parsing into `delimited_symbol` nodes by Tree-sitter. ```Ruby %s{a{b}c} %sc> %s(a(b)c) %s[a[b]c] ``` ```Tree-sitter (program (delimited_symbol (string_content)) (delimited_symbol (string_content)) (delimited_symbol (string_content)) (delimited_symbol (string_content))) ``` -------------------------------- ### Ruby %Q String with Balanced Delimiters Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates Ruby's `%Q` string literal with various balanced delimiters, showing how nested delimiters are handled and their Tree-sitter parse tree. ```Ruby %Qc> %Q{a{b}c} %Q[a[b]c] %Q(a(b)c) ``` ```Tree-sitter (program (string (string_content)) (string (string_content)) (string (string_content)) (string (string_content))) ``` -------------------------------- ### Ruby Percent `I` Symbol Array with Interpolations Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates the `%I()` syntax for creating an array of symbols that allows interpolation in Ruby, and its Tree-sitter parse, highlighting the difference from `%i()`. ```ruby %I(a #{b} c) ``` ```tree-sitter-s-expression (program (symbol_array (bare_symbol (string_content)) (bare_symbol (interpolation (identifier))) (bare_symbol (string_content)))) ``` -------------------------------- ### Ruby `BEGIN` Block with Code and Parse Tree Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Demonstrates a `BEGIN` block containing code, showing its execution order relative to other program statements, and its Tree-sitter parse tree. ```Ruby baz BEGIN { foo } bar ``` ```Tree-sitter Parse Tree (program (identifier) (begin_block (identifier)) (identifier)) ``` -------------------------------- ### Parse Tree for Lambda Expression with Keyword Argument Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the Tree-sitter parse tree for a Ruby lambda expression that includes a keyword argument with a default value. ```Ruby lambda { |a, b: nil| 1 } ``` ```Tree-sitter Ruby Parse Tree (program (call (identifier) (block (block_parameters (identifier) (keyword_parameter (identifier) (nil))) (block_body (integer))))) ``` -------------------------------- ### Ruby Unless Modifier Example Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/statements.txt Shows the 'unless' keyword used as a statement modifier in Ruby, executing the preceding expression only if the condition is false. Provides a simple demonstration of its usage. ```Ruby foo unless bar ``` ```Tree-sitter Grammar (program (unless_modifier body: (identifier) condition: (identifier))) ``` -------------------------------- ### Parse Tree for Various Lambda Expressions Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates the Tree-sitter parse tree for different forms of Ruby lambda expressions, including those with simple bodies, block arguments, and nested lambdas. ```Ruby lambda { foo } lambda(&block) { foo } lambda(&lambda{}) ``` ```Tree-sitter Ruby Parse Tree (program (call (identifier) (block (block_body (identifier)))) (call (identifier) (argument_list (block_argument (identifier))) (block (block_body (identifier)))) (call (identifier) (argument_list (block_argument (call (identifier) (block)))))) ``` -------------------------------- ### Ruby Lambda Literals with Various Argument Forms Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Covers the parsing of Ruby lambda literals demonstrating different ways to define arguments, including single arguments, arguments in parentheses, splat parameters, keyword parameters, and multiple positional arguments. ```Ruby -> foo { 1 } -> (foo) { 1 } -> *foo { 1 } -> foo: 1 { 2 } -> foo, bar { 2 } ``` ```Tree-sitter S-expression (program (lambda (lambda_parameters (identifier)) (block (block_body (integer)))) (lambda (lambda_parameters (identifier)) (block (block_body (integer)))) (lambda (lambda_parameters (splat_parameter (identifier))) (block (block_body (integer)))) (lambda (lambda_parameters (keyword_parameter (identifier) (integer))) (block (block_body (integer)))) (lambda (lambda_parameters (identifier) (identifier)) (block (block_body (integer))))) ``` -------------------------------- ### Ruby Module with Method Definition and Parse Tree Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Demonstrates a Ruby module containing a method definition and its corresponding Tree-sitter parse tree. ```Ruby module Foo def bar end end ``` ```Tree-sitter Parse Tree (program (module (constant) (body_statement (method (identifier))))) ``` -------------------------------- ### Ruby Empty Array Literal Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates the syntax for an empty array literal in Ruby and its corresponding Tree-sitter parse, showing the simplest array structure. ```ruby [] ``` ```tree-sitter-s-expression (program (array)) ``` -------------------------------- ### Parse Tree for Backslash-Newline Line Continuation Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates how Tree-sitter handles backslash-newline sequences for line continuation in Ruby code, including within strings. ```Ruby foo \ a, b "abc \ de" foo \ "abc" ``` ```Tree-sitter Ruby Parse Tree (program (call (identifier) (argument_list (identifier) (identifier))) (string (string_content) (escape_sequence) (string_content)) (call (identifier) (argument_list (string (string_content))))) ``` -------------------------------- ### Parse Tree for Empty Lambda Expression Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the Tree-sitter parse tree structure for an empty Ruby lambda expression, showing the 'call' and 'block' nodes. ```Ruby lambda {} ``` ```Tree-sitter Ruby Parse Tree (program (call (identifier) (block))) ``` -------------------------------- ### Ruby Binary Operations with Precedence Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates how Ruby handles operator precedence in binary expressions like '2+2*2', showing the nested structure in the Tree-sitter parse tree. ```Ruby 2+2*2 ``` ```Tree-sitter Parse Tree (program (binary (integer) (binary (integer) (integer)))) ``` -------------------------------- ### Ruby Multiple Assignment Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates various forms of multiple assignment in Ruby, including array destructuring, splat operators, and assignments to method calls, and their Tree-sitter parse tree representations. ```Ruby x, y = [1, 2] x, * = [1, 2] x, *args = [1, 2] x, y = *foo self.foo, self.bar = target.a?, target.b (x, y) = foo (a, b, c = 1) ``` ```Tree-sitter S-expression (program (assignment (left_assignment_list (identifier) (identifier)) (array (integer) (integer))) (assignment (left_assignment_list (identifier) (rest_assignment)) (array (integer) (integer))) (assignment (left_assignment_list (identifier) (rest_assignment (identifier))) (array (integer) (integer))) (assignment (left_assignment_list (identifier) (identifier)) (splat_argument (identifier))) (assignment (left_assignment_list (call (self) (identifier)) (call (self) (identifier))) (right_assignment_list (call (identifier) (identifier)) (call (identifier) (identifier)))) (assignment (left_assignment_list (destructured_left_assignment (identifier) (identifier))) (identifier)) (parenthesized_statements (assignment (left_assignment_list (identifier) (identifier) (identifier)) (integer)))) ``` -------------------------------- ### Ruby `__END__` Block Followed by Comment and Parse Tree Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Demonstrates a Ruby `__END__` block where the uninterpreted section starts with a comment, and its Tree-sitter parse tree. ```Ruby word __END__ # comment ``` ```Tree-sitter Parse Tree (program (identifier) (uninterpreted)) ``` -------------------------------- ### Ruby Vacuous Literal (Empty Parentheses) Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the use of empty parentheses as a vacuous literal or empty statement block, and its Tree-sitter parse tree representation. ```Ruby () ``` ```Tree-sitter S-expression (program (parenthesized_statements)) ``` -------------------------------- ### Ruby Percent `I` Symbol Array with Newlines and Interpolations Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows a `%I` symbol array with elements spanning multiple lines and including interpolation, demonstrating flexible formatting and its Tree-sitter parse. ```ruby %I{ * /#{something}+ ok } ``` ```tree-sitter-s-expression (program (symbol_array (bare_symbol (string_content)) (bare_symbol (string_content) (interpolation (identifier)) (string_content)) (bare_symbol (string_content)))) ``` -------------------------------- ### Parse Tree for Forward Slash Operator as Method Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows how Tree-sitter parses the forward slash as a binary operator when it's not a regex, such as in a method call context. ```Ruby Foo / "bar" "/edit" ``` ```Tree-sitter Ruby Parse Tree (program (binary (constant) (string (string_content))) (string (string_content))) ``` -------------------------------- ### Ruby Capitalized Hexadecimal Integers with Prefix and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Shows Ruby hexadecimal integers using the `0X` prefix, parsed as `integer` nodes by Tree-sitter. ```Ruby 0Xa_bcd_ef0_123_456_789 ``` ```Tree-sitter (program (integer)) ``` -------------------------------- ### Ruby Binary Minus Operator Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows the binary minus operator ('-') in Ruby, distinguishing it from unary minus, and its parsing as a 'binary' expression in Tree-sitter. ```Ruby foo-a @ivar-1 ``` ```Tree-sitter Parse Tree (program (binary (identifier) (identifier)) (binary (instance_variable) (integer))) ``` -------------------------------- ### Ruby Multiple Heredocs in a Single Line Print Statement Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates using multiple heredocs as arguments to a single method call (`puts`), where each heredoc is followed by a method call (`.size`). The Tree-sitter output shows the parsing of these distinct heredoc arguments. ```Ruby puts <<-ONE.size, <<-TWO.size first heredoc content ONE second heredoc content TWO ``` ```Tree-sitter (program (call (identifier) (argument_list (call (heredoc_beginning) (identifier)) (call (heredoc_beginning) ``` -------------------------------- ### Ruby Simple Symbols and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates various forms of simple Ruby symbols, including those with punctuation and special characters, and their corresponding `simple_symbol` node in the Tree-sitter parse tree. ```Ruby :foo :foo! :foo? :foo= :@foo :@foo_0123_bar :@@foo :$foo :$0 :_bar :åäö :_ ``` ```Tree-sitter (program (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol) (simple_symbol)) ``` -------------------------------- ### Ruby Heredoc with Method Chaining Continuation Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates a Ruby heredoc used as an argument to a method call, followed by method chaining on the result, and its Tree-sitter parse tree. ```Ruby select(<<-SQL) ab SQL .join() ``` ```Tree-sitter (program (call receiver: (call method: (identifier) arguments: (argument_list (heredoc_beginning))) (heredoc_body (heredoc_content) (heredoc_end)) method: (identifier))) ``` -------------------------------- ### Parse Ruby Method Calls with Reserved Keyword Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates how Ruby methods can accept arguments named after reserved keywords (e.g., `if:`, `alias:`, `and:`). The Tree-sitter parse tree shows these as `hash_key_symbol` within an `argument_list`. ```Ruby foo(if: true) foo alias: true foo and: true foo begin: true foo break: true foo case: true foo class: true foo def: true foo defined: true foo do: true foo else: true foo elsif: true foo end: true foo ensure: true foo false: true foo for: true foo if: true foo in: true foo module: true foo next: true foo nil: true foo not: true foo or: true foo redo: true foo rescue: true foo retry: true foo return: true foo self: true foo super: true foo then: true foo true: true foo undef: true foo unless: true foo until: true foo when: true foo while: true foo yield: true foo yield: ``` ```Tree-sitter Parse Tree (program (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol)) (true)))) ``` -------------------------------- ### Ruby Loop Control Keywords Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/control-flow.txt Demonstrates the usage of `next`, `retry`, `break`, and `redo` keywords within Ruby loops. Each example shows the keyword's placement and its corresponding Tree-sitter parse tree, illustrating how these control flow mechanisms are represented. ```Ruby for x in y next end for x in y retry end while b break end while b redo end ``` ```Tree-sitter (program (for (identifier) (in (identifier)) (do (next)))) (program (for pattern: (identifier) value: (in (identifier)) body: (do (retry)))) (program (while (identifier) (do (break)))) (program (while (identifier) (do (redo)))) ``` -------------------------------- ### Ruby Method Calls in Binary Expressions and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates how Tree-sitter parses Ruby method calls embedded within binary expressions (e.g., `or`, `and`), showing the operator precedence and argument grouping. ```Ruby one two or three four, five and six seven, eight, nine ``` ```Tree-sitter Grammar (program (binary left: (binary left: (call method: (identifier) arguments: (argument_list (identifier))) right: (call method: (identifier) arguments: (argument_list (identifier) (identifier)))) right: (call method: (identifier) arguments: (argument_list (identifier) (identifier) (identifier))))) ``` -------------------------------- ### Ruby Element Reference on Call Expressions Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates how element references are applied to the results of method calls and block expressions in Ruby, including chained operations and comparisons. ```Ruby d(a) [0] d.find { |x| x > 1 } [0] d.find { |x| x > 1 } [0] == 0 ``` ```Tree-sitter (program (element_reference (call (identifier) (argument_list (identifier))) (integer)) (element_reference (call (identifier) (identifier) (block (block_parameters (identifier)) (block_body (binary (identifier) (integer)))))) (integer)) (binary (element_reference (call (identifier) (identifier) (block (block_parameters (identifier)) (block_body (binary (identifier) (integer)))))) (integer)) (integer))) ``` -------------------------------- ### Parse Tree for Lambda Expression with Optional Argument Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows the Tree-sitter parse tree for a Ruby lambda expression that defines an optional argument with a default value. ```Ruby lambda { |a, b=nil| 1 } ``` ```Tree-sitter Ruby Parse Tree (program (call (identifier) (block (block_parameters (identifier) (optional_parameter (identifier) (nil))) (block_body (integer))))) ``` -------------------------------- ### Ruby Element Reference (Array/Hash Access) Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows various forms of element referencing in Ruby, such as accessing array or hash elements with and without splat arguments, and their Tree-sitter AST representation. ```Ruby foo[bar] foo[*bar] foo[* bar] foo[] ``` ```Tree-sitter S-expression (program (element_reference object: (identifier) (identifier)) (element_reference object: (identifier) (splat_argument (identifier))) (element_reference object: (identifier) (splat_argument (identifier))) (element_reference object: (identifier))) ``` -------------------------------- ### Ruby Method Calls with Keyword Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates Ruby method calls using modern keyword arguments (`key: value`) syntax, including cases with missing values. The Tree-sitter parse tree shows these as `pair` nodes with `hash_key_symbol`. ```Ruby foo(a: true) foo a: true foo B: true foo a: ; foo B: ``` ```Tree-sitter (program (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol) (true)))) (call (identifier) (argument_list (pair (hash_key_symbol)))) (call (identifier)) ``` -------------------------------- ### Ruby Method Call with Trailing Comma Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Examples of Ruby method calls that include a trailing comma in the argument list, and their partial Tree-sitter parse tree representation as provided in the source. ```Ruby foo(a, b,) foo(bar(a),) ``` ```Tree-sitter Parse Tree (program (call (identifier) (argument_list ``` -------------------------------- ### Parse Tree for Lambda Expression with Single Argument Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows the Tree-sitter parse tree for a Ruby lambda expression that accepts a single argument, detailing the 'block_parameters' node. ```Ruby lambda { |foo| 1 } ``` ```Tree-sitter Ruby Parse Tree (program (call (identifier) (block (block_parameters (identifier)) (block_body (integer))))) ``` -------------------------------- ### Single-Quoted Heredocs Without Interpolation or Escapes Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Illustrates how single-quoted heredocs (`<<'EOF'`) prevent interpolation and escape sequence processing in Ruby, and their corresponding Tree-sitter parses. Includes examples with different heredoc delimiters. ```ruby <<'EOF' This is \not\ an interpolation: #{foo} EOF <<~'EOF' This is \not\ an interpolation: #{foo} EOF <<-'EOF' This is \not\ an interpolation: #{foo} EOF ``` ```tree-sitter-s-expression (program (heredoc_beginning) (heredoc_body (heredoc_content) (heredoc_end)) (heredoc_beginning) (heredoc_body (heredoc_content) (heredoc_end)) (heredoc_beginning) (heredoc_body (heredoc_content) (heredoc_end))) ``` -------------------------------- ### Ruby Until Loop Examples Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/control-flow.txt Illustrates the `until` loop in Ruby, showing both an empty loop and a loop with a body. The corresponding Tree-sitter parse trees detail how the condition and body are structured, including cases with method calls in the condition. ```Ruby until foo bar do end until foo do bar end ``` ```Tree-sitter (program (until condition: (call method: (identifier) arguments: (argument_list (identifier))) body: (do))) (program (until (identifier) (do (identifier)))) ``` -------------------------------- ### Ruby Bitwise Shift Operators Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates the left ('<<') and right ('>>') bitwise shift operators in Ruby, along with their Tree-sitter parse tree representation as binary expressions. ```Ruby a >> b a << b ``` ```Tree-sitter Parse Tree (program (binary (identifier) (identifier)) (binary (identifier) (identifier))) ``` -------------------------------- ### Ruby Method Calls with Splat Arguments and Tree-sitter Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates how Ruby method calls using splat (`*`) arguments are parsed by Tree-sitter, including simple identifiers, array expansions, and method calls within splats. ```Ruby foo(*bar) foo *bar foo *%w{ .. lib } foo *(bar.baz) ``` ```Tree-sitter Grammar (program (call (identifier) (argument_list (splat_argument (identifier)))) (call (identifier) (argument_list (splat_argument (identifier)))) (call (identifier) (argument_list (splat_argument (string_array (bare_string (string_content)) (bare_string (string_content)))))) (call (identifier) (argument_list (splat_argument (parenthesized_statements (call (identifier) (identifier))))))) ``` -------------------------------- ### Ruby Nested Unparenthesized Method Calls Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates how Ruby parses nested method calls, particularly when inner calls lack parentheses, and their representation in the Tree-sitter parse tree. ```Ruby puts get_name self, true puts(get_name self, true) ``` ```Tree-sitter Parse Tree (program (call method: (identifier) arguments: (argument_list (call method: (identifier) arguments: (argument_list (self) (true))))) (call method: (identifier) arguments: (argument_list (call method: (identifier) arguments: (argument_list (self) (true)))))) ``` -------------------------------- ### Ruby Singleton Method Definition Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Demonstrates the basic syntax for defining a singleton method in Ruby using `self.method_name` and its corresponding Tree-sitter parse tree representation, showing the `singleton_method` node. ```Ruby def self.foo end ``` ```Tree-sitter Grammar (program (singleton_method (self) (identifier))) ``` -------------------------------- ### Relational Operators in Ruby Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Covers various relational operators in Ruby ('==', '!=', '===', '<=>', '=~', '!~'), including cases with and without spaces. The parse tree shows most as 'binary' operations, but '!~' without a space is parsed as a 'call' with a 'unary' operand, and a comment. ```Ruby a == b a != b a === b a <=> b a =~ b a !~ b a==b a!=b a===b a<=>b a=~b a!~b # not a binary operation ``` ```Tree-sitter (program (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (binary left: (identifier) right: (identifier)) (call method: (identifier) arguments: (argument_list (unary operand: (identifier)))) (comment)) ``` -------------------------------- ### Parse Tree for Division Without Spaces and Interpolation Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Shows how Tree-sitter parses division operations without spaces and within string interpolations, distinguishing them from regex literals. ```Ruby h/w "#{foo}" Time.at(timestamp/1000) "#{timestamp}" ``` ```Tree-sitter Ruby Parse Tree (program (binary left: (identifier) right: (identifier)) (string (interpolation (identifier))) (call receiver: (constant) method: (identifier) arguments: (argument_list (binary left: (identifier) right: (integer)))) (string (interpolation (identifier)))) ``` -------------------------------- ### Ruby Method Calls with Hash Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates Ruby method calls where arguments are passed as hash literals using the `=>` syntax. The Tree-sitter parse tree represents these as `pair` nodes within an `argument_list`. ```Ruby foo(:a => true) foo([] => 1) foo(bar => 1) foo :a => true, :c => 1 ``` ```Tree-sitter (program (call (identifier) (argument_list (pair (simple_symbol) (true)))) (call (identifier) (argument_list (pair (array) (integer)))) (call (identifier) (argument_list (pair (identifier) (integer)))) (call (identifier) (argument_list (pair (simple_symbol) (true)) (pair (simple_symbol) (integer))))) ``` -------------------------------- ### Ruby Singleton Method with Body Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Illustrates a singleton method definition that includes a body statement, showing how the Tree-sitter grammar captures the method's content within a `body_statement` node. ```Ruby def self.foo bar end ``` ```Tree-sitter Grammar (program (singleton_method (self) (identifier) (body_statement (identifier)))) ``` -------------------------------- ### Ruby CRLF Multiline Comments and S-expression Parse Tree Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/line-endings.txt Illustrates Ruby's `=begin` and `=end` multiline comment syntax and its representation in a Tree-sitter S-expression parse tree, showing how comments are recognized by Tree-sitter. ```Ruby =begin =end ``` ```S-expression (program (comment)) ``` -------------------------------- ### Empty Ruby Method Definitions and Tree-sitter Grammar Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Illustrates the Tree-sitter grammar for basic Ruby method definitions, including methods with `?` and `!` suffixes, which are common Ruby conventions. ```Ruby def foo end def foo? end def foo! end ``` ```Tree-sitter S-expression (program (method (identifier)) (method (identifier)) (method (identifier))) ``` -------------------------------- ### Tree-sitter AST for Ruby Parameter Types Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates the Tree-sitter Abstract Syntax Tree (AST) representation for various Ruby parameter types, including destructured parameters, splat parameters, method parameters, and block parameters. ```Tree-sitter (destructured_parameter (identifier) (identifier)))) (method (identifier) (method_parameters (identifier) (splat_parameter (identifier)) (destructured_parameter (identifier) (identifier)))) (call (identifier) (do_block (block_parameters (identifier) (destructured_parameter (identifier) (identifier) (splat_parameter (identifier)) (destructured_parameter (identifier) (identifier))) (splat_parameter (identifier)))))) ``` -------------------------------- ### Ruby Heredocs Used in Arguments, Hashes, and Arrays Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates the flexibility of Ruby heredocs by embedding them as method arguments, hash key-value pairs, and array elements. The Tree-sitter parse tree shows how these different contexts are represented. ```Ruby foo.new( select: <<-TEXT, heredoc content, TEXT conditions: <<-TEXT heredoc content TEXT ) { select: <<-TEXT, heredoc content, TEXT conditions: <<-TEXT heredoc content TEXT } [ <<-TEXT, a TEXT <<-TEXT b TEXT ] foo[ 1, <<-TEXT hi TEXT ] = 3 ``` ```Tree-sitter (program (call receiver: (identifier) method: (identifier) arguments: (argument_list (pair key: (hash_key_symbol) value: (heredoc_beginning)) (heredoc_body (heredoc_content) (heredoc_end)) (pair key: (hash_key_symbol) value: (heredoc_beginning)) (heredoc_body (heredoc_content) (heredoc_end)))) (hash (pair key: (hash_key_symbol) value: (heredoc_beginning)) (heredoc_body (heredoc_content) (heredoc_end)) (pair key: (hash_key_symbol) value: (heredoc_beginning)) (heredoc_body (heredoc_content) (heredoc_end))) (array (heredoc_beginning) (heredoc_body (heredoc_content) (heredoc_end)) (heredoc_beginning) (heredoc_body (heredoc_content) (heredoc_end))) (assignment left: (element_reference object: (identifier) (integer) (heredoc_beginning) (heredoc_body (heredoc_content) (heredoc_end))) right: (integer))) ``` -------------------------------- ### Ruby Array Literals with Various Elements Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates different forms of Ruby array literals, including simple elements, splat arguments, and hash pairs, along with their Tree-sitter parses, highlighting the flexibility of array content. ```ruby [ foo, bar ] [foo, *bar] [foo, *@bar] [foo, *$bar] [foo, :bar => 1] ``` ```tree-sitter-s-expression (program (array (identifier) (identifier)) (array (identifier) (splat_argument (identifier))) (array (identifier) (splat_argument (instance_variable))) (array (identifier) (splat_argument (global_variable))) (array (identifier) (pair (simple_symbol) (integer)))) ``` -------------------------------- ### Boolean AND/OR Operator Precedence in Ruby Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Demonstrates the combination of boolean AND and OR operators, highlighting operator precedence. The parse tree shows nested 'binary' operations reflecting the precedence. ```Ruby a || b && c a && b || c ``` ```Tree-sitter (program (binary left: (identifier) right: (binary left: (identifier) right: (identifier))) (binary left: (binary left: (identifier) right: (identifier)) right: (identifier))) ``` -------------------------------- ### Ruby Logical NOT Operator Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Illustrates the `not` keyword for logical negation, and its representation as a unary operation in the Tree-sitter parse tree. ```Ruby not foo ``` ```Tree-sitter S-expression (program (unary (identifier))) ``` -------------------------------- ### Ruby %Q String with Unbalanced Delimiters Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/literals.txt Demonstrates the use of Ruby's `%Q` string literal with various unbalanced delimiters, showcasing how they are interpreted by the parser, and its corresponding Tree-sitter parse tree representation. ```Ruby %Q#a# %Q/a/ %Q\a\ ``` ```Tree-sitter (program (string (string_content)) (string (string_content)) (string (string_content))) ``` -------------------------------- ### Ruby Chained Method Calls with Blocks and Implicit Parentheses Parsing Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Explores the Tree-sitter parsing of complex Ruby chained method calls that include blocks and omit explicit parentheses, highlighting how the grammar captures the nesting and argument passing. ```Ruby a.b c, *d do |e| f end.g h { |i| i }.j do k end ``` ```Tree-sitter Grammar (program (call receiver: (call receiver: (identifier) method: (identifier) arguments: (argument_list (identifier) (splat_argument (identifier))) block: (do_block parameters: (block_parameters (identifier)) body: (body_statement (identifier)))) method: (identifier) arguments: (argument_list (call receiver: (call method: (identifier) block: (block parameters: (block_parameters (identifier)) body: (block_body (identifier)))) method: (identifier) block: (do_block body: (body_statement (identifier))))))) ``` -------------------------------- ### Ruby Singleton Method with Multiple Parenthesized Arguments Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/declarations.txt Illustrates a singleton method defined with multiple parenthesized arguments, showing how the Tree-sitter grammar lists each argument within `method_parameters`. ```Ruby def self.foo(bar, baz) end ``` ```Tree-sitter Grammar (program (singleton_method (self) (identifier) (method_parameters (identifier) (identifier)))) ``` -------------------------------- ### Logical and Bitwise Operator Assignment in Ruby Source: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/test/corpus/expressions.txt Covers logical and bitwise operator assignments (e.g., '||=', '&&=', '&=', '|=', '%=', '>>=', '<<=', '^='). The Tree-sitter representation consistently identifies these as 'operator_assignment' nodes. ```Ruby x ||= y x &&= y x &= y x |= y x %= y x >>= y x <<= y x ^= y ``` ```Tree-sitter (program (operator_assignment (identifier) (identifier)) (operator_assignment (identifier) (identifier)) (operator_assignment (identifier) (identifier)) (operator_assignment (identifier) (identifier)) (operator_assignment (identifier) (identifier)) (operator_assignment (identifier) (identifier)) (operator_assignment (identifier) (identifier)) (operator_assignment (identifier) (identifier))) ```