Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into utf-8-compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan authored Jan 13, 2022
2 parents 6ec1f66 + bbc2ab4 commit acb3c55
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
12 changes: 8 additions & 4 deletions grammars/php.cson
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@
'name': 'storage.type.php'
}
{
'match': '\\b(noreturn)\\b',
'name': 'keyword.other.type.noreturn.php'
'match': '\\b(never)\\b',
'name': 'keyword.other.type.never.php'
}
{
'include': '#php-types'
Expand Down Expand Up @@ -2457,7 +2457,7 @@
{
# Tags followed by a type expression
# - @<tag> type
'begin': '(@(?:global|param|property(-(read|write))?|return|throws|var))\\s+(?=[A-Za-z_\\x{7f}-\\x{10ffff}\\\\]|\\()'
'begin': '(@(?:global|param|property(-(read|write))?|return|throws|var))\\s+(?=[?A-Za-z_\\x{7f}-\\x{10ffff}\\\\]|\\()'
'beginCaptures':
'1':
'name': 'keyword.other.phpdoc.php'
Expand Down Expand Up @@ -2495,10 +2495,14 @@
}
]
'php_doc_types':
'match': '(?i)[a-z_\\x{7f}-\\x{10ffff}\\\\][a-z0-9_\\x{7f}-\\x{10ffff}\\\\]*([|&][a-z_\\x{7f}-\\x{10ffff}\\\\][a-z0-9_\\x{7f}-\\x{10ffff}\\\\]*)*'
'match': '(?i)\\??[a-z_\\x{7f}-\\x{10ffff}\\\\][a-z0-9_\\x{7f}-\\x{10ffff}\\\\]*([|&]\\??[a-z_\\x{7f}-\\x{10ffff}\\\\][a-z0-9_\\x{7f}-\\x{10ffff}\\\\]*)*'
'captures':
'0':
'patterns': [
{
'match': '\\?'
'name': 'keyword.operator.nullable-type.php'
}
{
'match': '''(?x)\\b
(string|integer|int|boolean|bool|float|double|object|mixed
Expand Down
44 changes: 41 additions & 3 deletions spec/php-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1721,12 +1721,12 @@ describe 'PHP grammar', ->
expect(tokens[5]).toEqual value: '?', scopes: ["source.php", "meta.function.closure.php", "keyword.operator.nullable-type.php"]
expect(tokens[6]).toEqual value: 'Client', scopes: ["source.php", "meta.function.closure.php", "support.class.php"]

it 'tokenizes noreturn type', ->
{tokens} = grammar.tokenizeLine 'function app_exit() : noreturn {}'
it 'tokenizes never type', ->
{tokens} = grammar.tokenizeLine 'function app_exit() : never {}'

expect(tokens[0]).toEqual value: 'function', scopes: ['source.php', 'meta.function.php', 'storage.type.function.php']
expect(tokens[6]).toEqual value: ':', scopes: ['source.php', 'meta.function.php', 'keyword.operator.return-value.php']
expect(tokens[8]).toEqual value: 'noreturn', scopes: ['source.php', 'meta.function.php', 'keyword.other.type.noreturn.php']
expect(tokens[8]).toEqual value: 'never', scopes: ['source.php', 'meta.function.php', 'keyword.other.type.never.php']

it 'tokenizes closure returning reference', ->
{tokens} = grammar.tokenizeLine 'function&() {}'
Expand Down Expand Up @@ -2561,6 +2561,29 @@ describe 'PHP grammar', ->
expect(lines[1][3]).toEqual value: 'Test', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'support.class.php']
expect(lines[1][4]).toEqual value: ' description', scopes: ['source.php', 'comment.block.documentation.phpdoc.php']

it 'should tokenize a single nullable type', ->
lines = grammar.tokenizeLines '''
/**
*@param ?int description
'''

expect(lines[1][1]).toEqual value: '@param', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'keyword.other.phpdoc.php']
expect(lines[1][2]).toEqual value: ' ', scopes: ['source.php', 'comment.block.documentation.phpdoc.php']
expect(lines[1][3]).toEqual value: '?', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'keyword.operator.nullable-type.php']
expect(lines[1][4]).toEqual value: 'int', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'keyword.other.type.php']
expect(lines[1][5]).toEqual value: ' description', scopes: ['source.php', 'comment.block.documentation.phpdoc.php']

lines = grammar.tokenizeLines '''
/**
*@param ?Test description
'''

expect(lines[1][1]).toEqual value: '@param', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'keyword.other.phpdoc.php']
expect(lines[1][2]).toEqual value: ' ', scopes: ['source.php', 'comment.block.documentation.phpdoc.php']
expect(lines[1][3]).toEqual value: '?', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'keyword.operator.nullable-type.php']
expect(lines[1][4]).toEqual value: 'Test', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'support.class.php']
expect(lines[1][5]).toEqual value: ' description', scopes: ['source.php', 'comment.block.documentation.phpdoc.php']

it 'should tokenize a single namespaced type', ->
lines = grammar.tokenizeLines '''
/**
Expand Down Expand Up @@ -2588,6 +2611,21 @@ describe 'PHP grammar', ->
expect(lines[1][5]).toEqual value: 'Class', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'support.class.php']
expect(lines[1][6]).toEqual value: ' description', scopes: ['source.php', 'comment.block.documentation.phpdoc.php']

it 'should tokenize multiple nullable types', ->
lines = grammar.tokenizeLines '''
/**
*@param ?int|?Class description
'''

expect(lines[1][1]).toEqual value: '@param', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'keyword.other.phpdoc.php']
expect(lines[1][2]).toEqual value: ' ', scopes: ['source.php', 'comment.block.documentation.phpdoc.php']
expect(lines[1][3]).toEqual value: '?', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'keyword.operator.nullable-type.php']
expect(lines[1][4]).toEqual value: 'int', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'keyword.other.type.php']
expect(lines[1][5]).toEqual value: '|', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'punctuation.separator.delimiter.php']
expect(lines[1][6]).toEqual value: '?', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'keyword.operator.nullable-type.php']
expect(lines[1][7]).toEqual value: 'Class', scopes: ['source.php', 'comment.block.documentation.phpdoc.php', 'meta.other.type.phpdoc.php', 'support.class.php']
expect(lines[1][8]).toEqual value: ' description', scopes: ['source.php', 'comment.block.documentation.phpdoc.php']

it 'should tokenize intersection types', ->
lines = grammar.tokenizeLines '''
/**
Expand Down

0 comments on commit acb3c55

Please sign in to comment.