Skip to content

Commit 413006c

Browse files
committed
Example of adding an extra language
Signed-off-by: Jiri Tyr <jiri.tyr@gmail.com>
1 parent c612aee commit 413006c

6 files changed

Lines changed: 138 additions & 2 deletions

File tree

m4.include/mc-with-tree-sitter.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ AC_DEFUN([mc_WITH_TREE_SITTER], [
4848
AC_SUBST([TREE_SITTER_GRAMMAR_LIBDIR])
4949
5050
dnl Known grammar directory names (must match download-grammars.sh)
51-
all_ts_grammars="ada asm awk bash bison c caddy cmake cobol cpp c_sharp css cuda d diff dockerfile dot erlang fortran glsl go haskell hcl html idl ini java javascript json kotlin lisp lua make markdown markdown_inline matlab meson muttrc ocaml pascal perl php po properties proto python r ruby rust scala smalltalk sql strace swift tcl toml turtle typescript verilog vhdl xml yaml"
51+
all_ts_grammars="ada asm awk bash bison c caddy cmake cobol cpp c_sharp css cuda d diff dockerfile dot erlang fortran glsl go haskell hcl html idl ini java javascript json kotlin lisp lua make markdown markdown_inline matlab meson muttrc ocaml pascal perl php po properties proto python qmljs r ruby rust scala smalltalk sql strace swift tcl toml turtle typescript verilog vhdl xml yaml"
5252
5353
dnl Grammars that have scanner.c
54-
ts_scanner_c="awk bash bison caddy cmake cobol cpp c_sharp css cuda d dockerfile fortran haskell hcl html javascript kotlin lua markdown markdown_inline matlab ocaml perl php properties python r ruby rust scala tcl toml typescript xml yaml"
54+
ts_scanner_c="awk bash bison caddy cmake cobol cpp c_sharp css cuda d dockerfile fortran haskell hcl html javascript kotlin lua markdown markdown_inline matlab ocaml perl php properties python qmljs r ruby rust scala tcl toml typescript xml yaml"
5555
5656
dnl Grammars that have scanner.cc (C++ scanner)
5757
ts_scanner_cc="sql"

misc/syntax-ts/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ QUERYFILES = \
4747
queries/properties-highlights.scm \
4848
queries/proto-highlights.scm \
4949
queries/python-highlights.scm \
50+
queries/qmljs-highlights.scm \
5051
queries/r-highlights.scm \
5152
queries/ruby-highlights.scm \
5253
queries/rust-highlights.scm \

misc/syntax-ts/grammars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ file \.(po|pot)$ po PO\ Translation
7777
file \.(properties)$ properties Java\ Properties
7878
file \.(proto)$ proto Protocol\ Buffers
7979
file \.(py|pyw|pyi)$ python Python\ Program
80+
file \.(qml)$ qmljs QML
8081
file \.(r|R|Rmd)$ r R\ Program
8182
file \.(rb|rake|gemspec|Rakefile|Gemfile)$ ruby Ruby\ Program
8283
file \.(rs)$ rust Rust\ Program
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
;; Tree-sitter highlight queries for QML (Qt Modeling Language)
2+
;; Based on JavaScript/TypeScript syntax with QML extensions.
3+
4+
;; QML keywords -> yellow
5+
[
6+
"import"
7+
"pragma"
8+
"component"
9+
"property"
10+
"signal"
11+
"required"
12+
"readonly"
13+
"default"
14+
"on"
15+
] @keyword
16+
17+
;; JS/TS keywords -> yellow
18+
[
19+
"if"
20+
"else"
21+
"for"
22+
"while"
23+
"switch"
24+
"case"
25+
"break"
26+
"continue"
27+
"return"
28+
"function"
29+
"var"
30+
"let"
31+
"const"
32+
"class"
33+
"enum"
34+
"new"
35+
"delete"
36+
"typeof"
37+
"instanceof"
38+
"in"
39+
"of"
40+
"try"
41+
"catch"
42+
"finally"
43+
"throw"
44+
"async"
45+
"await"
46+
"yield"
47+
"export"
48+
"void"
49+
"with"
50+
] @keyword
51+
52+
;; Named keyword nodes -> yellow
53+
(this) @keyword
54+
(super) @keyword
55+
56+
;; Boolean and null literals -> brightgreen
57+
[
58+
(true)
59+
(false)
60+
(null)
61+
(undefined)
62+
] @number.builtin
63+
64+
;; Number literals -> brightgreen
65+
(number) @number.builtin
66+
67+
;; Strings -> green
68+
(string) @string
69+
(template_string) @string
70+
71+
;; Regex -> brightgreen
72+
(regex) @string.special
73+
74+
;; Comments -> brown
75+
(comment) @comment
76+
77+
;; Type annotations -> yellow
78+
(type_identifier) @type
79+
80+
;; Operators -> yellow
81+
[
82+
"="
83+
"+="
84+
"-="
85+
"*="
86+
"/="
87+
"%="
88+
"+"
89+
"-"
90+
"*"
91+
"/"
92+
"%"
93+
"=="
94+
"==="
95+
"!="
96+
"!=="
97+
"<"
98+
">"
99+
"<="
100+
">="
101+
"&&"
102+
"||"
103+
"!"
104+
"?"
105+
":"
106+
"."
107+
] @operator.word
108+
109+
;; Arrow -> brightcyan
110+
"=>" @operator
111+
112+
;; Semicolons -> brightmagenta
113+
";" @delimiter.special
114+
115+
;; Delimiters -> brightcyan
116+
[
117+
","
118+
"("
119+
")"
120+
"["
121+
"]"
122+
"{"
123+
"}"
124+
] @delimiter

src/editor/ts-grammars/download-grammars.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ download smalltalk tom95 tree-sitter-smalltalk f5d63d37ebb135f
271271
# strace — pinned to commit 2025-01-14
272272
download strace sigmaSd tree-sitter-strace ac874ddfcc08d689fee1f4533789e06d88388f29
273273

274+
# qmljs (Qt QML) — pinned to tag 0.3.0
275+
download qmljs yuja tree-sitter-qmljs 0.3.0
276+
download_extra qmljs yuja tree-sitter-qmljs 0.3.0 src/typescript-scanner.h
277+
274278
# turtle (RDF Turtle) — pinned to commit 2024-10-09
275279
download turtle GordianDziwis tree-sitter-turtle 7f789ea7ef765080f71a298fc96b7c957fa24422
276280

src/editor/ts-grammars/ts-grammar-registry.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ extern const TSLanguage *tree_sitter_proto (void);
157157
#ifdef HAVE_GRAMMAR_PYTHON
158158
extern const TSLanguage *tree_sitter_python (void);
159159
#endif
160+
#ifdef HAVE_GRAMMAR_QMLJS
161+
extern const TSLanguage *tree_sitter_qmljs (void);
162+
#endif
160163
#ifdef HAVE_GRAMMAR_R
161164
extern const TSLanguage *tree_sitter_r (void);
162165
#endif
@@ -354,6 +357,9 @@ static const ts_grammar_entry_static_t ts_grammar_registry[] = {
354357
#ifdef HAVE_GRAMMAR_PYTHON
355358
{ "python", tree_sitter_python },
356359
#endif
360+
#ifdef HAVE_GRAMMAR_QMLJS
361+
{ "qmljs", tree_sitter_qmljs },
362+
#endif
357363
#ifdef HAVE_GRAMMAR_R
358364
{ "r", tree_sitter_r },
359365
#endif

0 commit comments

Comments
 (0)