Skip to content

Commit

Permalink
Add usd tree sitter.
Browse files Browse the repository at this point in the history
  • Loading branch information
furby-tm committed Apr 15, 2024
1 parent bdff506 commit 3b983b1
Show file tree
Hide file tree
Showing 13 changed files with 16,683 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let package = Package(
.headerSearchPath("TreeSitterRust/include"),
.headerSearchPath("TreeSitterSwift/include"),
.headerSearchPath("TreeSitterTOML/include"),
// TODO: Create a (.usda) tree sitter.
.headerSearchPath("TreeSitterUSD/include"),
]
),
.target(
Expand Down
11 changes: 11 additions & 0 deletions Sources/Editors/Code/CosmoLanguages/CodeLanguage+Definitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public extension CodeLanguage
.rust,
.swift,
.toml,
.usd,
]

/// A language structure for `C`
Expand Down Expand Up @@ -124,6 +125,16 @@ public extension CodeLanguage
rangeCommentStrings: ("", "")
)

/// A language structure for `USD`
static let usd: CodeLanguage = .init(
id: .usd,
tsName: "usd",
extensions: ["usda"],
lineCommentString: "#",
rangeCommentStrings: ("", ""),
documentationCommentStrings: [.pair(("(", ")"))]
)

/// The default language (plain text)
static let `default`: CodeLanguage = .init(
id: .plainText,
Expand Down
2 changes: 2 additions & 0 deletions Sources/Editors/Code/CosmoLanguages/CodeLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public struct CodeLanguage
tree_sitter_swift()
case .toml:
tree_sitter_toml()
case .usd:
tree_sitter_usd()
case .plainText:
nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
(None) @constant.builtin
(asset_path) @text.uri
(attribute_property) @property
(bool) @boolean
(comment) @comment @spell
(custom) @function.builtin
(float) @float
(integer) @number
(orderer) @function.call
(prim_path) @string.special
(relationship_type) @type
(uniform) @function.builtin
(variant_set_definition) @keyword

;; Prefer namespace highlighting, if any.
;;
;; e.g. `rel fizz` - `fizz` uses `@identifier`
;; e.g. `rel foo:bar:fizz` - `foo` and `bar` use `@namespace` and `fizz` uses `@identifier`
;;
(namespace_identifier) @namespace
(namespace_identifier
(identifier) @namespace
)
(identifier) @variable

[
"class"
"def"
"over"
] @keyword.function

["(" ")" "[" "]" "{" "}"] @punctuation.bracket
[":" ";" "."] @punctuation.delimiter

[
"="
] @operator

(attribute_type) @type
(
;; Reference: https://openusd.org/release/api/sdf_page_front.html
(attribute_type) @type.builtin
(#any-of? @type.builtin
;; Scalar types
"asset" "asset[]"
"bool" "bool[]"
"double" "double[]"
"float" "float[]"
"half" "half[]"
"int" "int[]"
"int64" "int64[]"
"string" "string[]"
"timecode" "timecode[]"
"token" "token[]"
"uchar" "uchar[]"
"uint" "uint[]"
"uint64" "uint64[]"

;; Dimensioned Types
"double2" "double2[]"
"double3" "double3[]"
"double4" "double4[]"
"float2" "float2[]"
"float3" "float3[]"
"float4" "float4[]"
"half2" "half2[]"
"half3" "half3[]"
"half4" "half4[]"
"int2" "int2[]"
"int3" "int3[]"
"int4" "int4[]"
"matrix2d" "matrix2d[]"
"matrix3d" "matrix3d[]"
"matrix4d" "matrix4d[]"
"quatd" "quatd[]"
"quatf" "quatf[]"
"quath" "quath[]"

;; Extra Types
"color3f" "color3f[]"
"normal3f" "normal3f[]"
"point3f" "point3f[]"
"texCoord2f" "texCoord2f[]"
"vector3d" "vector3d[]"
"vector3f" "vector3f[]"
"vector3h" "vector3h[]"

"dictionary"

;; Deprecated Types
"EdgeIndex" "EdgeIndex[]"
"FaceIndex" "FaceIndex[]"
"Matrix4d" "Matrix4d[]"
"PointIndex" "PointIndex[]"
"PointFloat" "PointFloat[]"
"Transform" "Transform[]"
"Vec3f" "Vec3f[]"
)
)

; In USD def "foo" ("This is a docstring") {} < the ""s within the ()s is not
; a string but a docstring
;
(metadata
(comment)*
.
(string) @comment.documentation)

(string) @string
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public enum TreeSitterLanguage: String
case rust
case swift
case toml
case usd
case plainText
}
5 changes: 5 additions & 0 deletions Sources/Editors/Code/CosmoLanguages/TreeSitterModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class TreeSitterModel
swiftQuery
case .toml:
tomlQuery
case .usd:
usdQuery
case .plainText:
nil
}
Expand All @@ -81,6 +83,9 @@ public class TreeSitterModel
/// Query for `TOML` files.
public private(set) lazy var tomlQuery: Query? = queryFor(.toml)

/// Query for `USD` files.
public private(set) lazy var usdQuery: Query? = queryFor(.usd)

private func queryFor(_ codeLanguage: CodeLanguage) -> Query?
{
// get the tree-sitter language and query url if available
Expand Down
Loading

0 comments on commit 3b983b1

Please sign in to comment.