Skip to content

Commit e4564a2

Browse files
committed
Add Lua support
1 parent f0c8387 commit e4564a2

File tree

13 files changed

+538
-22
lines changed

13 files changed

+538
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[0.3.8]
2+
3+
- Add support for Lua language
4+
15
[0.3.7]
26

37
- Better error message for user-supplied regex

Cargo.lock

Lines changed: 30 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ tree-sitter-haskell = "<0.25.0"
5050
tree-sitter-html = "<0.25.0"
5151
tree-sitter-java = "<0.25.0"
5252
tree-sitter-javascript = "<0.25.0"
53+
tree-sitter-lua = "<0.25.0"
5354
tree-sitter-php = "<0.24.0"
5455
tree-sitter-python = "<0.25.0"
5556
tree-sitter-r = "1.1.0"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Codebook is in active development. As better dictionaries are added, words that
129129
| Haskell | ⚠️ |
130130
| Java ||
131131
| JavaScript ||
132+
| Lua ||
132133
| Markdown ||
133134
| PHP | ⚠️ |
134135
| Plain Text ||

crates/codebook/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ tree-sitter-haskell.workspace = true
3939
tree-sitter-html.workspace = true
4040
tree-sitter-java.workspace = true
4141
tree-sitter-javascript.workspace = true
42+
tree-sitter-lua.workspace = true
4243
tree-sitter-php.workspace = true
4344
tree-sitter-python.workspace = true
4445
tree-sitter-r.workspace = true

crates/codebook/src/dictionaries/combined.gen.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2988,4 +2988,4 @@ zip
29882988
zone
29892989
zoom
29902990
zsh
2991-
zshrc
2991+
zshrc

crates/codebook/src/queries.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub enum LanguageType {
1212
HTML,
1313
Java,
1414
Javascript,
15+
Lua,
1516
Php,
1617
Python,
1718
R,
@@ -137,6 +138,13 @@ pub static LANGUAGE_SETTINGS: &[LanguageSetting] = &[
137138
query: include_str!("queries/ruby.scm"),
138139
extensions: &["rb"],
139140
},
141+
LanguageSetting {
142+
type_: LanguageType::Lua,
143+
ids: &["lua"],
144+
dictionary_ids: &["lua"],
145+
query: include_str!("queries/lua.scm"),
146+
extensions: &["lua"],
147+
},
140148
LanguageSetting {
141149
type_: LanguageType::Bash,
142150
ids: &["bash", "shellscript", "sh", "shell script"],
@@ -182,6 +190,7 @@ impl LanguageSetting {
182190
LanguageType::HTML => Some(tree_sitter_html::LANGUAGE.into()),
183191
LanguageType::Java => Some(tree_sitter_java::LANGUAGE.into()),
184192
LanguageType::Javascript => Some(tree_sitter_javascript::LANGUAGE.into()),
193+
LanguageType::Lua => Some(tree_sitter_lua::LANGUAGE.into()),
185194
LanguageType::Php => Some(tree_sitter_php::LANGUAGE_PHP.into()),
186195
LanguageType::Python => Some(tree_sitter_python::LANGUAGE.into()),
187196
LanguageType::R => Some(tree_sitter_r::LANGUAGE.into()),

crates/codebook/src/queries/lua.scm

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; Comments
2+
(comment) @comment
3+
4+
; Strings
5+
(string) @string
6+
7+
; Function declarations
8+
(function_declaration
9+
name: (identifier) @identifier)
10+
11+
(function_declaration
12+
(method_index_expression
13+
method: (identifier) @identifier))
14+
15+
; Variable assignments
16+
(assignment_statement
17+
(variable_list
18+
(identifier) @identifier))
19+
20+
(assignment_statement
21+
(variable_list
22+
(dot_index_expression
23+
field: (identifier) @identifier)))
24+
25+
; Function parameters
26+
(parameters
27+
(identifier) @identifier)
28+
29+
; Table fields
30+
(field
31+
name: (identifier) @identifier)

crates/codebook/src/splitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct SplitRef<'a> {
1414
pub start_char: u32,
1515
}
1616

17-
pub fn split(s: &str) -> Vec<SplitRef> {
17+
pub fn split(s: &str) -> Vec<SplitRef<'_>> {
1818
if s.is_empty() {
1919
return Vec::new();
2020
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- Lua exampl file with intentional misspellings
2+
3+
-- Simple variable assignments
4+
mesage = "Helo Wrold!"
5+
countr = 0
6+
7+
-- Function declaration with misspelling
8+
function calculatr(numbr1, numbr2, operashun)
9+
local result = 0
10+
11+
if operashun == "+" then
12+
result = numbr1 + numbr2
13+
elseif operashun == "-" then
14+
result = numbr1 - numbr2
15+
end
16+
17+
return result
18+
end
19+
20+
-- Table definition
21+
local UserAccont = {}
22+
23+
-- Function with parameters
24+
function UserAccont:calculat_intrest(rate)
25+
return 1000 * rate
26+
end
27+
28+
-- Table with fields
29+
local config = {
30+
mesage = "test",
31+
countr = 42,
32+
intrest = 0.05
33+
}
34+
35+
-- Assignment statement
36+
local numbr = 100
37+
38+
-- More assignments
39+
local operashun = "add"

0 commit comments

Comments
 (0)