diff --git a/Cargo.lock b/Cargo.lock index d5856b9..942a44e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -401,6 +401,7 @@ dependencies = [ "tree-sitter-java", "tree-sitter-javascript", "tree-sitter-lua", + "tree-sitter-odin", "tree-sitter-php", "tree-sitter-python", "tree-sitter-r", @@ -2933,6 +2934,16 @@ dependencies = [ "tree-sitter-language", ] +[[package]] +name = "tree-sitter-odin" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24db210fe9ba2237c71c5030d7b146c7025420ba72dd8013d13cd822c3a8d77a" +dependencies = [ + "cc", + "tree-sitter-language", +] + [[package]] name = "tree-sitter-php" version = "0.24.2" diff --git a/Cargo.toml b/Cargo.toml index 1a7c9ad..6867e2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,7 @@ tree-sitter-html = "<0.25.0" tree-sitter-java = "<0.25.0" tree-sitter-javascript = "<0.26.0" tree-sitter-lua = "<0.25.0" +tree-sitter-odin = "1.3.0" tree-sitter-php = "<0.25.0" tree-sitter-python = "<0.26.0" tree-sitter-r = "1.1.0" diff --git a/crates/codebook/Cargo.toml b/crates/codebook/Cargo.toml index e490d32..6c17635 100644 --- a/crates/codebook/Cargo.toml +++ b/crates/codebook/Cargo.toml @@ -41,6 +41,7 @@ tree-sitter-java.workspace = true tree-sitter-javascript.workspace = true codebook-tree-sitter-latex.workspace = true tree-sitter-lua.workspace = true +tree-sitter-odin.workspace = true tree-sitter-php.workspace = true tree-sitter-python.workspace = true tree-sitter-r.workspace = true diff --git a/crates/codebook/src/queries.rs b/crates/codebook/src/queries.rs index b6e3031..7136945 100644 --- a/crates/codebook/src/queries.rs +++ b/crates/codebook/src/queries.rs @@ -17,6 +17,7 @@ pub enum LanguageType { Javascript, Latex, Lua, + Odin, Php, Python, R, @@ -179,7 +180,13 @@ pub static LANGUAGE_SETTINGS: &[LanguageSetting] = &[ query: include_str!("queries/bash.scm"), extensions: &["sh", "bash"], }, - // Added PHP + LanguageSetting { + type_: LanguageType::Odin, + ids: &["odin"], + dictionary_ids: &["odin"], + query: include_str!("queries/odin.scm"), + extensions: &["odin"], + }, LanguageSetting { type_: LanguageType::Php, ids: &["php"], @@ -243,6 +250,7 @@ impl LanguageSetting { LanguageType::Javascript => Some(tree_sitter_javascript::LANGUAGE.into()), LanguageType::Latex => Some(codebook_tree_sitter_latex::LANGUAGE.into()), LanguageType::Lua => Some(tree_sitter_lua::LANGUAGE.into()), + LanguageType::Odin => Some(tree_sitter_odin::LANGUAGE.into()), LanguageType::Php => Some(tree_sitter_php::LANGUAGE_PHP.into()), LanguageType::Python => Some(tree_sitter_python::LANGUAGE.into()), LanguageType::R => Some(tree_sitter_r::LANGUAGE.into()), diff --git a/crates/codebook/src/queries/odin.scm b/crates/codebook/src/queries/odin.scm new file mode 100644 index 0000000..eefc914 --- /dev/null +++ b/crates/codebook/src/queries/odin.scm @@ -0,0 +1,46 @@ +; Comments +(comment) @comment +(block_comment) @comment + +; Procedure declarations (including parameter names) +(procedure_declaration + (expression) @identifier) +(overloaded_procedure_declaration + (expression) @identifier) +(parameter + (identifier) @identifier) +(default_parameter + (identifier) @identifier) + +; Variables and constants identifiers (declaration-only) +(var_declaration + (expression) @identifier ":") +(assignment_statement + (expression) @identifier ":=") +(const_declaration + (expression)+ @identifier) +(const_type_declaration + (expression)+ @identifier) + +; Struct, enum, union, bit_fields names +(struct_declaration + (expression) @identifier) +(enum_declaration + (expression) @identifier) +(union_declaration + (expression) @identifier) +(bit_field_declaration + (expression) @identifier "::") + +; Field and enum variant names +; BUG: matches constants in enum value and bit size number +; (maybe be a skill issue, maybe a grammar update is needed) +(field + (identifier) @identifier) +(bit_field_declaration "::" + (identifier) @identifier) +(enum_declaration "::" + (identifier) @identifier) + +; Strings +(string_content) @string diff --git a/crates/codebook/tests/examples/example.odin b/crates/codebook/tests/examples/example.odin new file mode 100644 index 0000000..27cca73 --- /dev/null +++ b/crates/codebook/tests/examples/example.odin @@ -0,0 +1,98 @@ +package main + +import "core:fmt" + +// Test program for the Codebook spell-checking tool. +// The goal is to spellcheck comments, strings, +// identifiers during declarations, but not during usage + +// Commennt +/* + Block cooment + /* + Netsed block + */ +*/ + +my_proecdure :: proc(my_prameter: int, another_paramter: f64) { + fmt.println(cast(f64)my_prameter + another_paramter) +} + +another_porocedure :: proc(my_prameter: f64, another_paramter: int) { + fmt.println(my_prameter + cast(f64)another_paramter) +} + +overloded_procedure:: proc{my_proecdure, another_porocedure} + +with_deafult :: proc(my_prameter:= 42) { + fmt.println(my_prameter) +} + +with_varidic :: proc(numberes: ..int) { + fmt.println(numberes) +} + +MY_CONSATANT : int : 123 +ANOTHER_COONSTANT :: 456 + +main :: proc() { + declaring_without_assignement: int + declaring_anotther, and_annother: int + with_assignement := 42 + assignement_with_explicit_type : int = 33 + and_another_one, and_more := "Helloep", "Wordl" + fmt.println( + MY_CONSATANT, + ANOTHER_COONSTANT, + declaring_without_assignement, + declaring_anotther, + with_assignement, + assignement_with_explicit_type, + and_another_one, + and_more, + ) + + MyAwseomeStruct :: struct { + my_field: f32, + another_field: f32, + } + foo := MyAwseomeStruct{1, 2} + fmt.println(foo.my_field, foo.another_field) + + CompacotStruct :: struct { + aples, banananas, ornages: int + } + bar := CompacotStruct{3, 4, 5} + fmt.println(bar.aples, bar.banananas, bar.ornages) + + TWOOF :: 2 + MyCratfyEnum :: enum { + Aapple, + Baanana = 2, + Oranege = TWOOF, // BUG: (see odin.scm) + } + buzz := MyCratfyEnum.Baanana + fmt.println(buzz) + + MyUnberakableUnion :: union {int, bool} + + MyFruttyInstruction :: bit_field u64 { + verison: u8 | 3, + ttl: u8 | 8, + fruit: MyCratfyEnum | TWOOF, // BUG: (see odin.scm) + opration: u8 | 3, + left_opernd: u16 | 16, + right_oprand: u16 | 16, + destination: u16 | 16, + } + i := MyFruttyInstruction{} + i.fruit = .Baanana + fmt.println(i.left_opernd, i.right_oprand) + + fmt.println("Helolo, Wlorld!") + + overloded_procedure(33, 3.3) + overloded_procedure(4, 44.4) + with_deafult(42) + with_varidic(1, 2, 3) +}