Skip to content

[Go] Fix compiler directive syntax patterns #3242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 6, 2022
59 changes: 28 additions & 31 deletions Go/Go.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -133,52 +133,43 @@ contexts:
# as plain comments by default, and add some detailed meta scopes for
# enterprising users wishing to add more color.
- match: (//)([a-z]+[a-z-]*)(:)({{directive}})[ ]?
scope: meta.annotation.go
captures:
1: punctuation.definition.comment.go
2: meta.keyword.annotation.go
3: meta.punctuation.accessor.colon.go
3: punctuation.accessor.colon.go
4: meta.variable.function.go
push:
- meta_scope: meta.annotation.go comment.line.go
- match: .+
scope: meta.annotation.parameters.go
# End the annotation scope at EOL, but stretch the comment scope
# indefinitely to the right.
- match: $
set: pop-line-comment
push: pop-line-annotation

# Go also has line renumbering; line directives specify the source
# position for the character immediately following the comment as
# having come from the specified file, line and column. Both single
# line and block comment line directives are valid.
- match: (//)(line) ([a-zA-Z0-9. :]*(?::[0-9]+){1,2})$
- match: ((//)(line) )([a-zA-Z0-9. :]*(?::[0-9]+){1,2})$\n?
scope: comment.line.go
captures:
1: punctuation.definition.comment.go
2: meta.variable.function.go
3: meta.variable.parameter.go
push:
- meta_scope: meta.annotation.go comment.line.go
- match: $
set: pop-line-comment
1: meta.annotation.go
2: punctuation.definition.comment.go
3: meta.variable.function.go
4: meta.annotation.parameters.go

- match: (/\*)(line) ([a-zA-Z0-9. :]*(?::[0-9]+){1,2})(\*/)
scope: meta.annotation.go comment.block.go
- match: ((/\*)(line) )([a-zA-Z0-9. :]*(?::[0-9]+){1,2})(\*/)
scope: comment.block.go
captures:
1: punctuation.definition.comment.begin.go
2: meta.variable.function.go
3: meta.variable.parameter.go
4: punctuation.definition.comment.end.go
1: meta.annotation.go
2: punctuation.definition.comment.begin.go
3: meta.variable.function.go
4: meta.annotation.parameters.go
5: meta.annotation.go punctuation.definition.comment.end.go

# Finally, Cgo and gccgo have directives for exporting functions to C.
- match: (//)(export|extern) ({{ident}})$
- match: ((//)(export|extern) )({{ident}})$\n?
scope: comment.line.go
captures:
1: punctuation.definition.comment.go
2: meta.variable.function.go
3: meta.variable.parameter.go
push:
- meta_scope: meta.annotation.go comment.line.go
- match: $
set: pop-line-comment
1: meta.annotation.go
2: punctuation.definition.comment.go
3: meta.variable.function.go
4: meta.annotation.parameters.go

# Line comment
- match: //
Expand All @@ -197,6 +188,12 @@ contexts:
captures:
1: punctuation.definition.comment.go

pop-line-annotation:
- meta_scope: comment.line.go
- meta_content_scope: meta.annotation.parameters.go
- match: $\n?
pop: true

pop-line-comment:
- meta_scope: comment.line.go
# Including the newline allows the scope to visually stretch to the right,
Expand Down
51 changes: 28 additions & 23 deletions Go/syntax_test_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,84 +66,87 @@ You may have to disable Go-specific linters when working on this file.
//go:generate one two three
// ^ -comment -meta -punctuation
// ^^ punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation.go comment.line.go
// ^^^^^^^^^^^^^^ comment.line.go meta.annotation.go
// ^^ meta.keyword.annotation.go
// ^^^^^^^^ meta.variable.function.go
// ^^^^^^^^^^^^^ meta.annotation.parameters.go
// ^^^^^^^^^^^^^ comment.line.go meta.annotation.parameters.go
// ^ comment.line.go -meta.annotation

//go-sumtype:decl MySumType
// ^ -comment -meta -punctuation
// ^^ punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation.go comment.line.go
// ^^^^^^^^^^^^^^^^^^ comment.line.go meta.annotation.go
// ^^^^^^^^^^ meta.keyword.annotation.go
// ^^^^ meta.variable.function.go
// ^^^^^^^^^ meta.annotation.parameters.go
// ^^^^^^^^^ comment.line.go meta.annotation.parameters.go
// ^ comment.line.go -meta.annotation

//lint:ignore U1000 Reason.
// ^ -comment -meta -punctuation
// ^^ punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation.go comment.line.go
// ^^^^^^^^^^^^^^ comment.line.go meta.annotation.go
// ^^^^ meta.keyword.annotation.go
// ^^^^^^ meta.variable.function.go
// ^^^^^^^^^^^^^ meta.annotation.parameters.go
// ^^^^^^^^^^^^^ comment.line.go meta.annotation.parameters.go
// ^ comment.line.go -meta.annotation

//lint:file-ignore Reason.
// ^ -comment -meta -punctuation
// ^^ punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation.go comment.line.go
// ^^^^^^^^^^^^^^^^^^^ comment.line.go meta.annotation.go
// ^^^^ meta.keyword.annotation.go
// ^^^^^^^^^^^ meta.variable.function.go
// ^^^^^^^ meta.annotation.parameters.go
// ^^^^^^^ comment.line.go meta.annotation.parameters.go
// ^ comment.line.go -meta.annotation

//line :10
// ^ -comment -meta -punctuation
// ^^ punctuation.definition.comment.go
// ^^^^^^^^^^ meta.annotation.go comment.line.go
// ^^^^^^^ comment.line.go meta.annotation.go
// ^^^^ meta.variable.function.go
// ^^^ meta.variable.parameter.go
// ^^^ comment.line.go meta.annotation.parameters.go
// ^ comment.line.go -meta.annotation

//line file.rl:10
// ^ -comment -meta -punctuation
// ^^ punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^^^ meta.annotation.go comment.line.go
// ^^^^^^^ comment.line.go meta.annotation.go
// ^^^^ meta.variable.function.go
// ^^^^^^^^^^ meta.variable.parameter.go
// ^^^^^^^^^^ comment.line.go meta.annotation.parameters.go
// ^ comment.line.go -meta.annotation

//line file.rl:100:10
// ^ -comment -meta -punctuation
// ^^ punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^^^^^^^ meta.annotation.go comment.line.go
// ^^^^^^^ comment.line.go meta.annotation.go
// ^^^^ meta.variable.function.go
// ^^^^^^^^^^^^^^ meta.variable.parameter.go
// ^^^^^^^^^^^^^^ comment.line.go meta.annotation.parameters.go
// ^ comment.line.go -meta.annotation

/*line :10*/
// ^ -comment
// ^^^^^^^^^^^^ meta.annotation.go comment.block.go
// ^^^^^^^ comment.block.go meta.annotation.go
// ^^^^ meta.variable.function.go
// ^^^ meta.variable.parameter.go
// ^^^ comment.block.go meta.annotation.parameters.go
// ^^ comment.block.go punctuation.definition.comment.end.go
// ^ -comment.block.go -meta.annotation

/*line file.rl:10*/
// ^ -comment
// ^^^^^^^^^^^^^^^^^^^ meta.annotation.go comment.block.go
// ^^^^^^^ comment.block.go meta.annotation.go
// ^^ punctuation.definition.comment.begin.go
// ^^^^ meta.variable.function.go
// ^^^^^^^^^^ meta.variable.parameter.go
// ^^^^^^^^^^ comment.block.go meta.annotation.parameters.go
// ^^ comment.block.go punctuation.definition.comment.end.go
// ^ -comment.block.go -meta.annotation

/*line file.rl:100:10*/
// ^ -comment
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.annotation.go comment.block.go
// ^^^^^^^ comment.block.go meta.annotation.go
// ^^ punctuation.definition.comment.begin.go
// ^^^^ meta.variable.function.go
// ^^^^^^^^^^^^^^ meta.variable.parameter.go
// ^^ punctuation.definition.comment.end.go
// ^^^^^^^^^^^^^^ comment.block.go meta.annotation.parameters.go
// ^^ comment.block.go punctuation.definition.comment.end.go
// ^ -comment.block.go -meta.annotation

/*line :10 */
Expand All @@ -166,13 +169,15 @@ You may have to disable Go-specific linters when working on this file.
//export myfunc
// ^ -comment -meta -punctuation
// ^^ punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^ meta.annotation.go comment.line.go
// ^^^^^^^^^ comment.line.go meta.annotation.go
// ^^^^^^ comment.line.go meta.annotation.parameters.go
// ^ comment.line.go -meta.annotation

//extern myfunc
// ^ -comment -meta -punctuation
// ^^ punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^ meta.annotation.go comment.line.go
// ^^^^^^^^^ comment.line.go meta.annotation.go
// ^^^^^^ comment.line.go meta.annotation.parameters.go
// ^ comment.line.go -meta.annotation


Expand Down