Skip to content

About

Haxe hxml tree-sitter grammar

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

tree-sitter-hxml

test

A tree-sitter grammar for haxe hxml files.

Haxe grammar: https://github.com/tong/tree-sitter-haxe/

Grammar Support

  • Haxe 4.3 and 5 options, including deprecated single-dash aliases (-cp, -lib, -main, ...)
  • All compilation targets (--js, --cpp, --hl, ...) and custom targets
  • Library dependencies with versions (--library lib:1.2.3)
  • Defines with values (-D key=value)
  • Resource embedding (--resource file@name)
  • Macro execution (--macro expr), injected as haxe
  • --next sections and --run arguments
  • Server configurations (--connect, --server-listen)
  • Unknown options parse as unknown_option instead of an error

Values follow the haxe compiler: an option's value is the rest of the line, so it may contain spaces and #. Only lines starting with # are comments.

Queries

Query Purpose
highlights.scm Syntax highlighting, using Neovim capture names
injections.scm Haxe in --macro expressions, comment in comments
folds.scm Folds each section (the first one and every --next)
tags.scm Classes, defines, libraries, included files and resources

Highlighting --macro expressions needs the haxe parser installed as well.

Neovim

hxml is not bundled with nvim-treesitter, so register it as a custom parser (main branch):

vim.api.nvim_create_autocmd("User", {
  pattern = "TSUpdate",
  callback = function()
    require("nvim-treesitter.parsers").hxml = {
      install_info = {
        url = "https://github.com/tong/tree-sitter-hxml",
        queries = "queries",
      },
    }
  end,
})

vim.api.nvim_create_autocmd("FileType", {
  pattern = "hxml",
  callback = function() vim.treesitter.start() end,
})

Then run :TSInstall hxml. Neovim detects the hxml filetype by default.

Node

import Parser from "tree-sitter";
import Hxml from "tree-sitter-hxml";

const parser = new Parser();
parser.setLanguage(Hxml);
const tree = parser.parse("-p src\n-m Main\n--interp\n");

The binding also exports HIGHLIGHTS_QUERY, INJECTIONS_QUERY, TAGS_QUERY and nodeTypeInfo.

Examples

See the examples/ directory for comprehensive hxml configurations covering various use cases.

Development

# Install dependencies
npm install

# Generate the parser, commit the changes in src/ (CI checks they are up to date)
npx tree-sitter generate

# Run grammar and highlight tests
npx tree-sitter test

# Run node binding tests
npm test

# Test examples, including tags and injections queries
./test-examples.sh

If npx tree-sitter fails because the CLI binary is missing (npm may skip its install script), download it manually:

node node_modules/tree-sitter-cli/install.js

About

Haxe hxml tree-sitter grammar

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages