A tree-sitter grammar for LP (Linear Programming) files — the format used by CPLEX, Gurobi, PuLP, and other optimisation solvers.
Provides syntax highlighting, code folding, indentation, and local-variable queries for editors that support tree-sitter.
npm install # install dependencies
npm run build # generate the parser (tree-sitter generate)
npm test # run the test corpus
npm run parse -- FILE # parse a single .lp file
npm run format # format grammar.js with prettier
npm run format:check # check formatting without writingAdd the following to your Neovim configuration (e.g. init.lua or a ftdetect file) before any .lp file triggers tree-sitter:
-- Register the lp filetype and tree-sitter language
vim.filetype.add({ extension = { lp = 'lp' } })
vim.treesitter.language.register('lp', 'lp')
-- Point nvim-treesitter at the local grammar
local ok, parsers = pcall(require, 'nvim-treesitter.parsers')
if ok then
parsers.get_parser_configs().lp = {
install_info = {
url = '/path/to/tree-sitter-lp',
files = { 'src/parser.c' },
generate_requires_npm = false,
requires_generate_from_grammar = false,
},
filetype = 'lp',
}
endThen install the parser:
:TSInstall lpCopy the query files into your Neovim runtime so highlights, folds, and indents are picked up:
mkdir -p ~/.config/nvim/queries/lp
cp queries/*.scm ~/.config/nvim/queries/lp/An LP file has the following structure:
Minimize
obj: x1 + 2 x2 + 3 x3
Subject To
c1: x1 + x2 <= 10
c2: x2 + x3 >= 5
Bounds
0 <= x1 <= 40
x2 >= 0
Generals
x3
End
MIT