Skip to content

Commit

Permalink
Merge pull request #64 from matthewnitschke/fixed_keyword_highlighting
Browse files Browse the repository at this point in the history
Fixed keyword highlighting
  • Loading branch information
TimWhiting authored Apr 2, 2024
2 parents 1a31399 + 1e995cd commit 7861a48
Show file tree
Hide file tree
Showing 17 changed files with 109,432 additions and 107,815 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ pubspec.lock
*.dll
*.dylib
doc
.vscode
14 changes: 0 additions & 14 deletions .vscode/settings.json

This file was deleted.

31 changes: 18 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="tree-sitter-cli/dsl" />

// Using the informal draft spec to support the newest features of dart
// https://spec.dart.dev/DartLangSpecDraft.pdf

Expand Down Expand Up @@ -206,7 +208,7 @@ module.exports = grammar({

rules: {

// Page 188 libraryDeclaration
// Page 188 libraryDeclaration
program: $ => seq(
optional($.script_tag),
optional($.library_name),
Expand Down Expand Up @@ -256,7 +258,7 @@ module.exports = grammar({
$.function_signature,
$.function_body
),
// final or const static final declaration list
// final or const static final declaration list
seq(
optional($._metadata),
choice(
Expand Down Expand Up @@ -588,6 +590,7 @@ module.exports = grammar({
$.pattern_assignment,
$.assignment_expression,
$.throw_expression,
$.rethrow_expression,
seq(
$._real_expression,
repeat($.cascade_section)
Expand Down Expand Up @@ -661,13 +664,13 @@ module.exports = grammar({
throw_expression: $ => seq(
'throw',
$._expression

),
throw_expression_without_cascade: $ => seq(
'throw',
$._expression_without_cascade
),

rethrow_expression: $ => $.rethrow_builtin,

/**************************************************************************************************
***********************Assignment Expressions*****************************************************
Expand Down Expand Up @@ -1128,7 +1131,7 @@ module.exports = grammar({
)),

constructor_tearoff: $ => prec.right(seq(
$._type_name, optional($.type_arguments), '.', $._new_builtin,
$._type_name, optional($.type_arguments), '.', $._new_builtin,
)),

arguments: $ => seq('(', optional($._argument_list), ')'),
Expand Down Expand Up @@ -1275,7 +1278,7 @@ module.exports = grammar({
assert_statement: $ => seq($.assertion, ';'),

assertion: $ => seq(
$._assert_builtin,
$.assert_builtin,
$.assertion_arguments,
),

Expand Down Expand Up @@ -1320,7 +1323,7 @@ module.exports = grammar({

_logical_or_pattern: $ => seq($._logical_and_pattern, repeat(seq($.logical_or_operator, $._logical_and_pattern))),
_logical_and_pattern: $ => seq($._relational_pattern, repeat(seq($.logical_and_operator, $._relational_pattern))),
_relational_pattern: $ =>
_relational_pattern: $ =>
prec(DART_PREC.Relational, choice(
seq(choice($.relational_operator, $.equality_operator), $._real_expression),
$._unary_pattern,
Expand Down Expand Up @@ -1428,7 +1431,7 @@ module.exports = grammar({
$._semicolon
),

break_statement: $ => seq($._break_builtin, optional($.identifier), $._semicolon),
break_statement: $ => seq($.break_builtin, optional($.identifier), $._semicolon),

continue_statement: $ => seq('continue', optional($.identifier), $._semicolon),

Expand Down Expand Up @@ -1628,7 +1631,7 @@ module.exports = grammar({

part_of_directive: $ => seq(
optional($._metadata),
'part', 'of',
$.part_of_builtin,
choice($.dotted_identifier_list, $.uri),
$._semicolon
),
Expand Down Expand Up @@ -2081,7 +2084,7 @@ module.exports = grammar({
),
initializer_list_entry: $ => choice(
seq($.super, $.arguments),
seq($.super,
seq($.super,
seq('.', choice($.identifier, $._new_builtin), $.arguments),
),
$.field_initializer,
Expand Down Expand Up @@ -2330,7 +2333,7 @@ module.exports = grammar({
// $.generic_type
),

record_type: $ => choice(
record_type: $ => choice(
seq('(', ')'),
seq('(', commaSep1($.record_type_field), ',', '{' , commaSep1TrailingComma($.record_type_named_field), '}', ')'),
seq('(', commaSep1TrailingComma($.record_type_field), ')'),
Expand Down Expand Up @@ -2701,9 +2704,11 @@ module.exports = grammar({
DART_PREC.BUILTIN,
'as',
),
_break_builtin: $ => token('break'),
_assert_builtin: $ => token('assert'),
break_builtin: $ => token('break'),
assert_builtin: $ => token('assert'),
case_builtin: $ => token('case'),
rethrow_builtin: $ => token('rethrow'),
part_of_builtin: $ => token('part of'),
_covariant: $ => prec(
DART_PREC.BUILTIN,
'covariant',
Expand Down Expand Up @@ -2815,7 +2820,7 @@ module.exports = grammar({
DART_PREC.BUILTIN,
'external',
),

this: $ => prec(
DART_PREC.BUILTIN,
'this',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
],
"license": "ISC",
"dependencies": {
"nan": "^2.17.0"
"nan": "^2.18.0"
},
"devDependencies": {
"node-gyp": "^9.3.1",
"node-gyp": "^10.0.1",
"npm-watch": "^0.11.0",
"tree-sitter-cli": "^0.20.8"
},
Expand Down
93 changes: 49 additions & 44 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@
; var keyword
(inferred_type) @keyword

(const_builtin) @constant.builtin
(final_builtin) @constant.builtin

((identifier) @type
(#match? @type "^_?[A-Z]"))

("Function" @type)
(void_type) @type

(this) @variable.builtin

Expand Down Expand Up @@ -163,70 +161,77 @@

; Keywords
; --------------------
["import" "library" "export"] @include

; Reserved words (cannot be used as identifiers)
; TODO: "rethrow" @keyword
[
; "assert"
(case_builtin)
"extension"
"on"
"class"
"enum"
"extends"
"in"
"is"
"new"
"return"
"super"
"with"
] @keyword


; Built in identifiers:
; alone these are marked as keywords
[
(assert_builtin)
(break_statement)
(const_builtin)
(part_of_builtin)
(rethrow_builtin)
"abstract"
"as"
"async"
"async*"
"yield"
"sync*"
"await"
"base"
"case"
"catch"
"class"
"continue"
"covariant"
"default"
"deferred"
"do"
"dynamic"
"else"
"enum"
"export"
"extends"
"extension"
"external"
"factory"
"false"
"final"
"finally"
"for"
"Function"
"get"
"hide"
"if"
"implements"
"import"
"in"
"interface"
"is"
"late"
"library"
"operator"
"mixin"
"new"
"null"
"on"
"operator"
"part"
"required"
"return"
"sealed"
"set"
"show"
"static"
"super"
"switch"
"sync*"
"throw"
"true"
"try"
"typedef"
"var"
"when"
"while"
"with"
"yield"
] @keyword

; when used as an identifier:
((identifier) @variable
(#vim-match? @variable "^(abstract|as|covariant|deferred|dynamic|export|external|factory|Function|get|implements|import|interface|library|operator|mixin|part|set|static|typedef)$"))

["if" "else" "switch" "default"] @conditional

[
"try"
"throw"
"catch"
"finally"
(break_statement)
] @exception

["do" "while" "continue" "for"] @repeat
; Variable
(identifier) @variable

; Error
(ERROR) @error
Loading

0 comments on commit 7861a48

Please sign in to comment.