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

Commit f6815ff

Browse files
start on classes
1 parent c7e0ba4 commit f6815ff

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

grammars/tree-sitter-php.cson

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ scopes:
155155

156156
'comment': [
157157
{match: '^//', scopes: 'comment.line.double-slash.php'},
158-
'comment.block'
158+
'comment.block.php'
159159
]
160160

161161
'variable_name': [
@@ -165,6 +165,8 @@ scopes:
165165
'variable_name > "$"': 'punctuation.definition.variable.php'
166166
'parenthesized_expression > "("': 'punctuation.definition.begin.bracket.round.php'
167167
'parenthesized_expression > ")"': 'punctuation.definition.end.bracket.round.php'
168+
'object_creation_expression > arguments > "("': 'punctuation.definition.begin.bracket.round.php'
169+
'object_creation_expression > arguments > ")"': 'punctuation.definition.end.bracket.round.php'
168170
'arguments > "("': 'punctuation.definition.arguments.begin.bracket.round.php'
169171
'arguments > ")"': 'punctuation.definition.arguments.end.bracket.round.php'
170172
'formal_parameters > "("': 'punctuation.definition.parameters.begin.bracket.round.php'

spec/tree-sitter-spec.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,4 +1662,97 @@ ${caret}
16621662
// SKIP this is covered by tree-sitter-php, not this grammar
16631663
// it("tokenizes trailing comma in use statements", () => {});
16641664
});
1665+
1666+
describe("classes", () => {
1667+
it("tokenizes class declarations", () => {
1668+
editor.setContent("class Test { /* stuff */ }");
1669+
1670+
expect(editor).toHaveScopesAtPosition(
1671+
[1, 0],
1672+
["source.php", "meta.class.php", "storage.type.class.php"]
1673+
);
1674+
expect(editor).toHaveScopesAtPosition(
1675+
[1, 5],
1676+
["source.php", "meta.class.php"]
1677+
);
1678+
expect(editor).toHaveScopesAtPosition(
1679+
[1, 6],
1680+
["source.php", "meta.class.php", "entity.name.type.class.php"]
1681+
);
1682+
expect(editor).toHaveScopesAtPosition(
1683+
[1, 10],
1684+
["source.php", "meta.class.php"]
1685+
);
1686+
expect(editor).toHaveScopesAtPosition(
1687+
[1, 11],
1688+
[
1689+
"source.php",
1690+
"meta.class.php",
1691+
// FIXME TM doesn't include this, TS does
1692+
"meta.class.body.php",
1693+
"punctuation.definition.class.begin.bracket.curly.php"
1694+
]
1695+
);
1696+
expect(editor).toHaveScopesAtPosition(
1697+
[1, 12],
1698+
["source.php", "meta.class.php", "meta.class.body.php"]
1699+
);
1700+
// /*
1701+
expect(editor).toHaveScopesAtPosition(
1702+
[1, 13],
1703+
[
1704+
"source.php",
1705+
"meta.class.php",
1706+
"meta.class.body.php",
1707+
"comment.block.php"
1708+
// FIXME how to select & scope this?
1709+
// "punctuation.definition.comment.php"
1710+
]
1711+
);
1712+
expect(editor).toHaveScopesAtPosition(
1713+
[1, 25],
1714+
[
1715+
"source.php",
1716+
"meta.class.php",
1717+
// FIXME TM doesn't include this, TS does
1718+
"meta.class.body.php",
1719+
"punctuation.definition.class.end.bracket.curly.php"
1720+
]
1721+
);
1722+
});
1723+
1724+
it("tokenizes class instantiation", () => {
1725+
editor.setContent("$a = new ClassName();");
1726+
1727+
// new
1728+
expect(editor).toHaveScopesAtPosition(
1729+
[1, 5],
1730+
["source.php", "keyword.other.new.php"]
1731+
);
1732+
// ' '
1733+
expect(editor).toHaveScopesAtPosition([1, 8], ["source.php"]);
1734+
// ClassName
1735+
expect(editor).toHaveScopesAtPosition(
1736+
[1, 9],
1737+
["source.php", "support.class.php"]
1738+
);
1739+
// (
1740+
expect(editor).toHaveScopesAtPosition(
1741+
[1, 18],
1742+
// FIXME I wonder if punctuation.definition.arguments.begin.bracket.round.php
1743+
// would be more correct: these are surrounding arguments to a new instance
1744+
["source.php", "punctuation.definition.begin.bracket.round.php"]
1745+
);
1746+
// )
1747+
expect(editor).toHaveScopesAtPosition(
1748+
[1, 19],
1749+
["source.php", "punctuation.definition.end.bracket.round.php"]
1750+
);
1751+
// ;
1752+
expect(editor).toHaveScopesAtPosition(
1753+
[1, 20],
1754+
["source.php", "punctuation.terminator.expression.php"]
1755+
);
1756+
});
1757+
});
16651758
});

0 commit comments

Comments
 (0)