Skip to content

Commit a2bfac6

Browse files
committed
Add Odin support (#182)
1 parent 0d39da7 commit a2bfac6

File tree

6 files changed

+166
-1
lines changed

6 files changed

+166
-1
lines changed

Cargo.lock

Lines changed: 11 additions & 0 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
@@ -54,6 +54,7 @@ tree-sitter-html = "<0.25.0"
5454
tree-sitter-java = "<0.25.0"
5555
tree-sitter-javascript = "<0.26.0"
5656
tree-sitter-lua = "<0.25.0"
57+
tree-sitter-odin = "1.3.0"
5758
tree-sitter-php = "<0.25.0"
5859
tree-sitter-python = "<0.26.0"
5960
tree-sitter-r = "1.1.0"

crates/codebook/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ tree-sitter-java.workspace = true
4141
tree-sitter-javascript.workspace = true
4242
codebook-tree-sitter-latex.workspace = true
4343
tree-sitter-lua.workspace = true
44+
tree-sitter-odin.workspace = true
4445
tree-sitter-php.workspace = true
4546
tree-sitter-python.workspace = true
4647
tree-sitter-r.workspace = true

crates/codebook/src/queries.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub enum LanguageType {
1717
Javascript,
1818
Latex,
1919
Lua,
20+
Odin,
2021
Php,
2122
Python,
2223
R,
@@ -179,7 +180,13 @@ pub static LANGUAGE_SETTINGS: &[LanguageSetting] = &[
179180
query: include_str!("queries/bash.scm"),
180181
extensions: &["sh", "bash"],
181182
},
182-
// Added PHP
183+
LanguageSetting {
184+
type_: LanguageType::Odin,
185+
ids: &["odin"],
186+
dictionary_ids: &["odin"],
187+
query: include_str!("queries/odin.scm"),
188+
extensions: &["odin"],
189+
},
183190
LanguageSetting {
184191
type_: LanguageType::Php,
185192
ids: &["php"],
@@ -243,6 +250,7 @@ impl LanguageSetting {
243250
LanguageType::Javascript => Some(tree_sitter_javascript::LANGUAGE.into()),
244251
LanguageType::Latex => Some(codebook_tree_sitter_latex::LANGUAGE.into()),
245252
LanguageType::Lua => Some(tree_sitter_lua::LANGUAGE.into()),
253+
LanguageType::Odin => Some(tree_sitter_odin::LANGUAGE.into()),
246254
LanguageType::Php => Some(tree_sitter_php::LANGUAGE_PHP.into()),
247255
LanguageType::Python => Some(tree_sitter_python::LANGUAGE.into()),
248256
LanguageType::R => Some(tree_sitter_r::LANGUAGE.into()),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; Comments
2+
(comment) @comment
3+
(block_comment) @comment
4+
5+
; Procedure declarations (including parameter names)
6+
(procedure_declaration
7+
(expression) @identifier)
8+
(overloaded_procedure_declaration
9+
(expression) @identifier)
10+
(parameter
11+
(identifier) @identifier)
12+
(default_parameter
13+
(identifier) @identifier)
14+
15+
; Variables and constants identifiers (declaration-only)
16+
(var_declaration
17+
(expression) @identifier ":")
18+
(assignment_statement
19+
(expression) @identifier ":=")
20+
(const_declaration
21+
(expression)+ @identifier)
22+
(const_type_declaration
23+
(expression)+ @identifier)
24+
25+
; Struct, enum, union, bit_fields names
26+
(struct_declaration
27+
(expression) @identifier)
28+
(enum_declaration
29+
(expression) @identifier)
30+
(union_declaration
31+
(expression) @identifier)
32+
(bit_field_declaration
33+
(expression) @identifier "::")
34+
35+
; Field and enum variant names
36+
; BUG: matches constants in enum value and bit size number
37+
; (maybe be a skill issue, maybe a grammar update is needed)
38+
(field
39+
(identifier) @identifier)
40+
(bit_field_declaration "::"
41+
(identifier) @identifier)
42+
(enum_declaration "::"
43+
(identifier) @identifier)
44+
45+
; Strings
46+
(string_content) @string
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package main
2+
3+
import "core:fmt"
4+
5+
// Test program for the Codebook spell-checking tool.
6+
// The goal is to spellcheck comments, strings,
7+
// identifiers during declarations, but not during usage
8+
9+
// Commennt
10+
/*
11+
Block cooment
12+
/*
13+
Netsed block
14+
*/
15+
*/
16+
17+
my_proecdure :: proc(my_prameter: int, another_paramter: f64) {
18+
fmt.println(cast(f64)my_prameter + another_paramter)
19+
}
20+
21+
another_porocedure :: proc(my_prameter: f64, another_paramter: int) {
22+
fmt.println(my_prameter + cast(f64)another_paramter)
23+
}
24+
25+
overloded_procedure:: proc{my_proecdure, another_porocedure}
26+
27+
with_deafult :: proc(my_prameter:= 42) {
28+
fmt.println(my_prameter)
29+
}
30+
31+
with_varidic :: proc(numberes: ..int) {
32+
fmt.println(numberes)
33+
}
34+
35+
MY_CONSATANT : int : 123
36+
ANOTHER_COONSTANT :: 456
37+
38+
main :: proc() {
39+
declaring_without_assignement: int
40+
declaring_anotther, and_annother: int
41+
with_assignement := 42
42+
assignement_with_explicit_type : int = 33
43+
and_another_one, and_more := "Helloep", "Wordl"
44+
fmt.println(
45+
MY_CONSATANT,
46+
ANOTHER_COONSTANT,
47+
declaring_without_assignement,
48+
declaring_anotther,
49+
with_assignement,
50+
assignement_with_explicit_type,
51+
and_another_one,
52+
and_more,
53+
)
54+
55+
MyAwseomeStruct :: struct {
56+
my_field: f32,
57+
another_field: f32,
58+
}
59+
foo := MyAwseomeStruct{1, 2}
60+
fmt.println(foo.my_field, foo.another_field)
61+
62+
CompacotStruct :: struct {
63+
aples, banananas, ornages: int
64+
}
65+
bar := CompacotStruct{3, 4, 5}
66+
fmt.println(bar.aples, bar.banananas, bar.ornages)
67+
68+
TWOOF :: 2
69+
MyCratfyEnum :: enum {
70+
Aapple,
71+
Baanana = 2,
72+
Oranege = TWOOF, // BUG: (see odin.scm)
73+
}
74+
buzz := MyCratfyEnum.Baanana
75+
fmt.println(buzz)
76+
77+
MyUnberakableUnion :: union {int, bool}
78+
79+
MyFruttyInstruction :: bit_field u64 {
80+
verison: u8 | 3,
81+
ttl: u8 | 8,
82+
fruit: MyCratfyEnum | TWOOF, // BUG: (see odin.scm)
83+
opration: u8 | 3,
84+
left_opernd: u16 | 16,
85+
right_oprand: u16 | 16,
86+
destination: u16 | 16,
87+
}
88+
i := MyFruttyInstruction{}
89+
i.fruit = .Baanana
90+
fmt.println(i.left_opernd, i.right_oprand)
91+
92+
fmt.println("Helolo, Wlorld!")
93+
94+
overloded_procedure(33, 3.3)
95+
overloded_procedure(4, 44.4)
96+
with_deafult(42)
97+
with_varidic(1, 2, 3)
98+
}

0 commit comments

Comments
 (0)