8000 match statement by KapitanOczywisty · Pull Request #407 · atom/language-php · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

match statement #407

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions grammars/php.cson
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@
}
]
}
{
'include': '#match_statement'
}
{
'include': '#switch_statement'
}
Expand Down Expand Up @@ -3624,6 +3627,56 @@
]
}
]
'match_statement':
'patterns': [
{
'match': '\\s+(?=match\\b)'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've copied this from switch, but I really don't know why this is present and commit history didn't help with solving this mystery. Anyone?

}
{
'begin': '\\bmatch\\b'
'beginCaptures':
'0':
'name': 'keyword.control.match.php'
'end': '}|(?=\\?>)'
'endCaptures':
'0':
'name': 'punctuation.definition.section.match-block.end.bracket.curly.php'
'name': 'meta.match-statement.php'
'patterns': [
{
'begin': '\\('
'beginCaptures':
'0':
'name': 'punctuation.definition.match-expression.begin.bracket.round.php'
'end': '\\)|(?=\\?>)'
'endCaptures':
'0':
'name': 'punctuation.definition.match-expression.end.bracket.round.php'
'patterns': [
{
'include': '$self'
}
]
}
{
'begin': '{'
'beginCaptures':
'0':
'name': 'punctuation.definition.section.match-block.begin.bracket.curly.php'
'end': '(?=}|\\?>)'
'patterns': [
{
'match': '=>'
'name': 'keyword.definition.arrow.php'
}
{
'include': '$self'
}
]
}
]
}
]
'use-inner':
'patterns': [
{
Expand Down
38 changes: 38 additions & 0 deletions < 8000 /span> spec/php-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,44 @@ describe 'PHP grammar', ->
expect(lines[7][1]).toEqual value: 'continue', scopes: ['source.php', 'meta.switch-statement.php', 'keyword.control.continue.php']
expect(lines[8][0]).toEqual value: '}', scopes: ['source.php', 'meta.switch-statement.php', 'punctuation.definition.section.switch-block.end.bracket.curly.php']

it 'should tokenize match statements correctly', ->
lines = grammar.tokenizeLines '''
echo match (1) {
0 => 'Foo',
1, 2 => 'Bar',
default => 'Baz',
};
'''

expect(lines[0][0]).toEqual value: 'echo', scopes: ['source.php', 'support.function.construct.output.php']
expect(lines[0][2]).toEqual value: 'match', scopes: ['source.php', 'meta.match-statement.php', 'keyword.control.match.php']
expect(lines[0][4]).toEqual value: '(', scopes: ['source.php', 'meta.match-statement.php', 'punctuation.definition.match-expression.begin.bracket.round.php']
expect(lines[0][5]).toEqual value: '1', scopes: ['source.php', 'meta.match-statement.php', 'constant.numeric.decimal.php']
expect(lines[0][6]).toEqual value: ')', scopes: ['source.php', 'meta.match-statement.php', 'punctuation.definition.match-expression.end.bracket.round.php']
expect(lines[0][8]).toEqual value: '{', scopes: ['source.php', 'meta.match-statement.php', 'punctuation.definition.section.match-block.begin.bracket.curly.php']
expect(lines[1][1]).toEqual value: '0', scopes: ['source.php', 'meta.match-statement.php', 'constant.numeric.decimal.php']
expect(lines[1][3]).toEqual value: '=>', scopes: ['source.php', 'meta.match-statement.php', 'keyword.definition.arrow.php']
expect(lines[1][5]).toEqual value: '\'', scopes: ['source.php', 'meta.match-statement.php', 'string.quoted.single.php', 'punctuation.definition.string.begin.php']
expect(lines[1][6]).toEqual value: 'Foo', scopes: ['source.php', 'meta.match-statement.php', 'string.quoted.single.php']
expect(lines[1][7]).toEqual value: '\'', scopes: ['source.php', 'meta.match-statement.php', 'string.quoted.single.php', 'punctuation.definition.string.end.php']
expect(lines[1][8]).toEqual value: ',', scopes: ['source.php', 'meta.match-statement.php', 'punctuation.separator.delimiter.php']
expect(lines[2][1]).toEqual value: '1', scopes: ['source.php', 'meta.match-statement.php', 'constant.numeric.decimal.php']
expect(lines[2][2]).toEqual value: ',', scopes: ['source.php', 'meta.match-statement.php', 'punctuation.separator.delimiter.php']
expect(lines[2][4]).toEqual value: '2', scopes: ['source.php', 'meta.match-statement.php', 'constant.numeric.decimal.php']
expect(lines[2][6]).toEqual value: '=>', scopes: ['source.php', 'meta.match-statement.php', 'keyword.definition.arrow.php']
expect(lines[2][8]).toEqual value: '\'', scopes: ['source.php', 'meta.match-statement.php', 'string.quoted.single.php', 'punctuation.definition.string.begin.php']
expect(lines[2][9]).toEqual value: 'Bar', scopes: ['source.php', 'meta.match-statement.php', 'string.quoted.single.php']
expect(lines[2][10]).toEqual value: '\'', scopes: ['source.php', 'meta.match-statement.php', 'string.quoted.single.php', 'punctuation.definition.string.end.php']
expect(lines[2][11]).toEqual value: ',', scopes: ['source.php', 'meta.match-statement.php', 'punctuation.separator.delimiter.php']
expect(lines[3][1]).toEqual value: 'default', scopes: ['source.php', 'meta.match-statement.php', 'keyword.control.default.php']
expect(lines[3][3]).toEqual value: '=>', 5C60 scopes: ['source.php', 'meta.match-statement.php', 'keyword.definition.arrow.php']
expect(lines[3][5]).toEqual value: '\'', scopes: ['source.php', 'meta.match-statement.php', 'string.quoted.single.php', 'punctuation.definition.string.begin.php']
expect(lines[3][6]).toEqual value: 'Baz', scopes: ['source.php', 'meta.match-statement.php', 'string.quoted.single.php']
expect(lines[3][7]).toEqual value: '\'', scopes: ['source.php', 'meta.match-statement.php', 'string.quoted.single.php', 'punctuation.definition.string.end.php']
expect(lines[3][8]).toEqual value: ',', scopes: ['source.php', 'meta.match-statement.php', 'punctuation.separator.delimiter.php']
expect(lines[4][0]).toEqual value: '}', scopes: ['source.php', 'meta.match-statement.php', 'punctuation.definition.section.match-block.end.bracket.curly.php']
expect(lines[4][1]).toEqual value: ';', scopes: ['source.php', 'punctuation.terminator.expression.php']

it 'should tokenize storage types correctly', ->
{tokens} = grammar.tokenizeLine '(int)'

Expand Down
0