Skip to content

Commit 77fa11b

Browse files
fix: grammar
1 parent 8ea7b26 commit 77fa11b

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

packages/textmate/scripts/grammar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ export function createMiraScriptDocGrammar(): LanguageRegistration {
766766
patterns: [
767767
{
768768
begin: String.raw`(?<!\p{XID_Continue})(fn)${IDENTIFIER_END}(?=\s*(?:<|\())`,
769-
beginCaptures: { 1: { name: 'storage.type.function.mira' } },
769+
beginCaptures: { 1: { name: 'support.type.function.mira' } },
770770
end: String.raw`(?=\s*(?:,|\)|$))`,
771771
patterns: [
772772
{ include: '#generic-types' },

packages/textmate/test/grammar.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,53 @@ test('distinguishes doc declarations, globals, and nested function types', () =>
183183
expectScope(tokens, 'PI', 'variable.other.constant.mira', 1);
184184
expectScope(tokens, '(global)', 'entity.name.label.mira', 0);
185185
expectScope(tokens, 'fn', 'keyword.declaration.function.mira', 0);
186-
expectScope(tokens, 'fn', 'storage.type.function.mira', 2);
186+
expectScope(tokens, 'fn', 'support.type.function.mira', 2);
187187
expectScope(tokens, 'data', 'variable.other.constant.emphasis.mira', 1);
188188
expectScope(tokens, 'f', 'entity.name.function.emphasis.mira');
189189
expectScope(tokens, 'value', 'variable.other.constant.emphasis.mira');
190190
expectScope(tokens, 'type', 'keyword.operator.expression.mira');
191191
expectScope(tokens, 'data', 'variable.other.mira', 2);
192192
});
193193

194+
test('keeps nested types in unlabelled and module function signatures', () => {
195+
const tokens = tokenize(
196+
[
197+
'fn map(',
198+
' data: array | record,',
199+
' f: fn(value: any, key: number | string, input: type(data)) -> any,',
200+
') -> type(data)',
201+
'mod matrix {',
202+
' pub fn entrywise(',
203+
' a: any | any[] | any[][],',
204+
' b: any | any[] | any[][],',
205+
' f: fn(a: any, b: any) -> any,',
206+
' ) -> any | any[] | any[][];',
207+
'}',
208+
].join('\n'),
209+
'mirascript-doc',
210+
);
211+
const declarationFns = tokens.filter((token) => token.text === 'fn' && (token.line === 0 || token.line === 5));
212+
const typeFns = tokens.filter((token) => token.text === 'fn' && (token.line === 2 || token.line === 8));
213+
assert.equal(declarationFns.length, 2);
214+
assert.equal(typeFns.length, 2);
215+
for (const token of declarationFns) {
216+
assert.ok(token.scopes.includes('keyword.declaration.function.mira'), token.scopes.join(', '));
217+
assert.ok(!token.scopes.includes('support.type.function.mira'), token.scopes.join(', '));
218+
}
219+
for (const token of typeFns) {
220+
assert.ok(token.scopes.includes('support.type.function.mira'), token.scopes.join(', '));
221+
assert.ok(!token.scopes.includes('keyword.declaration.function.mira'), token.scopes.join(', '));
222+
}
223+
for (const token of tokens.filter((token) => token.text === 'type')) {
224+
assert.ok(token.scopes.includes('keyword.operator.expression.mira'), token.scopes.join(', '));
225+
}
226+
assert.equal(tokens.filter((token) => token.text === 'type').length, 2);
227+
for (const token of tokens.filter((token) => token.text === 'data' && (token.line === 2 || token.line === 3))) {
228+
assert.ok(token.scopes.includes('variable.other.mira'), token.scopes.join(', '));
229+
}
230+
assert.equal(tokens.filter((token) => token.text === 'data' && (token.line === 2 || token.line === 3)).length, 2);
231+
});
232+
194233
test('keeps tuple and array element types inside their type context', () => {
195234
const tokens = tokenize(
196235
[

0 commit comments

Comments
 (0)