on master help sign in
Add language support for ponylang (#5416)

See https://www.ponylang.io

commite65f28d41af0b095eb7ff340f20c7d0d4193e287 authorMatthias Wahl <mfelsche@users.noreply.github.com> dateWed 11 Jan 2023, 02:54 (4 years ago) parent3ca42f7
6 files changed+323
book/src/generated/lang-support.md+1 languages.toml+13 runtime/queries/ponylang/highlights.scm+176 runtime/queries/ponylang/indents.scm+32 runtime/queries/ponylang/locals.scm+37 runtime/queries/ponylang/textobjects.scm+64
book/src/generated/lang-support.md+1
@@ -93,6 +93,7 @@
9393| pascal | ✓ | ✓ | | `pasls` |
9494| perl | ✓ | ✓ | ✓ | |
9595| php | ✓ | ✓ | ✓ | `intelephense` |
96+| ponylang | ✓ | ✓ | ✓ | |
9697| prisma | ✓ | | | `prisma-language-server` |
9798| prolog | | | | `swipl` |
9899| protobuf | ✓ | | ✓ | |
languages.toml+13
@@ -2079,3 +2079,16 @@ indent = { tab-width = 2, unit = " " }
20792079[[grammar]]
20802080name = "matlab"
20812081source = { git = "https://github.com/mstanciu552/tree-sitter-matlab", rev = "2d5d3d5193718a86477d4335aba5b34e79147326" }
2082+
2083+[[language]]
2084+name = "ponylang"
2085+scope = "source.pony"
2086+file-types = ["pony"]
2087+injection-regex = "pony"
2088+roots = ["corral.json", "lock.json"]
2089+indent = { tab-width = 2, unit = " " }
2090+comment-token = "//"
2091+
2092+[[grammar]]
2093+name = "ponylang"
2094+source = { git = "https://github.com/mfelsche/tree-sitter-ponylang", rev = "ef66b151bc2604f431b5668fcec4747db4290e11" }
runtime/queries/ponylang/highlights.scmnew file+176
@@ -0,0 +1,176 @@
1+[
2+ (line_comment)
3+ (block_comment)
4+] @comment
5+
6+(bool) @constant.builtin.boolean
7+(integer) @constant.numeric.integer
8+(float) @constant.numeric.float
9+(character) @constant.character
10+
11+;; strings and docstring
12+(source_file docstring: (string) @string.special)
13+(entity docstring: (string) @string.special)
14+(method docstring: (string) @string.special) ; docstring for methods without body
15+(behavior docstring: (string) @string.special) ; docstring for methods without body
16+(constructor docstring: (string) @string.special) ; docstring for methods without body
17+(method body: (block . (string) @string.special)) ; docstring for methods with body
18+(behavior body: (block . (string) @string.special))
19+(constructor body: (block . (string) @string.special))
20+(field docstring: (string) @string.special)
21+(string) @string
22+
23+;; Punctuation
24+[
25+ "("
26+ ")"
27+ "{"
28+ "}"
29+ "["
30+ "]"
31+] @punctuation.bracket
32+[
33+ ";"
34+ "."
35+ ","
36+] @punctuation.delimiter
37+
38+(this) @variable.builtin
39+
40+(field name: (identifier) @variable.other.member)
41+
42+"use" @keyword.control.import
43+[
44+ "for"
45+ "in"
46+ "while"
47+ "do"
48+ "repeat"
49+ "until"
50+] @keyword.control.repeat
51+[
52+ "if"
53+ "ifdef"
54+ "iftype"
55+ "then"
56+ "elseif"
57+ "else"
58+ "match"
59+] @keyword.control.conditional
60+[
61+ "break"
62+ "continue"
63+ "return"
64+ "error"
65+ "compile_error"
66+ "compile_intrinsic"
67+] @keyword.control.return
68+[
69+ "recover"
70+ "consume"
71+ "end"
72+ "try"
73+ "with"
74+] @keyword.control
75+
76+[
77+ "as"
78+ "is"
79+ "isnt"
80+ "not"
81+ "and"
82+ "or"
83+ "xor"
84+ "digestof"
85+ "addressof"
86+ (location)
87+] @keyword.operator
88+
89+(entity_type) @keyword.storage.type
90+
91+[
92+ "var"
93+ "let"
94+ "embed"
95+] @keyword.storage
96+
97+[
98+ "fun"
99+ "be"
100+ "new"
101+] @keyword.function
102+
103+[
104+ (cap)
105+ (gencap)
106+ "where"
107+] @keyword
108+
109+[
110+ (partial)
111+ "=>"
112+ "~"
113+ ".>"
114+ "+"
115+ "-"
116+ "*"
117+ "/"
118+ "%"
119+ "%%"
120+ "+~"
121+ "-~"
122+ "/~"
123+ "*~"
124+ "%~"
125+ "%%~"
126+
127+ ">>"
128+ "<<"
129+ ">>~"
130+ "<<~"
131+
132+ "=="
133+ "!="
134+ ">"
135+ "<"
136+ ">="
137+ "<="
138+] @operator
139+
140+;; Types
141+(entity name: (identifier) @type)
142+(nominal_type name: (identifier) @type)
143+(typeparams (typeparam name: (identifier) @type))
144+
145+;; constructors / methods / behaviors
146+(constructor name: (identifier) @constructor)
147+(method name: (identifier) @function.method)
148+(behavior name: (identifier) @function.method)
149+
150+;; method calls
151+; TODO: be more specific about what is the actual function reference
152+(call callee: (field_access field: (identifier) @function.method))
153+(call callee: (_) @function.method)
154+(ffi_call name: (_) @function)
155+(partial_application function: (identifier) @function.method)
156+(chain function: (identifier) @function.method)
157+
158+;; fields and params
159+(field name: (identifier) @variable.other.member)
160+(param (identifier) @variable.parameter)
161+(lambdaparam (identifier) @variable.parameter)
162+
163+;; this.field is considered a member access
164+(field_access base: (this) field: (identifier) @variable.other.member)
165+
166+;; annotations
167+(annotations (identifier) @attribute)
168+
169+;; variables
170+;; references to upper case things are considered constructors
171+(
172+ (identifier) @constructor
173+ (#match @constructor "^[A-Z]")
174+)
175+(identifier) @variable
176+
runtime/queries/ponylang/indents.scmnew file+32
@@ -0,0 +1,32 @@
1+; queries for helix to do automatic indentation upon hitting enter
2+; TODO: needs more work, cover more cases
3+[
4+ (entity)
5+ (method)
6+ (behavior)
7+ (constructor)
8+ (block)
9+ (tuple)
10+ (grouped)
11+] @indent
12+(match_case body: (block) @indent)
13+; ffi_call and call
14+(_ arguments: (_) @indent)
15+(assignment right: (_) @indent
16+ (#set! "scope" "all")
17+)
18+
19+[
20+ (params)
21+ (object)
22+ ("if")
23+] @extend
24+(lambda params: (_) @extend)
25+
26+[
27+ "end"
28+ "}"
29+ "]"
30+ ")"
31+ "|"
32+] @outdent
runtime/queries/ponylang/locals.scmnew file+37
@@ -0,0 +1,37 @@
1+[
2+ (entity)
3+ (method)
4+ (behavior)
5+ (constructor)
6+ ("if")
7+ (elseif)
8+ (ifdef)
9+ (elseifdef)
10+ (iftype)
11+ (elseiftype)
12+ (match)
13+ (match_case)
14+ ("while")
15+ ("repeat")
16+ ("for")
17+ (lambda)
18+ (try_block)
19+ (with)
20+] @local.scope
21+(match else_block: (block) @local.scope)
22+(try_block else_block: (block) @local.scope)
23+(try_block then_block: (block) @local.scope)
24+(with else_block: (block) @local.scope)
25+
26+(field name: (identifier) @local.definition)
27+(local name: (identifier) @local.definition)
28+(param name: (identifier) @local.definition)
29+(lambdaparam name: (identifier) @local.definition)
30+("for" element: (idseq (identifier) @local.definition))
31+(withelem name: (idseq (identifier) @local.definition))
32+
33+; only lower case identifiers are references
34+(
35+ (identifier) @local.reference
36+ (#match? @local.reference "^[a-z_][a-zA-Z_]*")
37+)
runtime/queries/ponylang/textobjects.scmnew file+64
@@ -0,0 +1,64 @@
1+;; Queries for helix to select textobjects: https://docs.helix-editor.com/usage.html#textobjects
2+;; function.inside
3+;; function.around
4+;; class.inside
5+;; class.around
6+;; test.inside
7+;; test.around
8+;; parameter.inside
9+;; comment.inside
10+;; comment.around
11+
12+;; Queries for navigating using textobjects
13+
14+[
15+ (line_comment)
16+ (block_comment)
17+] @comment.inside
18+
19+(line_comment)+ @comment.around
20+(block_comment) @comment.around
21+
22+(entity members: (members)? @class.inside) @class.around
23+(object members: (members)? @class.inside) @class.around
24+
25+(method
26+ body: (block)? @function.inside
27+) @function.around
28+(behavior
29+ body: (block)? @function.inside
30+) @function.around
31+(constructor
32+ body: (block)? @function.inside
33+) @function.around
34+(lambda
35+ body: (block)? @function.inside
36+) @function.outside
37+
38+(params
39+ ((_) @parameter.inside . ","? @parameter.around) @parameter.around
40+)
41+(lambda
42+ params: ((_) @parameter.inside . ","? @parameter.around) @parameter.around
43+)
44+(typeargs
45+ ((_) @parameter.inside . ","? @parameter.around) @parameter.around
46+)
47+(typeparams
48+ ((_) @parameter.inside . ","? @parameter.around) @parameter.around
49+)
50+(arguments
51+ positional: (positional_args
52+ ((_) @parameter.inside . ","? @parameter.around)? @parameter.around)
53+ ; TODO: get named args right
54+ named: (named_args ((_) @parameter.inside . ","? @parameter.around)? @parameter.around)
55+)
56+
57+(
58+ (entity
59+ provides: (type (nominal_type name: (identifier) @_provides))
60+ members: (members) @test.inside
61+ ) @test.outside
62+ (#eq? @_provides "UnitTest")
63+)
64+