Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions internal/treesitter/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestDetectLanguage(t *testing.T) {
{"test.cs", false},
{"test.java", false},
{"test.php", false},
{"test.rb", false},
{"test.json", false},
{"test.yaml", false},
{"test.yml", false},
Expand Down Expand Up @@ -195,6 +196,17 @@ int main() { std::cout << "Hello C++\n"; return 0; }`)
t.Error("Parse(): expected non-nil AST root")
}
})

t.Run("valid ruby source", func(t *testing.T) {
src := []byte(`def hello; puts "Hello World"; end`)
ast, err := Parse(src, "main.rb")
if err != nil {
t.Fatalf("Parse(): unexpected error: %v", err)
}
if ast == nil {
t.Error("Parse(): expected non-nil AST root")
}
})
t.Run("unknown extension", func(t *testing.T) {
src := []byte(`some text`)
ast, err := Parse(src, "main.xyz")
Expand Down
157 changes: 157 additions & 0 deletions internal/treesitter/ruby/rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
flattened:
- string
- string_content
- heredoc_body
- comment
- integer
- float
- simple_symbol
- symbol
- identifier
- instance_variable
- class_variable
- global_variable
- constant

aliased:
# Comparison operators
"==": comparison_operator_literal
"!=": comparison_operator_literal
"===": comparison_operator_literal
"<=>": comparison_operator_literal
"<": comparison_operator_literal
"<=": comparison_operator_literal
">": comparison_operator_literal
">=": comparison_operator_literal
"=~": comparison_operator_literal
"!~": comparison_operator_literal

# Logical operators
"&&": logical_operator_literal
"||": logical_operator_literal
"!": unary_operator_literal

# Assignment operators
"=": assignment_operator_literal
"+=": assignment_operator_literal
"-=": assignment_operator_literal
"*=": assignment_operator_literal
"/=": assignment_operator_literal
"%=": assignment_operator_literal
"**=": assignment_operator_literal
"&=": assignment_operator_literal
"|=": assignment_operator_literal
"^=": assignment_operator_literal
"<<=": assignment_operator_literal
">>=": assignment_operator_literal
"||=": assignment_operator_literal
"&&=": assignment_operator_literal

# Arithmetic operators
"+": arithmetic_operator_literal
"-": arithmetic_operator_literal
"*": arithmetic_operator_literal
"/": arithmetic_operator_literal
"%": arithmetic_operator_literal
"**": arithmetic_operator_literal

# Bitwise operators
"&": bitwise_operator_literal
"|": bitwise_operator_literal
"^": bitwise_operator_literal
"<<": bitwise_operator_literal
">>": bitwise_operator_literal
"~": bitwise_operator_literal

ignored:
- "\n"
- "("
- ")"
- "{"
- "}"
- "["
- "]"
- ","
- ";"
- ":"
- "::"
- "."
- "->"
- "|"
- "=>"

scaffolding:
- program
- body_statement
- method
- singleton_method
- class
- module
- if
- unless
- elsif
- else
- while
- until
- for
- case
- when
- begin
- rescue
- ensure
- call
- method_call
- argument_list
- method_parameters
- block_parameters
- do_block
- block
- assignment
- operator_assignment
- hash
- array
- pair

keywords:
- def
- class
- module
- if
- unless
- elsif
- else
- case
- when
- while
- until
- for
- do
- begin
- rescue
- ensure
- end
- return
- yield
- break
- next
- redo
- retry
- alias
- undef
- and
- or
- not
- then
- in
- self
- nil
- true
- false
- super

declarations:
- method
- singleton_method
- class
- module

10 changes: 10 additions & 0 deletions internal/treesitter/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ func TestRulesAliased(t *testing.T) {
"++", "--", "??",
},
},
{
lang: "ruby",
operators: []string{
"==", "!=", "===", "<=>", "<", "<=", ">", ">=", "=~", "!~",
"&&", "||", "!",
"=", "+=", "-=", "*=", "/=", "%=", "**=", "&=", "|=", "^=", "<<=", ">>=", "||=", "&&=",
"+", "-", "*", "/", "%", "**",
"&", "|", "^", "<<", ">>", "~",
},
},
}

for _, tt := range tests {
Expand Down
Loading
Loading