Skip to content

Commit

Permalink
Merge branch 'master' into st4107
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Aug 18, 2024
2 parents 4ca96de + 5ed0508 commit 927e42e
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 3 deletions.
50 changes: 47 additions & 3 deletions WIT.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ variables:

break: (?!{{id_char}})

# a lazy semver pattern
semver: '[[:alnum:]_.+-]*[[:alnum:]_]'
# semver pattern <major> . <minor> [ . <micro> [ . <pre> ] ]
semver: '[[:digit:]]+(\.)[[:digit:]]+(?:(\.)[[:digit:]]+(?:([-+])[[:alnum:]_.+-]*[[:alnum:]])?)?'

keyword: |-
(?x: export | import | include | package | type | use | enum | flags
Expand Down Expand Up @@ -60,6 +60,7 @@ contexts:
- include: variant-declarations

# expressions
- include: annotations
- include: delimiters
- include: operators
- include: terminators
Expand Down Expand Up @@ -116,6 +117,33 @@ contexts:
- match: $\n?
pop: 1

###[ ANNOTATIONS ]#############################################################

annotations:
- match: (@){{id}}
scope: meta.annotation.identifier.wit variable.annotation.wit
captures:
1: punctuation.definition.variable.wit
push: annotation-argument-list

annotation-argument-list:
- meta_content_scope: meta.annotation.identifier.wit
- match: \(
scope: punctuation.section.arguments.begin.wit
set: annotation-argument-list-body

annotation-argument-list-body:
- meta_scope: meta.annotation.arguments.wit
- match: \)
scope: punctuation.section.arguments.end.wit
pop: 1
- match: '{{id}}'
scope: variable.parameter.wit
- include: delimiters
- include: numbers
- include: operators
- include: type-annotations

###[ PACKAGE DECLARATIONS ]####################################################

package-declarations:
Expand All @@ -135,6 +163,9 @@ contexts:
2: entity.name.namespace.package.wit
3: punctuation.separator.version.wit
4: constant.numeric.version.wit
5: punctuation.separator.decimal.wit
6: punctuation.separator.decimal.wit
7: punctuation.separator.decimal.wit
pop: 1
- include: else-pop

Expand Down Expand Up @@ -265,6 +296,9 @@ contexts:
1: entity.name.interface.wit
2: punctuation.separator.version.wit
3: constant.numeric.version.wit
4: punctuation.separator.decimal.wit
5: punctuation.separator.decimal.wit
6: punctuation.separator.decimal.wit
pop: 1
- include: immediately-pop

Expand Down Expand Up @@ -334,7 +368,10 @@ contexts:
1: support.interface.wit
2: punctuation.separator.version.wit
3: constant.numeric.version.wit
4: punctuation.separator.path.wit
4: punctuation.separator.decimal.wit
5: punctuation.separator.decimal.wit
6: punctuation.separator.decimal.wit
7: punctuation.separator.path.wit
pop: 1
- include: else-pop

Expand Down Expand Up @@ -556,6 +593,7 @@ contexts:
- match: \}
scope: punctuation.section.block.end.wit
pop: 1
- include: annotations
- include: terminators
- include: function-declarations

Expand Down Expand Up @@ -731,6 +769,12 @@ contexts:
2: punctuation.separator.path.wit

numbers:
- match: '{{semver}}'
scope: constant.numeric.version.wit
captures:
1: punctuation.separator.decimal.wit
2: punctuation.separator.decimal.wit
3: punctuation.separator.decimal.wit
- match: \d+
scope: meta.number.integer.decimal.wit constant.numeric.value.wit

Expand Down
52 changes: 52 additions & 0 deletions tests/syntax_test_scopes.wit
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
// ^^ meta.number.integer.decimal.wit constant.numeric.value.wit
// ^^ meta.number.integer.decimal.wit constant.numeric.value.wit

1.0.4-alpha.2
// ^^^^^^^^^^^^^ constant.numeric.version.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit

/// Types /////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -205,6 +210,8 @@ package foo:[email protected]
// ^^^ entity.name.namespace.package.wit
// ^ punctuation.separator.version.wit
// ^^^^^ constant.numeric.version.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit

package foo:bar:baz/quux/more;
// <- meta.package.wit keyword.declaration.package.wit
Expand Down Expand Up @@ -317,6 +324,8 @@ import ns1:ns2:ns3:pkg1/pkg2/[email protected];
// ^^^^ entity.name.interface.wit
// ^ punctuation.separator.version.wit
// ^^^^^ constant.numeric.version.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit

// 'import' id ':' 'interface' '{' interface-items* '}' ';'
import intf: interface { };
Expand Down Expand Up @@ -457,6 +466,8 @@ use wasi:http/[email protected]
// ^^^^^ support.interface.wit
// ^ punctuation.separator.version.wit
// ^^^^^ constant.numeric.version.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit

use wasi:http/types@1.0.0 as
// <- meta.statement.use.wit keyword.control.use.wit
Expand All @@ -472,6 +483,8 @@ use wasi:http/[email protected] as
// ^^^^^ support.interface.wit
// ^ punctuation.separator.version.wit
// ^^^^^ constant.numeric.version.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit
// ^^ keyword.opearator.assignment.as.wit

use wasi:http/types@1.0.0 as http-types1
Expand All @@ -489,6 +502,8 @@ use wasi:http/[email protected] as http-types1
// ^^^^^ support.interface.wit
// ^ punctuation.separator.version.wit
// ^^^^^ constant.numeric.version.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit
// ^^ keyword.opearator.assignment.as.wit
// ^^^^^^^^^^^ entity.name.interface.wit

Expand Down Expand Up @@ -587,6 +602,8 @@ use wasi:io/[email protected].{pollable};
// ^^^^ support.interface.wit
// ^ punctuation.separator.version.wit
// ^^^^^ constant.numeric.version.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.path.wit
// ^ punctuation.section.sequence.begin.wit
// ^^^^^^^^ variable.other.wit
Expand Down Expand Up @@ -715,11 +732,46 @@ world my-world-2 {
// ^^^^^^^^ keyword.declaration.resource.wit
// ^^^^^^^^^ entity.name.class.resource.wit

resource %resource-body {
@since(version = 0.2.0)
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.resource.body.wit meta.block.wit
// ^^^^^^ meta.annotation.identifier.wit
// ^^^^^^^^^^^^^^^^^ meta.annotation.arguments.wit
// ^ punctuation.definition.variable.wit
// ^^^^^^ variable.annotation.wit
// ^ punctuation.section.arguments.begin.wit
// ^^^^^^^ variable.parameter.wit
// ^ keyword.operator.assignment.wit
// ^^^^^ constant.numeric.version.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.section.arguments.end.wit
fun: func() -> bool;
// ^^^^^^^^^^^^^^^^^^^^ meta.resource.body.wit meta.block.wit
// ^^^ meta.function.identifier.wit entity.name.function.wit
// ^^^^^^ meta.function.wit
// ^^ meta.function.parameters.wit
// ^ meta.function.wit
// ^^^^^^^ meta.function.return-type.wit
}

type id = tuple<u32>;
// ^^^^^^^^^^^^^^^^^^^^ meta.world.body.wit meta.block.wit meta.type-alias
// ^^^^ keyword.declaration.type.wit
// ^^ entity.name.type.alias.wit

@since(version = 0.2.0)
// ^^^^^^ meta.annotation.identifier.wit
// ^^^^^^^^^^^^^^^^^ meta.annotation.arguments.wit
// ^ punctuation.definition.variable.wit
// ^^^^^^ variable.annotation.wit
// ^ punctuation.section.arguments.begin.wit
// ^^^^^^^ variable.parameter.wit
// ^ keyword.operator.assignment.wit
// ^^^^^ constant.numeric.version.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.separator.decimal.wit
// ^ punctuation.section.arguments.end.wit
variant %variant { a1(u32), all };
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.world.body.wit meta.block.wit meta.variant
// ^^^^^^^ keyword.declaration.variant.wit
Expand Down

0 comments on commit 927e42e

Please sign in to comment.