Skip to content

Commit

Permalink
Merge pull request #859 from savetheclocktower/tree-sitter-january
Browse files Browse the repository at this point in the history
Tree-sitter rolling fixes (January edition)
  • Loading branch information
savetheclocktower authored Jan 30, 2024
2 parents e999387 + 4f3bc68 commit 2dbd995
Show file tree
Hide file tree
Showing 145 changed files with 2,393 additions and 1,090 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.ts
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module.exports = {
asyncArrow: "always",
named: "never"
}],
"node/no-missing-require": [
"error",
{
allowModules: ["atom"]
}
],
"node/no-unpublished-require": [
"error",
{
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ jobs:
node ./rolling-release-binary-upload.js
- name: Upload Video Artifacts
if: runner.os != 'Linux'
# Run whether this job passed or failed, unless explicitly cancelled.
if: ${{ !cancelled() && runner.os != 'Linux' }}
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }} Videos
Expand Down Expand Up @@ -267,7 +268,8 @@ jobs:
node ./rolling-release-binary-upload.js
- name: Upload Video Artifacts - Linux
if: runner.os == 'Linux'
# Run whether this job passed or failed, unless explicitly cancelled.
if: ${{ !cancelled() && runner.os == 'Linux' }}
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }} Videos
Expand Down
2 changes: 1 addition & 1 deletion integration/workspace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const languages = [
// {language: "mustache", code: '10', checks: {numeric: '10'}},
{language: "Objective C", code: '10', checks: {numeric: '10'}},
{language: "Perl", code: '10', checks: {numeric: '10'}},
{language: "PHP", code: '<? 10 %>', checks: {numeric: '10'}},
{language: "PHP", code: '<? $foo ?>', checks: {variable: '$foo'}},
// {language: "property-list", code: '10', checks: {numeric: '10'}},
{language: "Python", code: '10', checks: {numeric: '10'}},
{language: "Ruby on Rails", code: '10', checks: {numeric: '10'}},
Expand Down
1 change: 1 addition & 0 deletions packages/atom-dark-syntax/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
@import "styles/syntax/base.less";
@import "styles/syntax/css.less";
@import "styles/syntax/html.less";
@import "styles/syntax/json.less";
6 changes: 6 additions & 0 deletions packages/atom-dark-syntax/styles/syntax/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@
&.syntax--italic {
font-style: italic;
}

// Horizontal rules in GFM used to be scoped as `comment.hr`. For continuity,
// we assign the color of a comment to this new scope.
&.syntax--horizontal-rule {
color: #8A8A8A;
}
}

// /* comment */
Expand Down
11 changes: 11 additions & 0 deletions packages/atom-dark-syntax/styles/syntax/json.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

.syntax--source.syntax--json {

// Color JSON keys differently from other strings.
.syntax--meta.syntax--structure.syntax--key {
.syntax--string.syntax--quoted.syntax--double {
color: #96CBFE;
}
}

}
1 change: 1 addition & 0 deletions packages/atom-light-syntax/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

@import "styles/syntax/base.less";
@import "styles/syntax/css.less";
@import "styles/syntax/json.less";
6 changes: 6 additions & 0 deletions packages/atom-light-syntax/styles/syntax/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
&.syntax--italic {
font-style: italic;
}

// Horizontal rules in GFM used to be scoped as `comment.hr`. For continuity,
// we assign the color of a comment to this new scope.
&.syntax--horizontal-rule {
color: #999988;
}
}

// /* comment */
Expand Down
11 changes: 11 additions & 0 deletions packages/atom-light-syntax/styles/syntax/json.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

.syntax--source.syntax--json {

// Color JSON keys differently from other strings.
.syntax--meta.syntax--structure.syntax--key {
.syntax--string.syntax--quoted.syntax--double {
color: #008080;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@
&.syntax--raw {
color: @green;
}

// Horizontal rules in GFM used to be scoped as `comment.hr`. For continuity,
// we assign the color of a comment to this new scope.
&.syntax--horizontal-rule {
color: @gray;
}
}

.syntax--source.syntax--gfm {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
}
}

// Color JSON keys differently from other strings.
.syntax--meta.syntax--structure.syntax--key {
.syntax--string.syntax--quoted.syntax--double {
color: @red;
}
}

.syntax--meta.syntax--structure.syntax--dictionary.syntax--json, .syntax--meta.syntax--structure.syntax--array.syntax--json {
& > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json,
& > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json > .syntax--punctuation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@
&.syntax--raw {
color: @green;
}

// Horizontal rules in GFM used to be scoped as `comment.hr`. For continuity,
// we assign the color of a comment to this new scope.
&.syntax--horizontal-rule {
color: @gray;
}
}

.syntax--source.syntax--gfm {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
}
}

// Color JSON keys differently from other strings.
.syntax--meta.syntax--structure.syntax--key {
.syntax--string.syntax--quoted.syntax--double {
color: @red;
}
}

.syntax--meta.syntax--structure.syntax--dictionary.syntax--json, .syntax--meta.syntax--structure.syntax--array.syntax--json {
& > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json,
& > .syntax--value.syntax--json > .syntax--string.syntax--quoted.syntax--json > .syntax--punctuation {
Expand Down
12 changes: 12 additions & 0 deletions packages/bracket-matcher/spec/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
env: { jasmine: true },
globals: {
waitsForPromise: true,
},
rules: {
"node/no-unpublished-require": "off",
"node/no-extraneous-require": "off",
"no-unused-vars": "off",
"no-empty": "off"
}
};
1 change: 1 addition & 0 deletions packages/language-c/grammars/modern-tree-sitter-c.cson
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ firstLineRegex: '-\\*-[^*]*(Mode:\\s*)?C(\\s*;.*?)?\\s*-\\*-'
injectionRegex: '^(c|C)$'

treeSitter:
parserSource: 'github:tree-sitter/tree-sitter-c#212a80f86452bb1316324fa0db730cf52f29e05a'
grammar: 'tree-sitter-c/tree-sitter-c.wasm'
highlightsQuery: 'tree-sitter-c/highlights.scm'
tagsQuery: 'tree-sitter-c/tags.scm'
Expand Down
2 changes: 1 addition & 1 deletion packages/language-c/grammars/modern-tree-sitter-cpp.cson
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parser: 'tree-sitter-cpp'
injectionRegex: '^(c|C)(\\+\\+|pp|PP)$'

treeSitter:
parserSource: 'github:tree-sitter/tree-sitter-cpp#a90f170f92d5d70e7c2d4183c146e61ba5f3a457'
parserSource: 'github:tree-sitter/tree-sitter-cpp#a71474021410973b29bfe99440d57bcd750246b1'
grammar: 'tree-sitter-cpp/tree-sitter-cpp.wasm'
highlightsQuery: 'tree-sitter-cpp/highlights.scm'
tagsQuery: 'tree-sitter-cpp/tags.scm'
Expand Down
109 changes: 84 additions & 25 deletions packages/language-c/grammars/tree-sitter-c/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"#define" @keyword.control.directive.define.c
"#include" @keyword.control.directive.include.c

(["#if" "#ifdef" "#ifndef" "#endif" "#elif" "#else" "#define" "#include"] @punctuation.definition.directive.c
(#set! adjust.endAfterFirstMatchOf "^#"))


; This will match if the more specific rules above haven't matched. The
; anonymous nodes will match under ideal conditions, but might not be present
; if the parser is flummoxed.
Expand Down Expand Up @@ -43,30 +47,41 @@
(type_identifier) @_IGNORE_
(#set! capture.final true))

(primitive_type) @support.type.builtin.c
(type_identifier) @support.type.other.c
(primitive_type) @support.storage.type.builtin.c
(type_identifier) @support.other.storage.type.c

; These types are all reserved words; if we see an identifier with this name,
; it must be a type.
((identifier) @support.type.builtin.c
(#match? @support.type.builtin.c "^(char|int|float|double|long)$"))
((identifier) @support.storage.type.builtin.c
(#match? @support.storage.type.builtin.c "^(char|int|float|double|long)$"))

; Assume any identifier that ends in `_t` is a type. This convention is not
; always followed, but it's a very strong indicator when it's present.
((identifier) @support.type.other.c
(#match? @support.type.other.c "_t$"))
((identifier) @support.other.storage.type.c
(#match? @support.other.storage.type.c "_t$"))

; These refer to language constructs and remain in the `storage` namespace.
[
"enum"
"long"
"short"
"signed"
"struct"
"typedef"
"union"
"unsigned"
] @storage.type.c

; These refer to value types and go under `support`.
[
"long"
"short"
] @support.storage.type.builtin.c

; These act as modifiers to value types and also go under `support`.
[
"signed"
"unsigned"
] @support.storage.modifier.builtin.c

; These act as general language modifiers and remain in the `storage`
; namespace.
[
"const"
"extern"
Expand All @@ -75,10 +90,10 @@
"restrict"
"static"
"volatile"
] @storage.modifier.c
] @storage.modifier._TYPE_.c

((primitive_type) @support.type.stdint.c
(#match? @support.type.stdint.c "^(int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t|intmax_t|intmax_t|uintmax_t|uintmax_t)$"))
((primitive_type) @support.storage.type.stdint.c
(#match? @support.storage.type.stdint.c "^(int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t|intmax_t|intmax_t|uintmax_t|uintmax_t)$"))

(enum_specifier
name: (type_identifier) @variable.other.declaration.type.c)
Expand Down Expand Up @@ -116,32 +131,57 @@
; Declarations and assignments
; ----------------------------

; The "x" in `int x`;
; The "x" in `int x;`
(declaration
declarator: (identifier) @variable.declaration.c)

; The "x" in `int x = y`;
; The "x" in `int x = y;`
(init_declarator
declarator: (identifier) @variable.declaration.c)

; The "x" in `SomeType *x;`
; (Should work no matter how many pointers deep we are.)
(pointer_declarator
declarator: [(identifier) (field_identifier)] @variable.declaration.pointer.c
(#is? test.descendantOfType "declaration field_declaration"))

; A member of a struct.
(field_declaration
(field_identifier) @entity.other.attribute-name.c)
(field_identifier) @variable.declaration.member.c)

; An attribute in a C99 struct designated initializer:
; the "foo" in `MY_TYPE a = { .foo = true };
(initializer_pair
(field_designator
(field_identifier) @variable.declaration.member.c))

; (and the associated ".")
(initializer_pair
(field_designator
"." @keyword.operator.accessor.c))

(field_declaration
(pointer_declarator
(field_identifier) @entity.other.attribute-name.c))
(field_identifier) @variable.declaration.member.c))

(field_declaration
(array_declarator
(field_identifier) @entity.other.attribute-name.c))
(field_identifier) @variable.declaration.member.c))

(init_declarator
(pointer_declarator
(identifier) @entity.other.attribute-name.c))
(identifier) @variable.declaration.member.c))

; The "x" in `x = y;`
(assignment_expression
left: (identifier) @variable.other.assignment.c)

; The "foo" in `something->foo = "bar";`
(assignment_expression
left: (field_expression
field: (field_identifier) @variable.other.member.assignment.c)
(#set! capture.final))


; Function parameters
; -------------------
Expand All @@ -154,9 +194,10 @@
declarator: (identifier) @variable.parameter.c)

; The "foo" in `const char *foo` within a parameter list.
(parameter_declaration
declarator: (pointer_declarator
declarator: (identifier) @variable.parameter.c))
; (Should work no matter how many pointers deep we are.)
(pointer_declarator
declarator: [(identifier) (field_identifier)] @variable.parameter.pointer.c
(#is? test.descendantOfType "parameter_declaration"))

; The "foo" in `const char foo[]` within a parameter list.
(parameter_declaration
Expand All @@ -172,7 +213,7 @@
; The "size" in `finfo->size`.
(field_expression
"->"
field: (field_identifier) @support.other.property.c)
field: (field_identifier) @variable.other.member.c)


; FUNCTIONS
Expand Down Expand Up @@ -309,8 +350,10 @@

";" @punctuation.terminator.statement.c

"," @punctuation.separator.comma.c
"->" @punctuation.separator.pointer-access.c
("," @punctuation.separator.comma.c
(#set! capture.shy))
("->" @keyword.operator.accessor.pointer-access.c
(#set! capture.shy))

(parameter_list
"(" @punctuation.definition.parameters.begin.bracket.round.c
Expand All @@ -335,6 +378,22 @@
"[" @punctuation.definition.array.begin.bracket.square.c
"]" @punctuation.definition.array.end.bracket.square.c


; META
; ====

((compound_statement) @meta.block.c
(#set! adjust.startAt firstChild.endPosition)
(#set! adjust.endAt lastChild.startPosition))

((enumerator_list) @meta.block.enum.c
(#set! adjust.startAt firstChild.endPosition)
(#set! adjust.endAt lastChild.startPosition))

((field_declaration_list) @meta.block.field.c
(#set! adjust.startAt firstChild.endPosition)
(#set! adjust.endAt lastChild.startPosition))

; TODO:
;
; * TM-style grammar has a lot of `mac-classic` scopes. I doubt they'd be
Expand Down
Binary file modified packages/language-c/grammars/tree-sitter-c/tree-sitter-c.wasm
Binary file not shown.
Loading

0 comments on commit 2dbd995

Please sign in to comment.