Skip to content

Commit 564edb8

Browse files
authored
refactor: move syntax grammars to TS definitions (#592)
* refactor: move syntax grammars to TS definitions This commit refactors remaining existing grammars to use TS definitions as started in #581. * fixup! refactor: move syntax grammars to TS definitions
1 parent 4dcfd5f commit 564edb8

File tree

7 files changed

+100
-178
lines changed

7 files changed

+100
-178
lines changed

scripts/build.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ cp server/package.json server/yarn.lock server/README.md dist/server
2222
node syntaxes/out/build.js
2323
mkdir dist/syntaxes
2424
cp syntaxes/out/*.json dist/syntaxes
25-
# TODO: Remove the next two lines once all syntaxes have been refactored to TypeScript
26-
cp syntaxes/*.json dist/syntaxes
27-
rm dist/syntaxes/tsconfig.json
2825

2926
pushd dist
3027
yarn install --production --ignore-scripts

syntaxes/inline-styles.json

Lines changed: 0 additions & 95 deletions
This file was deleted.

syntaxes/inline-template.json

Lines changed: 0 additions & 78 deletions
This file was deleted.

syntaxes/src/build.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import * as fs from 'fs';
1010

1111
import {GrammarDefinition, JsonObject} from './types';
1212
import {template} from './template/grammar';
13+
import {InlineTemplate} from './inline-template';
14+
import {InlineStyles} from './inline-styles';
1315

1416
// Recursively transforms a TypeScript grammar definition into an object which can be processed by
1517
// JSON.stringify to generate a valid TextMate JSON grammar definition
@@ -41,3 +43,5 @@ function build(grammar: GrammarDefinition, filename: string): void {
4143
}
4244

4345
build(template, 'template');
46+
build(InlineTemplate, 'inline-template');
47+
build(InlineStyles, 'inline-styles');

syntaxes/src/inline-styles.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {GrammarDefinition} from './types';
10+
11+
export const InlineStyles: GrammarDefinition = {
12+
scopeName: 'inline-styles.ng',
13+
injectionSelector: 'L:source.ts#meta.decorator.ts -comment',
14+
patterns: [{include: '#inlineStyles'}],
15+
repository: {
16+
inlineStyles: {
17+
begin: /(styles)\s*(:)/,
18+
beginCaptures: {
19+
1: {name: 'meta.object-literal.key.ts'},
20+
2: {name: 'meta.object-literal.key.ts punctuation.separator.key-value.ts'}
21+
},
22+
end: /(?=,|})/,
23+
patterns: [{include: '#tsParenExpression'}, {include: '#tsBracketExpression'}]
24+
},
25+
26+
tsParenExpression: {
27+
begin: /\G\s*(\()/,
28+
beginCaptures: {1: {name: 'meta.brace.round.ts'}},
29+
end: /\)/,
30+
endCaptures: {0: {name: 'meta.brace.round.ts'}},
31+
patterns: [{include: '$self'}, {include: '#tsBracketExpression'}]
32+
},
33+
34+
'tsBracketExpression': {
35+
begin: /\G\s*(\[)/,
36+
beginCaptures: {1: {name: 'meta.array.literal.ts meta.brace.square.ts'}},
37+
end: /\]/,
38+
endCaptures: {0: {name: 'meta.array.literal.ts meta.brace.square.ts'}},
39+
patterns: [{include: '#style'}]
40+
},
41+
42+
style: {
43+
begin: /\s*([`|'|"])/,
44+
beginCaptures: {1: {name: 'string'}},
45+
end: /\1/,
46+
endCaptures: {0: {name: 'string'}},
47+
contentName: 'source.css',
48+
patterns: [{include: 'source.css'}]
49+
}
50+
}
51+
}

syntaxes/src/inline-template.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {GrammarDefinition} from './types';
10+
11+
export const InlineTemplate: GrammarDefinition = {
12+
scopeName: 'inline-template.ng',
13+
injectionSelector: 'L:meta.decorator.ts -comment',
14+
patterns: [{include: '#inlineTemplate'}],
15+
repository: {
16+
inlineTemplate: {
17+
begin: /(template)\s*(:)/,
18+
beginCaptures: {
19+
1: {name: 'meta.object-literal.key.ts'},
20+
2: {name: 'meta.object-literal.key.ts punctuation.separator.key-value.ts'}
21+
},
22+
end: /(?=,|})/,
23+
patterns: [{include: '#tsParenExpression'}, {include: '#ngTemplate'}]
24+
},
25+
26+
tsParenExpression: {
27+
begin: /\G\s*(\()/,
28+
beginCaptures: {1: {name: 'meta.brace.round.ts'}},
29+
end: /\)/,
30+
endCaptures: {0: {name: 'meta.brace.round.ts'}},
31+
patterns: [{include: '#tsParenExpression'}, {include: '#ngTemplate'}]
32+
},
33+
34+
ngTemplate: {
35+
begin: /\G\s*([`|'|"])/,
36+
beginCaptures: {1: {name: 'string'}},
37+
end: /\1/,
38+
endCaptures: {0: {name: 'string'}},
39+
contentName: 'text.html',
40+
patterns: [{include: 'text.html.derivative'}, {include: 'template.ng'}]
41+
}
42+
}
43+
}

syntaxes/test/cases.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"name": "inline template",
44
"scopeName": "inline-template.ng",
55
"grammarFiles": [
6-
"syntaxes/inline-template.json",
6+
"syntaxes/out/inline-template.json",
77
"syntaxes/out/template.json"
88
],
99
"testFile": "syntaxes/test/data/inline-template.ts"
1010
},
1111
{
1212
"name": "inline styles",
1313
"scopeName": "inline-styles.ng",
14-
"grammarFiles": ["syntaxes/inline-styles.json"],
14+
"grammarFiles": ["syntaxes/out/inline-styles.json"],
1515
"testFile": "syntaxes/test/data/inline-styles.ts"
1616
},
1717
{

0 commit comments

Comments
 (0)