Skip to content

Commit

Permalink
[Go] Fix slice date type highlighting (sublimehq#3843)
Browse files Browse the repository at this point in the history
Fixes sublimehq#3842

This commit refactors `pop-type-single` context:

1. don't pop it off stack when matching `[` so arbitrary numbers of bracket
   pairs (slices) can be contained.

2. removes `pop-after-brackets` after `]` is matched as all its content is also
   part of `pop-type-single`.

3. simplify the context by removing some unneeded lookaheads.

   `pop-type-identifier` is included directly at last position as it also
   includes the `pop-before-nonblank`.
  • Loading branch information
deathaxe authored Nov 1, 2023
1 parent 20b93e7 commit f5132a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
31 changes: 11 additions & 20 deletions Go/Go.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1374,42 +1374,33 @@ contexts:
set: [pop-after-type, pop-type-single]

pop-type-single:
- include: pop-before-semicolon

# Note: Go allows wrapping types in an arbitrary number of parens.
- match: \(
scope: punctuation.section.parens.begin.go
push: [pop-type-nested-in-parens, pop-type]

# Note: Go allows multiple levels of slices
- match: \[
scope: punctuation.section.brackets.begin.go
push: pop-brackets-inner

- include: match-type-operators
- include: match-operators

- match: (?=\bchan\b)
set: pop-chan

- match: (?=\binterface\b)
set: pop-interface

- match: (?=\bmap\b)
set: pop-map

- match: (?=\bstruct\b)
set: pop-struct
- include: pop-chan
- include: pop-interface
- include: pop-map
- include: pop-struct

- match: \bfunc\b
scope: keyword.declaration.function.go
set: pop-func-parameter-and-return-lists

- match: (?={{ident}})
set: pop-type-identifier
- match: \btype\b
scope: keyword.operator.type.go

- match: \[
scope: punctuation.section.brackets.begin.go
set: [pop-after-brackets, pop-brackets-inner]

- include: pop-before-nonblank
# Note: must be the last one as it pops unconditionally
- include: pop-type-identifier

pop-after-type:
- match: \|{{operator_break}}
Expand Down
12 changes: 11 additions & 1 deletion Go/tests/syntax_test_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -3176,9 +3176,19 @@ by accident, but if necessary, such support could be sacrificed.

[]func(
// ^^^^ keyword.declaration.function.go
param typ
param typ,
// ^^^^^ variable.parameter.go
// ^^^ storage.type.go
// ^ punctuation.separator.go
param [][][]typ
// ^^^^^ variable.parameter.go
// ^ punctuation.section.brackets.begin.go
// ^ punctuation.section.brackets.end.go
// ^ punctuation.section.brackets.begin.go
// ^ punctuation.section.brackets.end.go
// ^ punctuation.section.brackets.begin.go
// ^ punctuation.section.brackets.end.go
// ^^^ storage.type.go
) typ ident
// ^^^ storage.type.go
// ^^^^^ variable.other.go
Expand Down

0 comments on commit f5132a0

Please sign in to comment.