Skip to content

Commit 79e251b

Browse files
Ra77a3l3-jaralschena
authored andcommitted
Add tree-sitter support for BASIC and FreeBASIC (helix-editor#14711)
1 parent 8307199 commit 79e251b

File tree

10 files changed

+238
-0
lines changed

10 files changed

+238
-0
lines changed

book/src/generated/lang-support.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
| astro || | | | | `astro-ls` |
99
| awk ||| | | | `awk-language-server` |
1010
| bash |||||| `bash-language-server` |
11+
| basic ||||| | |
1112
| bass || | | | | `bass` |
1213
| beancount || | | | | `beancount-language-server` |
1314
| bibtex || | | | | `texlab` |
@@ -75,6 +76,7 @@
7576
| flatbuffers || | | | | |
7677
| forth || | | | | `forth-lsp` |
7778
| fortran || || | | `fortls` |
79+
| freebasic ||||| | |
7880
| fsharp || | | | | `fsautocomplete` |
7981
| gas ||| | | | `asm-lsp` |
8082
| gdscript ||||| | |

languages.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5027,3 +5027,27 @@ persistent-diagnostic-sources = ["haxe"]
50275027
[[grammar]]
50285028
name = "haxe"
50295029
source = { git = "https://github.com/vantreeseba/tree-sitter-haxe", rev = "a55f3e2cf1e4449200fd089a80d3af642bcf5f94" }
5030+
5031+
[[language]]
5032+
name = "basic"
5033+
scope = "source.basic"
5034+
injection-regex = "basic"
5035+
file-types = ["bas"]
5036+
comment-token = "REM"
5037+
indent = { tab-width = 2, unit = " " }
5038+
5039+
[[grammar]]
5040+
name = "basic"
5041+
source = { git = "https://github.com/Ra77a3l3-jar/tree-sitter-basic", rev = "a98449c11d6c688b54c1ca132148a62d7e586a2a" }
5042+
5043+
[[language]]
5044+
name = "freebasic"
5045+
scope = "source.freebasic"
5046+
injection-regex = "freebasic"
5047+
file-types = ["bas", "bi"]
5048+
comment-tokens = ["'", "REM"]
5049+
indent = { tab-width = 4, unit = " " }
5050+
5051+
[[grammar]]
5052+
name = "freebasic"
5053+
source = { git = "https://github.com/Ra77a3l3-jar/tree-sitter-freebasic", rev = "dbf696adb4c0b9c020074e75043c90592981ee7f" }
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
; Keywords
2+
[
3+
"PRINT"
4+
"LET"
5+
"IF"
6+
"THEN"
7+
"GOTO"
8+
"GOSUB"
9+
"RETURN"
10+
"FOR"
11+
"TO"
12+
"STEP"
13+
"NEXT"
14+
"INPUT"
15+
"END"
16+
"REM"
17+
"DATA"
18+
"READ"
19+
"DIM"
20+
] @keyword
21+
22+
; Logical operators
23+
[
24+
"AND"
25+
"and"
26+
"OR"
27+
"or"
28+
"NOT"
29+
] @keyword.operator
30+
31+
; Comments
32+
(comment) @comment
33+
(rem_statement) @comment
34+
35+
; Function calls
36+
(function_call) @function.call
37+
38+
; Numbers
39+
(line_number) @constant.numeric
40+
(number) @constant.numeric
41+
42+
; Strings
43+
(string) @string
44+
45+
; Operators
46+
[
47+
"="
48+
"<>"
49+
"<"
50+
">"
51+
"<="
52+
">="
53+
"+"
54+
"-"
55+
"*"
56+
"/"
57+
"^"
58+
] @operator
59+
60+
; Punctuation
61+
[
62+
"("
63+
")"
64+
] @punctuation.bracket
65+
66+
[
67+
","
68+
";"
69+
] @punctuation.delimiter
70+
71+
; Variables
72+
(identifier) @variable

runtime/queries/basic/indents.scm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
(for_statement)
3+
] @indent
4+
5+
[
6+
"NEXT"
7+
] @outdent

runtime/queries/basic/tags.scm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(for_statement
2+
variable: (identifier) @definition.variable)
3+
4+
(let_statement
5+
variable: (identifier) @definition.variable)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(for_statement) @function.around
2+
3+
(comment) @comment.inside
4+
(comment)+ @comment.around
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
; Keywords
2+
[
3+
"DIM"
4+
"IF"
5+
"THEN"
6+
"ELSE"
7+
"END IF"
8+
"WHILE"
9+
"WEND"
10+
"FOR"
11+
"TO"
12+
"STEP"
13+
"NEXT"
14+
"DO"
15+
"LOOP"
16+
"UNTIL"
17+
"SUB"
18+
"END SUB"
19+
"FUNCTION"
20+
"END FUNCTION"
21+
"RETURN"
22+
"PRINT"
23+
"INPUT"
24+
"SLEEP"
25+
"AS"
26+
] @keyword
27+
28+
; Logical operators
29+
[
30+
"AND"
31+
"OR"
32+
"NOT"
33+
"MOD"
34+
] @keyword.operator
35+
36+
; Types
37+
[
38+
"INTEGER"
39+
"LONG"
40+
"SINGLE"
41+
"DOUBLE"
42+
"STRING"
43+
"BYTE"
44+
] @type
45+
46+
(type_identifier) @type
47+
48+
; Function and sub declarations
49+
(sub_declaration
50+
name: (identifier) @function)
51+
(function_declaration
52+
name: (identifier) @function)
53+
54+
; Function calls
55+
(call_expression
56+
function: (identifier) @function.call)
57+
58+
; Built-in functions
59+
((identifier) @function.builtin
60+
(#match? @function.builtin "^(?i)(ABS|SIN|COS|TAN|SQR|LEN|VAL|ASC|CHR|LEFT|RIGHT|MID|STR|INT|RND|INSTR|UCASE|LCASE|LTRIM|RTRIM|SPACE|TIME|DATE|TIMER)$"))
61+
62+
; Literals
63+
(number_literal) @constant.numeric
64+
(string_literal) @string
65+
66+
; Comments
67+
(comment) @comment
68+
69+
; Operators
70+
[
71+
"="
72+
"+"
73+
"-"
74+
"*"
75+
"/"
76+
"^"
77+
"<>"
78+
"<"
79+
">"
80+
"<="
81+
">="
82+
] @operator
83+
84+
; Punctuation
85+
[
86+
"("
87+
")"
88+
] @punctuation.bracket
89+
90+
[
91+
","
92+
";"
93+
] @punctuation.delimiter
94+
95+
; Variables
96+
(identifier) @variable
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
(for_statement)
3+
(if_statement)
4+
(while_statement)
5+
(do_statement)
6+
(function_declaration)
7+
(sub_declaration)
8+
] @indent
9+
10+
[
11+
"NEXT"
12+
"END IF"
13+
"WEND"
14+
"LOOP"
15+
"END FUNCTION"
16+
"END SUB"
17+
] @outdent

runtime/queries/freebasic/tags.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(sub_declaration name: (identifier) @definition.function)
2+
3+
(function_declaration name: (identifier) @definition.function)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(function_declaration) @function.around
2+
3+
(sub_declaration) @function.around
4+
5+
(for_statement) @function.around
6+
7+
(comment) @comment.inside
8+
(comment)+ @comment.around

0 commit comments

Comments
 (0)