# Tree-Sitter LAMMPS
A [tree-sitter](https://github.com/tree-sitter/tree-sitter) parser for input scripts for the [LAMMPS](https://github.com/lammps/lammps) molecular dynamics simulations package.
## Tree-sitter
### Grammar: `grammar.js`
This file contains code that is transpiled to the parser.
It is a DSL that is described in the [tree-sitter docs](https://tree-sitter.github.io/tree-sitter/creating-parsers)
### Queries `queries/*.scm`
These files describe how the tree should be read and allows for
syntax highlighting
## Using with Neovim
1. Install [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) plugin to Neovim
2. Add the following to your `init.lua` to define lammps file types:
``` lua
-- LAMMPS File type
vim.filetype.add {
extension = {
lmp = 'lammps',
},
pattern = {
-- These are lua matching patterns, not regex
['.*%.lmp'] = 'lammps',
['in%..*'] = 'lammps',
['.*%.in'] = 'lammps',
},
}
```
4. Add the following to your `init.lua` to tell tree-sitter how
to access this parser:
``` lua
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
parser_config.lammps = {
install_info = {
url = 'https://github.com/chappertron/tree-sitter-lammps', -- local path or git repo
files = { 'src/parser.c', 'src/scanner.c' }, -- note that some parsers also require src/scanner.c or src/scanner.cc
-- optional entries:
branch = 'main', -- default branch in case of git repo if different from master
generate_requires_npm = false, -- if stand-alone parser without npm dependencies
requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
},
filetype = 'lammps', -- if filetype does not match the parser name
}
vim.treesitter.language.register('lammps', 'lammps')
```
6. run `:TSInstallFromGrammar lammps` to install the tree-sitter grammar.
7. Copy the files from `queries` in this repo to a folder `queries/lammps`
in the same directory as your `init.lua`
8. Presto! Your LAMMPS input scripts should now have pretty
colours