tree-sitter-macaulay2 6.3.2

Macaulay2 grammar for the tree-sitter parsing library
Documentation

tree-sitter-macaulay2

release crates docs.rs npm pypi license

Macaulay2 grammar for tree-sitter.

The parse tree follows the precedence and newline rules of Macaulay2's own parser; docs/macaulay2-parsing-precedence.md describes how they are modelled.

Queries

File Purpose
highlights.scm Syntax highlighting, see docs/highlight-queries.md
indents.scm Indentation
folds.scm Code folding
tags.scm Symbol tags for definitions and method installations
injections.scm Language injections

queries/macaulay2/ holds deprecated copies of the same files and will be removed in 7.x.

Usage

Rust

cargo add tree-sitter tree-sitter-macaulay2
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_macaulay2::language())?;
let tree = parser.parse("R = QQ[x, y]", None).unwrap();

Node.js

npm install tree-sitter tree-sitter-macaulay2
import Parser from "tree-sitter";
import Macaulay2 from "tree-sitter-macaulay2";

const parser = new Parser();
parser.setLanguage(Macaulay2);
const tree = parser.parse("R = QQ[x, y]");

Python

pip install tree-sitter tree-sitter-macaulay2
from tree_sitter import Language, Parser
import tree_sitter_macaulay2

parser = Parser(Language(tree_sitter_macaulay2.language()))
tree = parser.parse(b"R = QQ[x, y]")

All bindings also export the queries as HIGHLIGHTS_QUERY, INJECTIONS_QUERY, TAGS_QUERY, INDENTS_QUERY, and FOLDS_QUERY.

Neovim

The parser is not bundled with nvim-treesitter yet. With the master branch of nvim-treesitter, register it and the .m2 file type, then run :TSInstall macaulay2:

vim.filetype.add({ extension = { m2 = "macaulay2" } })

require("nvim-treesitter.parsers").get_parser_configs().macaulay2 = {
  install_info = {
    url = "https://github.com/AlexanderGolys/tree-sitter-macaulay2",
    files = { "src/parser.c", "src/scanner.c" },
  },
  filetype = "macaulay2",
}

Neovim reads queries from queries/macaulay2/ on the runtime path; add a clone of this repository to runtimepath to use them.

Development

npm install
npx tree-sitter generate   # regenerate src/ from grammar.js
npx tree-sitter test       # corpus and highlight tests
npm run build:wasm         # build tree-sitter-macaulay2.wasm

Part of the corpus is generated from Macaulay2's own parser; see CONTRIBUTING.md for that workflow and the full set of checks.

References

License

MIT