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
112 changes: 112 additions & 0 deletions internal/treesitter/lua/rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
flattened:
- string
- comment
aliased:
# Arithmetic operators
"+": arithmetic_operator_literal
"-": arithmetic_operator_literal
"*": arithmetic_operator_literal
"/": arithmetic_operator_literal
"//": arithmetic_operator_literal
"%": arithmetic_operator_literal
"^": arithmetic_operator_literal

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

# Logical operators
"and": logical_operator_literal
"or": logical_operator_literal
"not": unary_operator_literal

# Bitwise operators (Lua 5.3+)
"&": bitwise_operator_literal
"|": bitwise_operator_literal
"~": bitwise_operator_literal
"<<": bitwise_operator_literal
">>": bitwise_operator_literal

# String concatenation
"..": concat_operator_literal

# Assignment
"=": assignment_operator_literal

# Length operator
"#": length_operator_literal

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

scaffolding:
- chunk
- block
- arguments
- parameters
- parenthesized_expression
- expression_list
- variable_list
- table_constructor
- field
- function_declaration
- function_definition
- if_statement
- elseif_statement
- else_statement
- for_statement
- for_generic_clause
- for_numeric_clause
- while_statement
- repeat_statement
- do_statement
- assignment_statement
- variable_declaration
- return_statement
- label_statement
- goto_statement

keywords:
- function
- local
- return
- if
- else
- elseif
- then
- end
- for
- in
- do
- while
- repeat
- until
- break
- goto
- and
- or
- not
- true
- false
- nil

declarations:
- function_declaration
- function_definition
- variable_declaration

11 changes: 11 additions & 0 deletions internal/treesitter/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ int main() { std::cout << "Hello C++\n"; return 0; }`)
t.Error("Parse(): expected non-nil AST root")
}
})

t.Run("valid lua source", func(t *testing.T) {
src := []byte(`local function greet(name) print("Hello, " .. name) end`)
ast, err := Parse(src, "main.lua")
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
11 changes: 11 additions & 0 deletions internal/treesitter/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ func TestRulesAliased(t *testing.T) {
"&", "|", "^", "<<", ">>", "~",
},
},
{
lang: "lua",
operators: []string{
"+", "-", "*", "/", "//", "%", "^",
"==", "~=", "<", "<=", ">", ">=",
"and", "or", "not",
"=",
"&", "|", "~", "<<", ">>",
"..", "#",
},
},
}

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