aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/queries/dart
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/queries/dart')
-rw-r--r--runtime/queries/dart/folds.scm13
-rw-r--r--runtime/queries/dart/highlights.scm303
-rw-r--r--runtime/queries/dart/indents.scm49
-rw-r--r--runtime/queries/dart/injections.scm2
-rw-r--r--runtime/queries/dart/locals.scm32
5 files changed, 399 insertions, 0 deletions
diff --git a/runtime/queries/dart/folds.scm b/runtime/queries/dart/folds.scm
new file mode 100644
index 000000000..fc75ac219
--- /dev/null
+++ b/runtime/queries/dart/folds.scm
@@ -0,0 +1,13 @@
+[
+ (class_definition)
+ (enum_declaration)
+ (extension_declaration)
+ (arguments)
+ (function_body)
+ (block)
+ (switch_block)
+ (list_literal)
+ (set_or_map_literal)
+ (string_literal)
+ (import_or_export)+
+] @fold
diff --git a/runtime/queries/dart/highlights.scm b/runtime/queries/dart/highlights.scm
new file mode 100644
index 000000000..072a10d26
--- /dev/null
+++ b/runtime/queries/dart/highlights.scm
@@ -0,0 +1,303 @@
+(identifier) @variable
+
+(dotted_identifier_list) @string
+
+; Methods
+; --------------------
+; TODO: add method/call_expression to grammar and
+; distinguish method call from variable access
+(function_expression_body
+ (identifier) @function.call)
+
+; ((identifier)(selector (argument_part)) @function)
+; NOTE: This query is a bit of a work around for the fact that the dart grammar doesn't
+; specifically identify a node as a function call
+(((identifier) @function.call
+ (#lua-match? @function.call "^_?[%l]"))
+ .
+ (selector
+ .
+ (argument_part))) @function.call
+
+; Annotations
+; --------------------
+(annotation
+ "@" @attribute
+ name: (identifier) @attribute)
+
+; Operators and Tokens
+; --------------------
+(template_substitution
+ "$" @punctuation.special
+ "{" @punctuation.special
+ "}" @punctuation.special) @none
+
+(template_substitution
+ "$" @punctuation.special
+ (identifier_dollar_escaped) @variable) @none
+
+(escape_sequence) @string.escape
+
+[
+ "=>"
+ ".."
+ "??"
+ "=="
+ "!"
+ "?"
+ "&&"
+ "%"
+ "<"
+ ">"
+ "="
+ ">="
+ "<="
+ "||"
+ ">>>="
+ ">>="
+ "<<="
+ "&="
+ "|="
+ "??="
+ "%="
+ "+="
+ "-="
+ "*="
+ "/="
+ "^="
+ "~/="
+ (shift_operator)
+ (multiplicative_operator)
+ (increment_operator)
+ (is_operator)
+ (prefix_operator)
+ (equality_operator)
+ (additive_operator)
+] @operator
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
+
+; Delimiters
+; --------------------
+[
+ ";"
+ "."
+ ","
+ ":"
+ "?."
+ "?"
+] @punctuation.delimiter
+
+; Types
+; --------------------
+(class_definition
+ name: (identifier) @type)
+
+(constructor_signature
+ name: (identifier) @type)
+
+(scoped_identifier
+ scope: (identifier) @type)
+
+(function_signature
+ name: (identifier) @function.method)
+
+(getter_signature
+ (identifier) @function.method)
+
+(setter_signature
+ name: (identifier) @function.method)
+
+(enum_declaration
+ name: (identifier) @type)
+
+(enum_constant
+ name: (identifier) @type)
+
+(void_type) @type
+
+((scoped_identifier
+ scope: (identifier) @type
+ name: (identifier) @type)
+ (#lua-match? @type "^[%u%l]"))
+
+(type_identifier) @type
+
+(type_alias
+ (type_identifier) @type.definition)
+
+(type_arguments
+ [
+ "<"
+ ">"
+ ] @punctuation.bracket)
+
+; Variables
+; --------------------
+; var keyword
+(inferred_type) @keyword
+
+((identifier) @type
+ (#lua-match? @type "^_?[%u].*[%l]")) ; catch Classes or IClasses not CLASSES
+
+"Function" @type
+
+; properties
+(unconditional_assignable_selector
+ (identifier) @property)
+
+(conditional_assignable_selector
+ (identifier) @property)
+
+(this) @variable.builtin
+
+; Parameters
+; --------------------
+(formal_parameter
+ (identifier) @variable.parameter)
+
+(named_argument
+ (label
+ (identifier) @variable.parameter))
+
+; Literals
+; --------------------
+[
+ (hex_integer_literal)
+ (decimal_integer_literal)
+ (decimal_floating_point_literal)
+ ; TODO: inaccessible nodes
+ ; (octal_integer_literal)
+ ; (hex_floating_point_literal)
+] @number
+
+(symbol_literal) @string.special.symbol
+
+(string_literal) @string
+
+(true) @boolean
+
+(false) @boolean
+
+(null_literal) @constant.builtin
+
+(comment) @comment @spell
+
+(documentation_comment) @comment.documentation @spell
+
+; Keywords
+; --------------------
+[
+ "import"
+ "library"
+ "export"
+ "as"
+ "show"
+ "hide"
+] @keyword.import
+
+; Reserved words (cannot be used as identifiers)
+[
+ ; TODO:
+ ; "rethrow" cannot be targeted at all and seems to be an invisible node
+ ; TODO:
+ ; the assert keyword cannot be specifically targeted
+ ; because the grammar selects the whole node or the content
+ ; of the assertion not just the keyword
+ ; assert
+ (case_builtin)
+ "late"
+ "required"
+ "on"
+ "extends"
+ "in"
+ "is"
+ "new"
+ "super"
+ "with"
+] @keyword
+
+[
+ "class"
+ "enum"
+ "extension"
+] @keyword.type
+
+"return" @keyword.return
+
+; Built in identifiers:
+; alone these are marked as keywords
+[
+ "deferred"
+ "factory"
+ "get"
+ "implements"
+ "interface"
+ "library"
+ "operator"
+ "mixin"
+ "part"
+ "set"
+ "typedef"
+] @keyword
+
+[
+ "async"
+ "async*"
+ "sync*"
+ "await"
+ "yield"
+] @keyword.coroutine
+
+[
+ (const_builtin)
+ (final_builtin)
+ "abstract"
+ "covariant"
+ "external"
+ "static"
+ "final"
+ "base"
+ "sealed"
+] @keyword.modifier
+
+; when used as an identifier:
+((identifier) @variable.builtin
+ (#any-of? @variable.builtin
+ "abstract" "as" "covariant" "deferred" "dynamic" "export" "external" "factory" "Function" "get"
+ "implements" "import" "interface" "library" "operator" "mixin" "part" "set" "static" "typedef"))
+
+[
+ "if"
+ "else"
+ "switch"
+ "default"
+] @keyword.conditional
+
+(conditional_expression
+ [
+ "?"
+ ":"
+ ] @keyword.conditional.ternary)
+
+[
+ "try"
+ "throw"
+ "catch"
+ "finally"
+ (break_statement)
+] @keyword.exception
+
+[
+ "do"
+ "while"
+ "continue"
+ "for"
+] @keyword.repeat
diff --git a/runtime/queries/dart/indents.scm b/runtime/queries/dart/indents.scm
new file mode 100644
index 000000000..03d9464bc
--- /dev/null
+++ b/runtime/queries/dart/indents.scm
@@ -0,0 +1,49 @@
+[
+ (class_body)
+ (function_body)
+ (function_expression_body)
+ (declaration
+ (initializers))
+ (switch_block)
+ (formal_parameter_list)
+ (formal_parameter)
+ (list_literal)
+ (return_statement)
+ (arguments)
+ (try_statement)
+] @indent.begin
+
+(switch_block
+ (_) @indent.begin
+ (#set! indent.immediate 1)
+ (#set! indent.start_at_same_line 1))
+
+[
+ (switch_statement_case)
+ (switch_statement_default)
+] @indent.branch
+
+[
+ "("
+ ")"
+ "{"
+ "}"
+ "["
+ "]"
+] @indent.branch
+
+"}" @indent.end
+
+(return_statement
+ ";" @indent.end)
+
+(break_statement
+ ";" @indent.end)
+
+(comment) @indent.ignore
+
+; dedenting the else block is painfully slow; replace with simpler strategy
+; (if_statement) @indent.begin
+; (if_statement
+; (block) @indent.branch)
+(if_statement) @indent.auto
diff --git a/runtime/queries/dart/injections.scm b/runtime/queries/dart/injections.scm
new file mode 100644
index 000000000..2f0e58eb6
--- /dev/null
+++ b/runtime/queries/dart/injections.scm
@@ -0,0 +1,2 @@
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/runtime/queries/dart/locals.scm b/runtime/queries/dart/locals.scm
new file mode 100644
index 000000000..3e3beb58e
--- /dev/null
+++ b/runtime/queries/dart/locals.scm
@@ -0,0 +1,32 @@
+; Definitions
+(function_signature
+ name: (identifier) @local.definition.function)
+
+(formal_parameter
+ name: (identifier) @local.definition.parameter)
+
+(initialized_variable_definition
+ name: (identifier) @local.definition.var)
+
+(initialized_identifier
+ (identifier) @local.definition.var)
+
+(static_final_declaration
+ (identifier) @local.definition.var)
+
+; References
+(identifier) @local.reference
+
+; Scopes
+(class_definition
+ body: (_) @local.scope)
+
+[
+ (block)
+ (if_statement)
+ (for_statement)
+ (while_statement)
+ (try_statement)
+ (catch_clause)
+ (finally_clause)
+] @local.scope