Skip to content

Commit

Permalink
feat: add Ursa support
Browse files Browse the repository at this point in the history
closes #9
  • Loading branch information
RubixDev committed Sep 24, 2023
1 parent d2728cb commit 9456104
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ once_cell = "1.18.0"
rustc_version = "0.4.0"
serde = "1.0.188"
strum = "0.25.0"
tft = { version = "0.1.0", default-features = false }
tft = { version = "0.1.1", default-features = false }
thiserror = "1.0.48"
toml = "0.8.0"

Expand Down
39 changes: 39 additions & 0 deletions examples/example_programs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -968,3 +968,42 @@ license.workspace = true
repository.workspace = true
description = "Modern and easy syntax highlighting using tree-sitter"
'''

ursa = '''
print("hello, woods!")
let fac = null
fn fac(x) {
if x == 0 {1} else {x * fac(x - 1)}
}
fac(6)
let sum = fn(l) {
let tot = 0
let i = 0
loop {
if i == l.length { return tot }
tot = tot + l[i]
i = i + 1
}
}
sum([10, 30, 50, 5, 5])
let newAccums = fn() {
let tot = 0
[
fn(x) {
tot = tot + x
},
fn(x) {
tot = tot + x
},
]
}
let accums = newAccums()
let accums2 = newAccums()
[
[accums[0](1), accums[0](1), accums2[0](1)],
[accums[1](1), accums[1](1), accums2[1](1)],
]
'''
101 changes: 101 additions & 0 deletions queries/ursa/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
;; Forked from https://github.com/ursalang/tree-sitter-ursa/blob/main/queries/highlights.scm
;; Licensed under the ISC licence
; Special identifiers
;--------------------
(
(identifier) @variable.builtin
(#match? @variable.builtin "^(pi)$")
(#is-not? local)
)

(
(identifier) @function.builtin
(#eq? @function.builtin "print")
(#is-not? local)
)

; Function definitions
;---------------------
(named_fn
(identifier) @function
)

(let
(identifier) @function
(lambda)
)

; Function and calls
;-------------------
(call
function: (identifier) @function
)

; (call
; (member_expression
; property: (property_identifier) @function.method))
; Variables
;----------
(identifier) @variable

; Properties
;-----------
(property_identifier) @property

; Literals
;---------
[
(bool)
(null)
] @constant.builtin

(comment) @comment

(string) @string

(number) @number

; Tokens
;-------
[
";"
"."
","
] @punctuation.delimiter

[
"-"
"+"
"*"
"**"
"/"
"%"
"<"
"<="
"="
"=="
"!="
">"
">="
] @operator

[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket

[
"break"
(continue)
"else"
"fn"
"if"
"let"
"loop"
"return"
"use"
] @keyword
18 changes: 18 additions & 0 deletions queries/ursa/locals.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
;; Forked from https://github.com/ursalang/tree-sitter-ursa/blob/main/queries/locals.scm
;; Licensed under the ISC licence
; Scopes
;-------
[
(block)
(lambda)
] @local.scope

; Definitions
;------------
(let
identifier: (identifier) @local.definition
)

; References
;------------
(identifier) @local.reference
1 change: 1 addition & 0 deletions syntastica-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const LANGUAGES = [
'toml',
'tsx',
'typescript',
'ursa',
'verilog',
'wat',
'yaml',
Expand Down
16 changes: 16 additions & 0 deletions syntastica-macros/languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,22 @@ nvim-like = true
injections = true
locals = true

[[languages]]
name = "ursa"
group = "all"
file-types = ["ursa"]
[languages.parser]
git = { url = "https://github.com/ursalang/tree-sitter-ursa", rev = "e15effeeff88df0e2c81a03f8e3098bdb6d749c4" }
external-scanner = { c = true, cpp = false }
ffi-func = "tree_sitter_ursa"
rust-func = "language"
package = "tree-sitter-ursa"
crates-io = "0.0.3"
[languages.queries]
nvim-like = false
injections = false
locals = true

[[languages]]
name = "verilog"
group = "all"
Expand Down
2 changes: 2 additions & 0 deletions syntastica-parsers-git/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ all = [
"ocaml_interface",
"ql",
"rush",
"ursa",
"verilog",
"wat",
]
Expand Down Expand Up @@ -161,6 +162,7 @@ scss = []
toml = []
tsx = []
typescript = []
ursa = []
verilog = []
wat = []
yaml = []
1 change: 1 addition & 0 deletions syntastica-parsers-git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ it will be reused the next time the build script is run.
- [ocaml_interface](https://github.com/tree-sitter/tree-sitter-ocaml/tree/694c57718fd85d514f8b81176038e7a4cfabcaaf)
- [ql](https://github.com/tree-sitter/tree-sitter-ql/tree/bd087020f0d8c183080ca615d38de0ec827aeeaf)
- [rush](https://github.com/rush-rs/tree-sitter-rush/tree/20c04a0824dabcbf8119a84979cfb1c6f6c2155f)
- [ursa](https://github.com/ursalang/tree-sitter-ursa/tree/e15effeeff88df0e2c81a03f8e3098bdb6d749c4)
- [verilog](https://github.com/tree-sitter/tree-sitter-verilog/tree/902031343056bc0b11f3e47b33f036a9cf59f58d)
- [wat](https://github.com/wasm-lsp/tree-sitter-wasm/tree/2ca28a9f9d709847bf7a3de0942a84e912f59088)

Expand Down
7 changes: 7 additions & 0 deletions syntastica-parsers-gitdep/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ all = [
"ocaml_interface",
"ql",
"rush",
"ursa",
"verilog",
]

Expand Down Expand Up @@ -136,6 +137,7 @@ rust = ["dep:tree-sitter-rust"]
scala = ["dep:tree-sitter-scala"]
scss = ["dep:tree-sitter-scss"]
toml = ["dep:tree-sitter-toml"]
ursa = ["dep:tree-sitter-ursa"]
verilog = ["dep:tree-sitter-verilog"]
yaml = ["dep:tree-sitter-yaml"]

Expand Down Expand Up @@ -299,6 +301,11 @@ optional = true
git = "https://github.com/Mathspy/tree-sitter-toml"
rev = "ae4cdb5d27bf876a432b6c30b6a88f56c9b3e761"

[dependencies.tree-sitter-ursa]
optional = true
git = "https://github.com/ursalang/tree-sitter-ursa"
rev = "e15effeeff88df0e2c81a03f8e3098bdb6d749c4"

[dependencies.tree-sitter-verilog]
optional = true
git = "https://github.com/tree-sitter/tree-sitter-verilog"
Expand Down
1 change: 1 addition & 0 deletions syntastica-parsers-gitdep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ for more information on all parser collections.
- [ocaml_interface](https://github.com/tree-sitter/tree-sitter-ocaml/tree/694c57718fd85d514f8b81176038e7a4cfabcaaf)
- [ql](https://github.com/tree-sitter/tree-sitter-ql/tree/bd087020f0d8c183080ca615d38de0ec827aeeaf)
- [rush](https://github.com/rush-rs/tree-sitter-rush/tree/20c04a0824dabcbf8119a84979cfb1c6f6c2155f)
- [ursa](https://github.com/ursalang/tree-sitter-ursa/tree/e15effeeff88df0e2c81a03f8e3098bdb6d749c4)
- [verilog](https://github.com/tree-sitter/tree-sitter-verilog/tree/902031343056bc0b11f3e47b33f036a9cf59f58d)
- [wat](https://github.com/wasm-lsp/tree-sitter-wasm/tree/2ca28a9f9d709847bf7a3de0942a84e912f59088) (not supported by this collection)

Expand Down
6 changes: 6 additions & 0 deletions syntastica-parsers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ all = [
"ocaml",
"ocaml_interface",
"rush",
"ursa",
]

## Meant to be enabled when building docs
Expand Down Expand Up @@ -113,6 +114,7 @@ rush = ["dep:tree-sitter-rush"]
rust = ["dep:tree-sitter-rust"]
scala = ["dep:tree-sitter-scala"]
toml = ["dep:tree-sitter-toml"]
ursa = ["dep:tree-sitter-ursa"]

[dependencies.tree-sitter-asm]
optional = true
Expand Down Expand Up @@ -205,3 +207,7 @@ version = "=0.20.1"
[dependencies.tree-sitter-toml]
optional = true
version = "=0.20.0"

[dependencies.tree-sitter-ursa]
optional = true
version = "=0.0.3"
1 change: 1 addition & 0 deletions syntastica-parsers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ for more information on all parser collections.
- [ocaml_interface](https://docs.rs/tree-sitter-ocaml/0.20.4/)
- [ql](https://github.com/tree-sitter/tree-sitter-ql) (not supported by this collection)
- [rush](https://docs.rs/tree-sitter-rush/0.1.0/)
- [ursa](https://docs.rs/tree-sitter-ursa/0.0.3/)
- [verilog](https://github.com/tree-sitter/tree-sitter-verilog) (not supported by this collection)
- [wat](https://github.com/wasm-lsp/tree-sitter-wasm) (not supported by this collection)

Expand Down
82 changes: 82 additions & 0 deletions syntastica-queries/generated_queries/ursa/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
(
(identifier) @variable.builtin
(#match? @variable.builtin "^(pi)$")
(#is-not? local)
)

(
(identifier) @function.builtin
(#eq? @function.builtin "print")
(#is-not? local)
)

(named_fn
(identifier) @function
)

(let
(identifier) @function
(lambda)
)

(call
function: (identifier) @function
)

(identifier) @variable

(property_identifier) @property

[
(bool)
(null)
] @constant.builtin

(comment) @comment

(string) @string

(number) @number

[
";"
"."
","
] @punctuation.delimiter

[
"-"
"+"
"*"
"**"
"/"
"%"
"<"
"<="
"="
"=="
"!="
">"
">="
] @operator

[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket

[
"break"
(continue)
"else"
"fn"
"if"
"let"
"loop"
"return"
"use"
] @keyword
Loading

0 comments on commit 9456104

Please sign in to comment.