#tree-sitter #molecular-dynamics #incremental #parser #lammps

tree-sitter-lammps

lammps grammar for the tree-sitter parsing library

5 releases

0.0.8 Oct 13, 2024
0.0.6 Oct 10, 2024
0.0.5 Oct 8, 2024
0.0.4 Sep 23, 2024
0.0.3 Sep 23, 2024

#112 in Text editors

Download history 140/week @ 2024-09-17 206/week @ 2024-09-24 34/week @ 2024-10-01 477/week @ 2024-10-08 76/week @ 2024-10-15 5/week @ 2024-10-22

209 downloads per month
Used in lammps-analyser

MIT license

330KB
12K SLoC

C 12K SLoC // 0.0% comments JavaScript 377 SLoC // 0.2% comments Rust 35 SLoC // 0.4% comments Scheme 28 SLoC // 0.2% comments

Tree-Sitter LAMMPS

A tree-sitter parser for input scripts for the 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

Queries queries/*.scm

These files describe how the tree should be read and allows for syntax highlighting

Using with Neovim

  1. Install nvim-treesitter plugin to Neovim

  2. Add the following to your init.lua to define lammps file types:

    -- LAMMPS File type
    vim.filetype.add {
    extension = {
    lmp = 'lammps',
      },
    
      pattern = {
        -- These are lua matching patterns, not regex
        ['.*%.lmp'] = 'lammps',
        ['in%..*'] = 'lammps',
        ['.*%.in'] = 'lammps',
      },
    }
    
    
  3. Add the following to your init.lua to tell tree-sitter how to access this parser:

    
    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')
    
    
  4. run :TSInstallFromGrammar lammps to install the tree-sitter grammar.

  5. Copy the files from queries in this repo to a folder queries/lammps in the same directory as your init.lua

  6. Presto! Your LAMMPS input scripts should now have pretty colours

Dependencies

~2–285KB