Tree-sitter grammar for SysML v2 and KerML textual notation per the OMG SysML v2.0 and KerML 1.0 specifications.
- Near-complete language coverage — parses all 213 official OMG example and training files plus 92 of 94 standard library files from the SysML-v2-Release repository with zero errors, and 165 of the 169 code listings in the SysML v2 Book (Weilkiens, 2026-05) — the remaining 4 are deliberate fragments/errata in the book itself
- Definitions — unified rule covering 40+ definition keywords (part, action, state, port, connection, attribute, item, requirement, constraint, view, calc, class, struct, type, function, and more)
- Usages — unified rule covering 20+ usage keywords, plus specialized rules for action, state, connection, interface, constraint, requirement, event, allocation, flow, metadata, binding, succession, and KerML usages
- Behavioral constructs — actions, states, transitions, control flow
(if/else-if/else, while/for with body and ref forms, typed for-loops with
1..nranges), terminate (with occurrence argument), inline transitions, send/accept withwhen/at/aftertriggers,do action send ... via ...transition effects, entry/do/exit actions with names and types, while-until loops, fork/join/merge/decide nodes, action chaining withthen(includingthen perform actionandthen include) - Relationships — specialization (
:>/specializes), redefinition (:>>/redefines), binding (::>), conjugation, chaining, crosses (=>),typed by/defined by,unions/intersects/differences,featuring by,disjoint from— all supporting comma-separated multiple targets - Connections — named binding/succession usages with multiplicity on endpoints,
multi-end connections with
crosses, end features with occurrence/action/flow qualifiers,::>bindings in parenthesized connect clauses - Expressions — arithmetic, logical, comparison, invocation with named
arguments (structured
named_argumentnodes) and qualified names, conditional,newexpressions, function-literal body expressions ({ in x; expr }) as call arguments and values,->collect/select/reduce arrows with bodies, invocations, and function references,.?{...}select,metaexpressions, classification operators@and@@, result expressions - Requirements —
assert/not satisfy,require constraint/requirementwith bodies, subject/actor/objective/stakeholder/frame declarations with full type relationship and multiplicity support - Metadata —
#prefix annotations with qualified names (also before body statements likeallocate), qualified metadata annotations with bodies (@Pkg::Def { ... }), structuredmetadata_bodywithredefines/:>>patterns,metadata ... aboutclause,member featuredeclarations - Variability —
variation/variantand all other modifiers are namedmodifierCST nodes, queryable for variant-aware tooling (Ch 35) - Standard library patterns — standalone multiplicity definitions, feature
qualifiers (
nonunique,ordered),defaultwith body values,bindstatements, standalone:>>redefines in bodies, quoted operator names - Views — render with rendering keyword and typing, expose, viewpoint frames
- Textual representation —
rep/languageblocks for embedding foreign code - Multiplicity with
ordered nonuniquein any order, flexible positioning between name, type, and specialization - Imports with recursive
**, packages with short names, barenamespace(KerML), dependencies with comma-separated targets, comments with multi-targetaboutandlocalesupport
- 198 corpus tests covering definitions, usages, expressions, control flow, connections, requirements, states, imports, packages, comments, and KerML extensions
- 213 official OMG files (examples, training, KerML) — all parse with zero errors
- 92/94 standard library files — near-complete coverage of the SysML v2 and KerML standard libraries (Kernel Semantic, Kernel Function, Domain, Systems)
The 2 remaining standard library files (Actions.sysml, Occurrences.kerml) use
inline action body chaining and complex end feature patterns that cannot be
added without exceeding tree-sitter's generator memory limits.
Pre-built binaries (Linux, macOS, Windows) and WASM artifacts are published automatically on each tagged release. See Releases.
Install the grammar:
(add-to-list 'treesit-language-source-alist
'(sysml "https://github.com/jackhale98/tree-sitter-sysml" nil "src"))
(treesit-install-language-grammar 'sysml)Then use sysml2-mode which automatically activates tree-sitter when the grammar is available.
Add to your nvim-treesitter config:
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.sysml = {
install_info = {
url = "https://github.com/jackhale98/tree-sitter-sysml",
files = {"src/parser.c"},
branch = "main",
},
filetype = "sysml",
}Copy queries/ to your editor's runtime queries directory as sysml/.
The grammar handles syntax; semantics (diagnostics, navigation, hover,
completions) come from
sysml-lsp, which embeds
this grammar. Per-editor setup for both pieces together:
Editor Setup.
npm install
npx tree-sitter generate
npx tree-sitter testnpx tree-sitter build --wasmmake emacs
cp tree-sitter-sysml.so ~/.emacs.d/tree-sitter/libtree-sitter-sysml.soqueries/highlights.scm— Syntax highlightingqueries/indents.scm— Indentationqueries/folds.scm— Code folding
.sysml— SysML v2 files.kerml— KerML files
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option (Apache-2.0 OR MIT).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work shall be dual licensed as above, without any additional terms or conditions.
The SysML v2 / KerML example models vendored under test/examples/ are
taken or adapted from the OMG
SysML-v2-Release
repository and remain under their original licence, the Eclipse Public
License 2.0 (EPL-2.0). They are test fixtures only: they are not part of the
published grammar package (package.json and Cargo.toml do not include
test/), and the dual licence above does not apply to them.