Skip to content

Commit

Permalink
Add tree-sitter-vhdl
Browse files Browse the repository at this point in the history
  • Loading branch information
arbrauns committed Jan 8, 2024
1 parent 3de60c6 commit 6387fff
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ fn main() {
src_dir: "vendored_parsers/tree-sitter-typescript-src/typescript/src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-vhdl",
src_dir: "vendored_parsers/tree-sitter-vhdl-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-xml",
src_dir: "vendored_parsers/tree-sitter-xml-src/tree-sitter-xml/src",
Expand Down
3 changes: 3 additions & 0 deletions sample_files/compare.expected
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ sample_files/typing_before.ml sample_files/typing_after.ml
sample_files/utf16_before.py sample_files/utf16_after.py
bbf22d2c5003b638c0f8d08f21bbbb66 -

sample_files/vhdl_before.vhd sample_files/vhdl_after.vhd
eb987aa621cfa733bb4fcd52b255fbbf -

sample_files/whitespace_before.tsx sample_files/whitespace_after.tsx
53017b74523e203817d64189142b26ed -

Expand Down
35 changes: 35 additions & 0 deletions sample_files/vhdl_after.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity blinky is
port (
clk: in std_logic;
led: out std_logic_vector(3 downto 0)
);
end entity;

architecture a of blinky is
constant CLK_FREQ: positive := 48_000_000;
signal counter1: unsigned(25 downto 0) := (others => '0');
signal counter2: unsigned(1 downto 0) := (others => '0');
begin
process(clk)
begin
if rising_edge(clk) then
if to_integer(counter1) = CLK_FREQ / 2 then
counter2 <= counter2 + 1;
counter1 <= (others => '0');
else
counter1 <= counter1 + 1;
end if;
end if;
end process;

process(counter2)
begin
for n in 0 to 3 loop
led(n) <= '1' when to_integer(counter2) = n else '0';
end loop;
end process;
end architecture;
27 changes: 27 additions & 0 deletions sample_files/vhdl_before.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity blinky is
port (
clk: in std_logic;
led: out std_logic
);
end entity;

architecture a of blinky is
constant CLK_FREQ: positive := 12_000_000;
signal counter: unsigned(23 downto 0) := (others => '0');
begin
process(clk)
begin
if rising_edge(clk) then
if to_integer(counter) = CLK_FREQ / 2 then
led <= not led;
counter <= (others => '0');
else
counter <= counter + 1;
end if;
end if;
end process;
end architecture;
4 changes: 4 additions & 0 deletions src/parse/guess_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub(crate) enum Language {
Toml,
TypeScript,
TypeScriptTsx,
Vhdl,
Xml,
Yaml,
Zig,
Expand Down Expand Up @@ -161,6 +162,7 @@ pub(crate) fn language_name(language: Language) -> &'static str {
Toml => "TOML",
TypeScript => "TypeScript",
TypeScriptTsx => "TypeScript TSX",
Vhdl => "VHDL",
Xml => "XML",
Yaml => "YAML",
Zig => "Zig",
Expand Down Expand Up @@ -352,6 +354,7 @@ pub(crate) fn language_globs(language: Language) -> Vec<glob::Pattern> {
],
TypeScript => &["*.ts"],
TypeScriptTsx => &["*.tsx"],
Vhdl => &["*.vhdl", "*.vhd"],
Xml => &[
"*.ant",
"*.csproj",
Expand Down Expand Up @@ -508,6 +511,7 @@ fn from_emacs_mode_header(src: &str) -> Option<Language> {
"toml" => Some(Toml),
"tuareg" => Some(OCaml),
"typescript" => Some(TypeScript),
"vhdl" => Some(Vhdl),
"yaml" => Some(Yaml),
"zig" => Some(Zig),
_ => None,
Expand Down
15 changes: 15 additions & 0 deletions src/parse/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ extern "C" {
fn tree_sitter_toml() -> ts::Language;
fn tree_sitter_tsx() -> ts::Language;
fn tree_sitter_typescript() -> ts::Language;
fn tree_sitter_vhdl() -> ts::Language;
fn tree_sitter_xml() -> ts::Language;
fn tree_sitter_yaml() -> ts::Language;
fn tree_sitter_zig() -> ts::Language;
Expand Down Expand Up @@ -1107,6 +1108,20 @@ pub(crate) fn from_language(language: guess::Language) -> TreeSitterConfig {
sub_languages: vec![],
}
}
Vhdl => {
let language = unsafe { tree_sitter_vhdl() };
TreeSitterConfig {
language,
atom_nodes: vec![].into_iter().collect(),
delimiter_tokens: vec![("(", ")")],
highlight_query: ts::Query::new(
language,
include_str!("../../vendored_parsers/highlights/vhdl.scm"),
)
.unwrap(),
sub_languages: vec![],
}
}
Zig => {
let language = unsafe { tree_sitter_zig() };
TreeSitterConfig {
Expand Down
1 change: 1 addition & 0 deletions vendored_parsers/highlights/vhdl.scm
1 change: 1 addition & 0 deletions vendored_parsers/tree-sitter-vhdl-src

0 comments on commit 6387fff

Please sign in to comment.