Skip to content

Commit

Permalink
Add galah tree sitter & file UTType.
Browse files Browse the repository at this point in the history
Signed-off-by: furby™ <devs@wabi.foundation>
  • Loading branch information
furby-tm committed Sep 6, 2024
1 parent d6c6eb7 commit 2f2e471
Show file tree
Hide file tree
Showing 22 changed files with 526,422 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Bundler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ icon = "kraken.png"
[apps.Kraken.plist]
commit = '$(COMMIT_HASH)'
CFBundleURLTypes = [ { type = "dict", value = { CFBundleTypeRole = 'Viewer', CFBundleURLName = 'Kraken', CFBundleURLSchemes = [ 'kraken' ] } } ]
CFBundleDocumentTypes = [ { type = "dict", value = { CFBundleTypeExtensions = [ 'usd', 'usda', 'usdc', 'usdz' ], CFBundleTypeIconFile = 'AppIcon.icns', CFBundleTypeName = 'Universal Scene Description File', CFBundleTypeRole = 'Editor', LSIsAppleDefaultForType = true, LSItemContentTypes = [ 'com.pixar.universal-scene-description', 'com.pixar.universal-scene-description-mobile', 'com.pixar.usd.ascii', 'com.pixar.usd.crate' ], CFBundleTypeIconSystemGenerated = true } } ]
CFBundleDocumentTypes = [
{ type = "dict", value = { CFBundleTypeExtensions = [ 'usd', 'usda', 'usdc', 'usdz' ], CFBundleTypeIconFile = 'AppIcon.icns', CFBundleTypeName = 'Universal Scene Description File', CFBundleTypeRole = 'Editor', LSIsAppleDefaultForType = true, LSItemContentTypes = [ 'com.pixar.universal-scene-description', 'com.pixar.universal-scene-description-mobile', 'com.pixar.usd.ascii', 'com.pixar.usd.crate' ], CFBundleTypeIconSystemGenerated = true } },
{ type = "dict", value = { CFBundleTypeExtensions = [ 'galah' ], CFBundleTypeIconFile = 'AppIcon.icns', CFBundleTypeName = 'Galah File', CFBundleTypeRole = 'Editor', LSIsAppleDefaultForType = true, LSItemContentTypes = [ 'dev.stackotter.galah' ], CFBundleTypeIconSystemGenerated = true } }
]
UTExportedTypeDeclarations = [ { type = "dict", value = { UTTypeConformsTo = [ 'public.data', 'public.source-code' ], UTTypeIdentifier = 'dev.stackotter.galah', UTTypeDescription = 'Galah File', UTTypeIcons = { type = "dict", value = { UTTypeIconName = "Galah File", UTTypeIconText = "galah" } }, UTTypeTagSpecification = { type = "dict", value = { 'public.filename-extension' = [ 'galah' ] } } } } ]
2 changes: 1 addition & 1 deletion Kraken.usda
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#usda 1.0
(
doc = "Kraken v1.1.0 | 08-09-2024 09:20:10"
doc = "Kraken v1.1.0 | 09-06-2024 09:23:39"
)

def Xform "Geometry"
Expand Down
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ let package = Package(
cSettings: [
.headerSearchPath("TreeSitterC/include"),
.headerSearchPath("TreeSitterCPP/include"),
.headerSearchPath("TreeSitterGalah/include"),
.headerSearchPath("TreeSitterJSDoc/include"),
.headerSearchPath("TreeSitterJSON/include"),
.headerSearchPath("TreeSitterPython/include"),
Expand All @@ -126,6 +127,7 @@ let package = Package(
resources: [
.copy("Resources/tree-sitter-c"),
.copy("Resources/tree-sitter-cpp"),
.copy("Resources/tree-sitter-galah"),
.copy("Resources/tree-sitter-jsdoc"),
.copy("Resources/tree-sitter-json"),
.copy("Resources/tree-sitter-python"),
Expand Down
15 changes: 15 additions & 0 deletions Sources/Editors/Code/Languages/CodeLanguage+Definitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public extension Editor.Code.Language
static let allLanguages: [Editor.Code.Language] = [
.c,
.cpp,
.galah,
.jsdoc,
.json,
.python,
Expand Down Expand Up @@ -71,6 +72,20 @@ public extension Editor.Code.Language
highlights: ["injections"]
)

/// A language structure for `Galah`
static let galah: Editor.Code.Language = .init(
id: .galah,
tsName: "galah",
extensions: ["galah"],
lineCommentString: "//",
rangeCommentStrings: ("/*", "*/"),
documentationCommentStrings: [
.single("///"),
.pair(("/**", "*/"))
],
highlights: ["injections"]
)

/// A language structure for `JSDoc`
static let jsdoc: Editor.Code.Language = .init(
id: .jsdoc,
Expand Down
2 changes: 2 additions & 0 deletions Sources/Editors/Code/Languages/CodeLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public extension Editor.Code
tree_sitter_c()
case .cpp:
tree_sitter_cpp()
case .galah:
tree_sitter_galah()
case .jsdoc:
tree_sitter_jsdoc()
case .json:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
[ "." ";" ":" "," ] @punctuation.delimiter
[ "\\(" "(" ")" "[" "]" "{" "}" ] @punctuation.bracket ; TODO: "\\(" ")" in interpolations should be @punctuation.special

; Identifiers
(attribute) @variable
(type_identifier) @type
(self_expression) @variable
(user_type (type_identifier) @keyword (#eq? @keyword "Self"))

; Declarations
"fn" @keyword.function
[
(visibility_modifier)
(member_modifier)
(function_modifier)
(property_modifier)
(parameter_modifier)
(inheritance_modifier)
(mutation_modifier)
] @keyword

(function_declaration (simple_identifier) @function)
(init_declaration ["init" @constructor])
(deinit_declaration ["deinit" @constructor])
(throws) @keyword
"async" @keyword
"await" @keyword
(where_keyword) @keyword
(parameter external_name: (simple_identifier) @property)
(parameter name: (simple_identifier) @property)
(type_parameter (type_identifier) @property)
(inheritance_constraint (identifier (simple_identifier) @property))
(equality_constraint (identifier (simple_identifier) @property))
(pattern bound_identifier: (simple_identifier)) @variable

[
"typealias"
"struct"
"class"
"actor"
"enum"
"protocol"
"extension"
"indirect"
"nonisolated"
"override"
"convenience"
"required"
"mutating"
"nonmutating"
"associatedtype"
] @keyword

(opaque_type ["some" @keyword])
(existential_type ["any" @keyword])

(precedence_group_declaration
["precedencegroup" @keyword]
(simple_identifier) @type)
(precedence_group_attribute
(simple_identifier) @keyword
[(simple_identifier) @type
(boolean_literal) @boolean])

[
(getter_specifier)
(setter_specifier)
(modify_specifier)
] @keyword

(class_body (property_declaration (pattern (simple_identifier) @variable.parameter)))
(protocol_property_declaration (pattern (simple_identifier) @variable.parameter))

(value_argument
name: (value_argument_label) @property)

(import_declaration
"import" @keyword)

(enum_entry
"case" @keyword)

; Function calls
(call_expression (simple_identifier) @function) ; foo()
(call_expression ; foo.bar.baz(): highlight the baz()
(navigation_expression
(navigation_suffix (simple_identifier) @function)))
((navigation_expression
(simple_identifier) @variable) ; SomeType.method(): highlight SomeType as a type
(#match? @variable "^[A-Z]"))
(call_expression (simple_identifier) @type) ; SomeType { ... }

(try_operator) @operator
(try_operator ["try" @keyword])

(directive) @number
(diagnostic) @number

; Statements
(for_statement ["for" @keyword])
(for_statement ["in" @keyword])
(for_statement (pattern) @variable)
(else) @keyword
(as_operator) @keyword

["while" "repeat" "continue" "break"] @keyword

["let" "var"] @keyword

(guard_statement
"guard" @keyword)

(if_statement
"if" @keyword)

(switch_statement
"switch" @keyword)

(switch_entry
"case" @keyword)

(switch_entry
"fallthrough" @keyword)

(switch_entry
(default_keyword) @keyword)

"return" @keyword.return

(ternary_expression
["?" ":"] @keyword)

["do" (throw_keyword) (catch_keyword)] @keyword

(statement_label) @label

; Comments
[
(comment)
(multiline_comment)
] @comment @spell

((comment) @comment.documentation
(#lua-match? @comment.documentation "^///[^/]"))

((comment) @comment.documentation
(#lua-match? @comment.documentation "^///$"))

((multiline_comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))

; String literals
(line_str_text) @string
(str_escaped_char) @string
(multi_line_str_text) @string
(raw_str_part) @string
(raw_str_end_part) @string
(raw_str_interpolation_start) @punctuation.special
["\"" "\"\"\""] @string

; Lambda literals
(lambda_literal ["in" @keyword])

; Basic literals
[
(integer_literal)
(hex_literal)
(oct_literal)
(bin_literal)
] @number
(real_literal) @number
(boolean_literal) @boolean
"nil" @keyword

; Regex literals
(regex_literal) @string

; Operators
(custom_operator) @keyword

[
"!"
"?"
"+"
"-"
"*"
"/"
"%"
"="
"+="
"-="
"*="
"/="
"<"
">"
"<="
">="
"++"
"--"
"&"
"~"
"%="
"!="
"!=="
"=="
"==="
"??"
"->"
"..<"
"..."
(bang)
] @keyword

(value_parameter_pack ["each" @keyword])
(value_pack_expansion ["repeat" @keyword])
(type_parameter_pack ["each" @keyword])
(type_pack_expansion ["repeat" @keyword])
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
[
; ... refers to the section that will get affected by this indent.begin capture
(protocol_body) ; protocol Foo { ... }
(class_body) ; class Foo { ... }
(enum_class_body) ; enum Foo { ... }
(function_declaration) ; fn Foo (...) {...}
(init_declaration) ; init(...) {...}
(deinit_declaration) ; deinit {...}
(computed_property) ; { ... }
(subscript_declaration) ; subscript Foo(...) { ... }

(computed_getter) ; get { ... }
(computed_setter) ; set { ... }

(assignment) ; a = b

(control_transfer_statement) ; return ...
(for_statement)
(while_statement)
(repeat_while_statement)
(do_statement)
(if_statement)
(switch_statement)
(guard_statement)

(type_parameters) ; x<Foo>
(tuple_type) ; (...)
(array_type) ; [String]
(dictionary_type) ; [Foo: Bar]

(call_expression) ; callFunc(...)
(tuple_expression) ; ( foo + bar )
(array_literal) ; [ foo, bar ]
(dictionary_literal) ; [ foo: bar, x: y ]
(lambda_literal)
(willset_didset_block)
(willset_clause)
(didset_clause)
] @indent.begin

; @something(...)
((modifiers
(attribute) @indent.begin))

(function_declaration
(modifiers
.
(attribute)
(_)* @indent.branch)
.
_ @indent.branch
(#not-has-type? @indent.branch type_parameters parameter))


(ERROR
[
"<"
"{"
"("
"["
]
) @indent.begin


; if-elseif
(if_statement
(if_statement) @indent.dedent)

; case Foo:
; default Foo:
; @attribute default Foo:
(switch_entry . _ @indent.branch)

(function_declaration ")" @indent.branch)

(type_parameters ">" @indent.branch @indent.end .)
(tuple_expression ")" @indent.branch @indent.end)
(value_arguments ")" @indent.branch @indent.end)
(tuple_type ")" @indent.branch @indent.end)
(modifiers
(attribute ")" @indent.branch @indent.end))

[
"}"
"]"
] @indent.branch @indent.end


[
; (ERROR)
(comment)
(multiline_comment)
(raw_str_part)
(multi_line_string_literal)
] @indent.auto

(directive) @indent.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; Parse regex syntax within regex literals

((regex_literal) @injection.content
(#set! injection.language "regex"))
Loading

0 comments on commit 2f2e471

Please sign in to comment.