A tree sitter grammar for logstash
Go to file
Preston Baxter f257840fd8 Allow for empty strings 2024-01-29 13:32:34 -06:00
bindings init 2024-01-23 15:22:00 -06:00
docs Add image 2024-01-27 00:47:01 -06:00
node_modules init 2024-01-23 15:22:00 -06:00
queries Apply consitant prec like treetop would 2024-01-27 00:26:45 -06:00
src Allow for empty strings 2024-01-29 13:32:34 -06:00
tests add example logstash config 2024-01-27 00:37:57 -06:00
Cargo.toml init 2024-01-23 15:22:00 -06:00
README.md Update readme 2024-01-27 00:58:43 -06:00
binding.gyp init 2024-01-23 15:22:00 -06:00
grammar.js Allow for empty strings 2024-01-29 13:32:34 -06:00
logstash_orig_grammar.treetop init 2024-01-23 15:22:00 -06:00
package-lock.json init 2024-01-23 15:22:00 -06:00
package.json Add highlights and language deff 2024-01-23 22:41:20 -06:00

README.md

Tree Sitter Logstash

This is an implementation of the treetop logstash grammar for tree-sitter.

Notes

  • There are differences between treetop and tree-sitter. I have done my best to match tree top, however deviations may exist
  • This is good enough for syntax highlighting, I am working on using this as a config validator
  • nvim-treesitter expects a unqiue-ish filename, so unlike the logstash standard, this project expects logstash pipelines to have the .logastash file extension

Example

What highlighting of tests/example.logstash looks like

image of colored code

Neovim

nvim-treesitter has great instructions. Below is a walkthrough of their intrsuctions, but focused on tree-sitter-logstash

First clone the repo into a directory that can be referenced by neovim

mkdir -p ~/some/path
cd ~/some/path
git clone https://git.preston-baxter.com/Preston_PLB/tree-sitter-logstash.git

Add this to wherever you configure your nvim. I would recomend placing this where you load nvim-treesitter. In your lazy config for example. Creating a file in the after/ direcrtory is also fine.

    local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
    parser_config.logstash = {
      install_info = {
        url = "~/some/path/tree-sitter-logstash",
        files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc
        branch = "master",
      },
    }

    vim.filetype.add({
        extension = {
            logstash = "logstash"
        }
    })
    vim.treesitter.language.register("logstash", "logstash")

The block above tells nvim-treesitter where to find the logstash parser, defines the logstash file type, and registers that filetype to a treesitter parser

In vim now run

:TSInstall logstah

This will load the logstash parser into neovim. Now you need to link the syntax highlighting file to a place where neovim can find it.(See this for why)

mkdir -p ~/.config/nvim/queries/logstash
ln -s ~/some/path/queries/highlights.scm ~/.config/nvim/queries/logstash/highlights.scm

~/.config/nvim/queries/logstash/ can be replaced with any queries/logstash path in a nvim runtime directory

Now that all that is done. Load up neovim and open a logstash file