Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e5e6ade

Browse files
ShalokShalomsammy-ette
andauthoredSep 26, 2023
feat: add Julia support (#47)
Co-authored-by: sammyette <torchedsammy@gmail.com>
1 parent b298b41 commit e5e6ade

File tree

3 files changed

+199
-1
lines changed

3 files changed

+199
-1
lines changed
 

‎README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ It is work in progress, but functions well.
2323
- [x] [go.mod][tree-sitter-go-mod]
2424
- [ ] HTML
2525
- [x] [Javascript/JSX][tree-sitter-javascript]
26+
- [x] [Julia][tree-sitter-julia]
2627
- [x] [Lua][tree-sitter-lua]
2728
- [x] [Rust][tree-sitter-rust]
2829
- [x] [Zig][tree-sitter-zig]
2930

3031
If you want more languages supported, open an issue.
3132

3233
# Requirements
33-
- Lite XL 2.1+
34+
- Lite XL 2.1+ or [Pragtical](https://github.com/pragtical/pragtical)
3435
- [ltreesitter](#ltreesitter-installation) (automatic, manually or via LuaRocks)
3536

3637
# Install
@@ -186,6 +187,7 @@ MIT
186187
[tree-sitter-go]: https://github.com/tree-sitter/tree-sitter-go
187188
[tree-sitter-go-mod]: https://github.com/camdencheek/tree-sitter-go-mod
188189
[tree-sitter-javascript]: https://github.com/tree-sitter/tree-sitter-javascript
190+
[tree-sitter-julia]: https://github.com/tree-sitter/tree-sitter-julia
189191
[tree-sitter-lua]: https://github.com/MunifTanjim/tree-sitter-lua
190192
[tree-sitter-rust]: https://github.com/tree-sitter/tree-sitter-rust
191193
[tree-sitter-zig]: https://github.com/maxxnino/tree-sitter-zig

‎languages.lua

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ M.extensionMappings = makeTbl {
2222
'go',
2323
'lua',
2424
['jsx,js'] = 'javascript',
25+
['jl'] = 'julia',
2526
['rs'] = 'rust',
2627
'zig'
2728
}
@@ -40,6 +41,7 @@ M.exts = {
4041
go = 'https://github.com/tree-sitter/tree-sitter-go',
4142
gomod = 'https://github.com/camdencheek/tree-sitter-go-mod',
4243
javascript = 'https://github.com/tree-sitter/tree-sitter-javascript',
44+
julia = 'https://github.com/tree-sitter/tree-sitter-julia',
4345
lua = 'https://github.com/MunifTanjim/tree-sitter-lua',
4446
rust = 'https://github.com/tree-sitter/tree-sitter-rust',
4547
zig = 'https://github.com/maxxnino/tree-sitter-zig'

‎queries/julia/highlights.scm

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
(identifier) @variable
2+
3+
(operator) @operator
4+
(range_expression ":" @operator)
5+
(pair_expression "=>" @operator)
6+
7+
;; In case you want type highlighting based on Julia naming conventions (this might collide with mathematical notation)
8+
;((identifier) @type ; exception: mark `A_foo` sort of identifiers as variables
9+
;(match? @type "^[A-Z][^_]"))
10+
((identifier) @constant
11+
(#match? @constant "^[A-Z][A-Z_]{2}[A-Z_]*$"))
12+
13+
(macro_identifier) @function.macro
14+
(macro_identifier (identifier) @function.macro) ; for any one using the variable highlight
15+
(macro_definition
16+
name: (identifier) @function.macro
17+
["macro" "end" @keyword])
18+
19+
(field_expression
20+
(identifier)
21+
(identifier) @field .)
22+
23+
(function_definition
24+
name: (identifier) @function)
25+
(call_expression
26+
(identifier) @function)
27+
(call_expression
28+
(field_expression (identifier) @method .))
29+
(broadcast_call_expression
30+
(identifier) @function)
31+
(broadcast_call_expression
32+
(field_expression (identifier) @method .))
33+
(parameter_list
34+
(identifier) @parameter)
35+
(parameter_list
36+
(optional_parameter .
37+
(identifier) @parameter))
38+
(typed_parameter
39+
(identifier) @parameter
40+
(identifier) @type)
41+
(type_parameter_list
42+
(identifier) @type)
43+
(typed_parameter
44+
(identifier) @parameter
45+
(parameterized_identifier) @type)
46+
(function_expression
47+
. (identifier) @parameter)
48+
(spread_parameter) @parameter
49+
(spread_parameter
50+
(identifier) @parameter)
51+
(named_argument
52+
. (identifier) @parameter)
53+
(argument_list
54+
(typed_expression
55+
(identifier) @parameter
56+
(identifier) @type))
57+
(argument_list
58+
(typed_expression
59+
(identifier) @parameter
60+
(parameterized_identifier) @type))
61+
62+
;; Symbol expressions (:my-wanna-be-lisp-keyword)
63+
(quote_expression
64+
(identifier)) @symbol
65+
66+
;; Parsing error! foo (::Type) gets parsed as two quote expressions
67+
(argument_list
68+
(quote_expression
69+
(quote_expression
70+
(identifier) @type)))
71+
72+
(type_argument_list
73+
(identifier) @type)
74+
(parameterized_identifier (_)) @type
75+
(argument_list
76+
(typed_expression . (identifier) @parameter))
77+
78+
(typed_expression
79+
(identifier) @type .)
80+
(typed_expression
81+
(parameterized_identifier) @type .)
82+
83+
(abstract_definition
84+
name: (identifier) @type)
85+
(struct_definition
86+
name: (identifier) @type)
87+
88+
(subscript_expression
89+
(_)
90+
(range_expression
91+
(identifier) @constant.builtin .)
92+
(#eq? @constant.builtin "end"))
93+
94+
"end" @keyword
95+
96+
(if_statement
97+
["if" "end"] @conditional)
98+
(elseif_clause
99+
["elseif"] @conditional)
100+
(else_clause
101+
["else"] @conditional)
102+
(ternary_expression
103+
["?" ":"] @conditional)
104+
105+
(function_definition ["function" "end"] @keyword.function)
106+
107+
[
108+
"abstract"
109+
"const"
110+
"macro"
111+
"primitive"
112+
"struct"
113+
"type"
114+
] @keyword
115+
116+
"return" @keyword.return
117+
118+
((identifier) @keyword (#any-of? @keyword "global" "local"))
119+
120+
(compound_expression
121+
["begin" "end"] @keyword)
122+
(try_statement
123+
["try" "end" ] @exception)
124+
(finally_clause
125+
"finally" @exception)
126+
(catch_clause
127+
"catch" @exception)
128+
(quote_statement
129+
["quote" "end"] @keyword)
130+
(let_statement
131+
["let" "end"] @keyword)
132+
(for_statement
133+
["for" "end"] @repeat)
134+
(while_statement
135+
["while" "end"] @repeat)
136+
(break_statement) @repeat
137+
(continue_statement) @repeat
138+
(for_clause
139+
"for" @repeat)
140+
(do_clause
141+
["do" "end"] @keyword)
142+
143+
"in" @keyword.operator
144+
145+
(export_statement
146+
["export"] @include)
147+
148+
(import_statement
149+
["import" "using"] @include)
150+
151+
(module_definition
152+
["module" "end"] @include)
153+
154+
((identifier) @include (#eq? @include "baremodule"))
155+
156+
157+
;;; Literals
158+
159+
(integer_literal) @number
160+
(float_literal) @float
161+
162+
((identifier) @float
163+
(#any-of? @float "NaN" "NaN16" "NaN32"
164+
"Inf" "Inf16" "Inf32"))
165+
166+
((identifier) @boolean
167+
(#any-of? @boolean "true" "false"))
168+
169+
((identifier) @constant.builtin
170+
(#any-of? @constant.builtin "nothing" "missing"))
171+
172+
(character_literal) @character
173+
(escape_sequence) @string.escape
174+
175+
(string_literal) @string
176+
(prefixed_string_literal
177+
prefix: (identifier) @function.macro) @string
178+
179+
(command_literal) @string
180+
(prefixed_command_literal
181+
prefix: (identifier) @function.macro) @string
182+
183+
[
184+
(line_comment)
185+
(block_comment)
186+
] @comment
187+
188+
;;; Punctuation
189+
190+
(quote_expression ":" @symbol)
191+
["::" "." "," "..."] @punctuation.delimiter
192+
["[" "]" "(" ")" "{" "}"] @punctuation.bracket
193+
194+
(ERROR) @error

0 commit comments

Comments
 (0)
Please sign in to comment.