on master help sign in
Pascal support (#3542)
commit86a8ea57bb3cb651cf9bee3fd1ae37f7e134c526 authorath3 <45574139+ath3@users.noreply.github.com> dateFri 26 Aug 2022, 00:59 (4 years ago) parentf0fb340
5 files changed+409
book/src/generated/lang-support.md+1 languages.toml+14 runtime/queries/pascal/highlights.scm+382 runtime/queries/pascal/injections.scm+2 runtime/queries/pascal/textobjects.scm+10
book/src/generated/lang-support.md+1
@@ -76,6 +76,7 @@
7676| odin | ✓ | | | `ols` |
7777| openscad | ✓ | | | `openscad-language-server` |
7878| org | ✓ | | | |
79+| pascal | ✓ | ✓ | | `pasls` |
7980| perl | ✓ | ✓ | ✓ | |
8081| php | ✓ | ✓ | ✓ | `intelephense` |
8182| prisma | ✓ | | | `prisma-language-server` |
languages.toml+14
@@ -1691,3 +1691,17 @@ roots = ["edgedb.toml"]
16911691[[grammar]]
16921692name ="esdl"
16931693source = { git = "https://github.com/greym0uth/tree-sitter-esdl", rev = "b840c8a8028127e0a7c6e6c45141adade2bd75cf" }
1694+
1695+[[language]]
1696+name = "pascal"
1697+scope = "source.pascal"
1698+injection-regex = "pascal"
1699+file-types = ["pas", "pp", "inc", "lpr", "lfm"]
1700+roots = []
1701+comment-token = "//"
1702+indent = { tab-width = 2, unit = " " }
1703+language-server = { command = "pasls", args = [] }
1704+
1705+[[grammar]]
1706+name = "pascal"
1707+source = { git = "https://github.com/Isopod/tree-sitter-pascal", rev = "2fd40f477d3e2794af152618ccfac8d92eb72a66" }
runtime/queries/pascal/highlights.scmnew file+382
@@ -0,0 +1,382 @@
1+; -- Identifier type inferrence
2+
3+; VERY QUESTIONABLE: Highlighting of identifiers based on spelling
4+(exprBinary ((identifier) @constant
5+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
6+(exprUnary ((identifier) @constant
7+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
8+(assignment rhs: ((identifier) @constant
9+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
10+(exprBrackets ((identifier) @constant
11+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
12+(exprParens ((identifier) @constant
13+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
14+(exprDot rhs: ((identifier) @constant
15+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
16+(exprTpl args: ((identifier) @constant
17+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
18+(exprArgs ((identifier) @constant
19+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
20+(declEnumValue ((identifier) @constant
21+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
22+(defaultValue ((identifier) @constant
23+ (#match? @constant "^[A-Z][A-Z0-9_]+$|^[a-z]{2,3}[A-Z].+$")))
24+
25+; -- Break, Continue & Exit
26+; (Not ideal: ideally, there would be a way to check if these special
27+; identifiers are shadowed by a local variable)
28+(statement ((identifier) @keyword.control.return
29+ (#match? @keyword.control.return "^[eE][xX][iI][tT]$")))
30+(statement (exprCall entity: ((identifier) @keyword.control.return
31+ (#match? @keyword.control.return "^[eE][xX][iI][tT]$"))))
32+(statement ((identifier) @keyword.control.repeat
33+ (#match? @keyword.control.repeat "^[bB][rR][eE][aA][kK]$")))
34+(statement ((identifier) @keyword.control.repeat
35+ (#match? @keyword.control.repeat "^[cC][oO][nN][tT][iI][nN][uU][eE]$")))
36+
37+; -- Heuristic for procedure/function calls without parentheses
38+; (If a statement consists only of an identifier, assume it's a procedure)
39+; (This will still not match all procedure calls, and also may produce false
40+; positives in rare cases, but only for nonsensical code)
41+
42+(statement (exprDot rhs: (exprTpl entity: (identifier) @function)))
43+(statement (exprTpl entity: (identifier) @function))
44+(statement (exprDot rhs: (identifier) @function))
45+(statement (identifier) @function)
46+
47+; -- Procedure name in calls with parentheses
48+; (Pascal doesn't require parentheses for procedure calls, so this will not
49+; detect all calls)
50+
51+(inherited) @function
52+
53+; foo.bar<t>
54+(exprCall entity: (exprDot rhs: (exprTpl entity: (identifier) @function)))
55+; foo.bar
56+(exprCall entity: (exprDot rhs: (identifier) @function))
57+; foobar<t>
58+(exprCall entity: (exprTpl entity: (identifier) @function))
59+; foobar
60+(exprCall entity: (identifier) @function)
61+
62+; -- Fields
63+
64+(declSection (declVars (declVar name:(identifier) @variable.other.member)))
65+(declSection (declField name:(identifier) @variable.other.member))
66+(declClass (declField name:(identifier) @variable.other.member))
67+(exprDot rhs: (exprDot) @variable.other.member)
68+(exprDot rhs: (identifier) @variable.other.member)
69+
70+(recInitializerField name:(identifier) @variable.other.member)
71+
72+; -- Variable & constant declarations
73+; (This is only questionable because we cannot detect types of identifiers
74+; declared in other units, so the results will be inconsistent)
75+
76+(declVar name: (identifier) @variable)
77+(declConst name: (identifier) @constant)
78+(declEnumValue name: (identifier) @constant)
79+
80+; -- Constant usage
81+
82+[
83+ (caseLabel)
84+ (label)
85+] @constant
86+
87+(procAttribute (identifier) @constant)
88+(procExternal (identifier) @constant)
89+
90+; -- Type usage
91+
92+(typeref) @type
93+
94+; -- Exception parameters
95+
96+(exceptionHandler variable: (identifier) @variable.parameter)
97+
98+; -- Template parameters
99+
100+(genericArg type: (typeref) @type)
101+(genericArg name: (identifier) @variable.parameter)
102+
103+(declProc name: (genericDot lhs: (identifier) @type))
104+(declType (genericDot (identifier) @type))
105+
106+(genericDot (genericTpl (identifier) @type))
107+(genericDot (genericDot (identifier) @type))
108+
109+(genericTpl entity: (genericDot (identifier) @type))
110+(genericTpl entity: (identifier) @type)
111+
112+; -- Function parameters
113+
114+(declArg name: (identifier) @variable.parameter)
115+
116+; Treat property declarations like functions
117+
118+(declProp name: (identifier) @function)
119+(declProp getter: (identifier) @variable.other.member)
120+(declProp setter: (identifier) @variable.other.member)
121+
122+; -- Procedure & function declarations
123+
124+; foo.bar<t>
125+(declProc name: (genericDot rhs: (genericTpl entity: (identifier) @function)))
126+; foo.bar
127+(declProc name: (genericDot rhs: (identifier) @function))
128+; foobar<t>
129+(declProc name: (genericTpl entity: (identifier) @function))
130+; foobar
131+(declProc name: (identifier) @function)
132+
133+; -- Type declaration
134+
135+(declType name: (genericTpl entity: (identifier) @type))
136+(declType name: (identifier) @type)
137+
138+; -- Comments
139+
140+(comment) @comment
141+(pp) @function.macro
142+
143+; -- Variables
144+
145+(exprBinary (identifier) @variable)
146+(exprUnary (identifier) @variable)
147+(assignment (identifier) @variable)
148+(exprBrackets (identifier) @variable)
149+(exprParens (identifier) @variable)
150+(exprDot (identifier) @variable)
151+(exprTpl (identifier) @variable)
152+(exprArgs (identifier) @variable)
153+(defaultValue (identifier) @variable)
154+
155+; -- Literals
156+
157+(literalNumber) @constant.builtin.numeric
158+(literalString) @string
159+
160+; -- Builtin constants
161+
162+[
163+ (kTrue)
164+ (kFalse)
165+] @constant.builtin.boolean
166+
167+[
168+ (kNil)
169+] @constant.builtin
170+
171+; -- Punctuation & operators
172+
173+[
174+ (kOr)
175+ (kXor)
176+ (kDiv)
177+ (kMod)
178+ (kAnd)
179+ (kShl)
180+ (kShr)
181+ (kNot)
182+ (kIs)
183+ (kAs)
184+ (kIn)
185+] @keyword.operator
186+
187+[
188+ (kDot)
189+ (kAdd)
190+ (kSub)
191+ (kMul)
192+ (kFdiv)
193+ (kAssign)
194+ (kAssignAdd)
195+ (kAssignSub)
196+ (kAssignMul)
197+ (kAssignDiv)
198+ (kEq)
199+ (kLt)
200+ (kLte)
201+ (kGt)
202+ (kGte)
203+ (kNeq)
204+ (kAt)
205+ (kHat)
206+] @operator
207+
208+[
209+ ".."
210+] @punctuation.special
211+
212+[
213+ ";"
214+ ","
215+ ":"
216+ (kEndDot)
217+] @punctuation.delimiter
218+
219+[
220+ "("
221+ ")"
222+ "["
223+ "]"
224+] @punctuation.bracket
225+
226+; -- Attributes
227+
228+(procAttribute (kPublic) @attribute)
229+
230+[
231+ (kDefault)
232+ (kIndex)
233+ (kNodefault)
234+ (kStored)
235+
236+ (kStatic)
237+ (kVirtual)
238+ (kAbstract)
239+ (kSealed)
240+ (kDynamic)
241+ (kOverride)
242+ (kOverload)
243+ (kReintroduce)
244+ (kInline)
245+
246+ (kForward)
247+
248+ (kStdcall)
249+ (kCdecl)
250+ (kCppdecl)
251+ (kPascal)
252+ (kRegister)
253+ (kMwpascal)
254+ (kExternal)
255+ (kName)
256+ (kMessage)
257+ (kDeprecated)
258+ (kExperimental)
259+ (kPlatform)
260+ (kUnimplemented)
261+ (kCvar)
262+ (kExport)
263+ (kFar)
264+ (kNear)
265+ (kSafecall)
266+ (kAssembler)
267+ (kNostackframe)
268+ (kInterrupt)
269+ (kNoreturn)
270+ (kIocheck)
271+ (kLocal)
272+ (kHardfloat)
273+ (kSoftfloat)
274+ (kMs_abi_default)
275+ (kMs_abi_cdecl)
276+ (kSaveregisters)
277+ (kSysv_abi_default)
278+ (kSysv_abi_cdecl)
279+ (kVectorcall)
280+ (kVarargs)
281+ (kWinapi)
282+ (kAlias)
283+ (kDelayed)
284+
285+ (rttiAttributes)
286+ (procAttribute)
287+
288+] @attribute
289+
290+; -- Keywords
291+[
292+ (kProgram)
293+ (kLibrary)
294+ (kUnit)
295+ (kUses)
296+
297+ (kBegin)
298+ (kEnd)
299+ (kAsm)
300+
301+ (kVar)
302+ (kThreadvar)
303+ (kConst)
304+ (kResourcestring)
305+ (kConstref)
306+ (kOut)
307+ (kType)
308+ (kLabel)
309+ (kExports)
310+
311+ (kAbsolute)
312+
313+ (kProperty)
314+ (kRead)
315+ (kWrite)
316+ (kImplements)
317+
318+ (kClass)
319+ (kInterface)
320+ (kObject)
321+ (kRecord)
322+ (kObjcclass)
323+ (kObjccategory)
324+ (kObjcprotocol)
325+ (kArray)
326+ (kFile)
327+ (kString)
328+ (kSet)
329+ (kOf)
330+ (kHelper)
331+ (kPacked)
332+
333+ (kInherited)
334+
335+ (kGeneric)
336+ (kSpecialize)
337+
338+ (kFunction)
339+ (kProcedure)
340+ (kConstructor)
341+ (kDestructor)
342+ (kOperator)
343+ (kReference)
344+
345+ (kInterface)
346+ (kImplementation)
347+ (kInitialization)
348+ (kFinalization)
349+
350+ (kPublished)
351+ (kPublic)
352+ (kProtected)
353+ (kPrivate)
354+ (kStrict)
355+ (kRequired)
356+ (kOptional)
357+
358+ (kTry)
359+ (kExcept)
360+ (kFinally)
361+ (kRaise)
362+ (kOn)
363+ (kCase)
364+ (kWith)
365+ (kGoto)
366+] @keyword
367+
368+[
369+ (kFor)
370+ (kTo)
371+ (kDownto)
372+ (kDo)
373+ (kWhile)
374+ (kRepeat)
375+ (kUntil)
376+] @keyword.control.repeat
377+
378+[
379+ (kIf)
380+ (kThen)
381+ (kElse)
382+] @keyword.control.conditional
runtime/queries/pascal/injections.scmnew file+2
@@ -0,0 +1,2 @@
1+((comment) @injection.content
2+ (#set! injection.language "comment"))
runtime/queries/pascal/textobjects.scmnew file+10
@@ -0,0 +1,10 @@
1+
2+(declType (declClass (declSection) @class.inside)) @class.around
3+
4+(defProc body: (_) @function.inside) @function.around
5+
6+(declArgs (_) @parameter.inside) @parameter.around
7+(exprArgs (_) @parameter.inside) @parameter.around
8+
9+(comment) @comment.inside
10+(comment)+ @comment.around