- JavaScript 94.6%
- Scheme 5.4%
| bindings | ||
| queries | ||
| src | ||
| test/corpus | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| binding.gyp | ||
| Cargo.toml | ||
| CMakeLists.txt | ||
| go.mod | ||
| grammar.js | ||
| LICENSE | ||
| Makefile | ||
| package.json | ||
| Package.swift | ||
| pyproject.toml | ||
| README.md | ||
| setup.py | ||
| tree-sitter.json | ||
| uv.lock | ||
Introduction
When I was exploring my options for modding Stellaris I made some conclusions, one of which was that I wanted all sorts of things that boiled down to "merge with less bullshit". mergiraf can do nice merging, but I need a tree-sitter grammar for the language they use. That is PDXScript, which has no formal syntax definition and while there are some bespoke tools for working with it (the most well-known is cwtools) they don't define a grammar in a way I can use for this. So I have to make one myself.
Current state
Workability
It parses pdxscript-based objects well enough, I tested a few 3-way merges of ascension perks of popular mods in mergiraf. It'll be really irritating to use for highlighting as it doesn't have a very good idea of what things are keywords inside of known classes (e.g. ai_weight, triggered_modifier). This is also why it is palatable for trivial merge cases (e.g. weird adds, order changes or stacked variable changes are no problem) but currently isn't capable of processing merges in files that add two "identical" "variables". One such case is on_enabled inside of ascension perks. I'm pretty sure that you can have more than one, but it doesn't work very well for that right now.
Language definition for mergiraf
If you want to give it a try, this is the language definition I used for mergiraf:
LangProfile {
name: "PDXScript",
alternate_names: &["pdx", "pdxscript"],
extensions: vec!["txt"],
file_names: vec![],
language: tree_sitter_pdxscript::LANGUAGE.into(),
atomic_nodes: vec![],
commutative_parents: vec![
CommutativeParent::new("block", "{", "", "}"),
CommutativeParent::without_delimiters("source_file", "\n"),
],
signatures: vec![signature("variable_definition", vec![vec![Field("name")]])],
injections: None,
flattened_nodes: &[],
comment_nodes: &[],
},
You will also need to add something like this (under [dependencies]) to mergiraf's Cargo.toml:
tree-sitter-pdxscript = { git = "https://git.sr.ht/~canteen/tree-sitter-pdxscript" }
If you make local changes or something like that I'm pretty sure you can make it look at a directory too. That's all outlined in the cargo reference.
Plans
- Add keywords to parser
- Make mergiraf not break on multiple on_enabled keys
- Make a proper merge request so this gets added to mergiraf
I want to add keywords to the parser and make it so that mergiraf is more chill with them or merges the contents of blocks under identical keywords. Can't imagine it isn't already capable of doing so, I probably just fucked it up somehow.