Skip to content

Commit

Permalink
refactor: move syntax grammars to TS definitions
Browse files Browse the repository at this point in the history
This commit refactors remaining existing grammars to use TS definitions
as started in angular#581.
  • Loading branch information
ayazhafiz committed Jan 29, 2020
1 parent 4dcfd5f commit 96c0a9b
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 176 deletions.
3 changes: 0 additions & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ cp server/package.json server/yarn.lock server/README.md dist/server
node syntaxes/out/build.js
mkdir dist/syntaxes
cp syntaxes/out/*.json dist/syntaxes
# TODO: Remove the next two lines once all syntaxes have been refactored to TypeScript
cp syntaxes/*.json dist/syntaxes
rm dist/syntaxes/tsconfig.json

pushd dist
yarn install --production --ignore-scripts
Expand Down
95 changes: 0 additions & 95 deletions syntaxes/inline-styles.json

This file was deleted.

78 changes: 0 additions & 78 deletions syntaxes/inline-template.json

This file was deleted.

4 changes: 4 additions & 0 deletions syntaxes/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import * as fs from 'fs';

import {GrammarDefinition, JsonObject} from './types';
import {template} from './template/grammar';
import {InlineTemplate} from './inline-template';
import {InlineStyles} from './inline-styles';

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

build(template, 'template');
build(InlineTemplate, 'inline-template');
build(InlineStyles, 'inline-styles');
51 changes: 51 additions & 0 deletions syntaxes/src/inline-styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {GrammarDefinition} from './types';

export const InlineStyles: GrammarDefinition = {
scopeName: 'inline-styles.ng',
injectionSelector: 'L:source.ts#meta.decorator.ts -comment',
patterns: [{include: '#inlineStyles'}],
repository: {
inlineStyles: {
begin: /(styles)\s*(:)/,
beginCaptures: {
1: {name: 'meta.object-literal.key.ts'},
2: {name: 'meta.object-literal.key.ts punctuation.separator.key-value.ts'}
},
end: /(?=,|})/,
patterns: [{include: '#tsParenExpression'}, {include: '#tsBracketExpression'}]
},

tsParenExpression: {
begin: /\G\s*(\()/,
beginCaptures: {1: {name: 'meta.brace.round.ts'}},
end: /\)/,
endCaptures: {0: {name: 'meta.brace.round.ts'}},
patterns: [{include: '$self'}, {include: '#tsBracketExpression'}]
},

'tsBracketExpression': {
begin: /\G\s*(\[)/,
beginCaptures: {1: {name: 'meta.array.literal.ts meta.brace.square.ts'}},
end: /\]/,
endCaptures: {0: {name: 'meta.array.literal.ts meta.brace.square.ts'}},
patterns: [{include: '#style'}]
},

style: {
begin: /\s*([`|'|"])/,
beginCaptures: {1: {name: 'string'}},
end: /\1/,
endCaptures: {0: {name: 'string'}},
contentName: 'source.css',
patterns: [{include: 'source.css'}]
}
}
}
43 changes: 43 additions & 0 deletions syntaxes/src/inline-template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {GrammarDefinition} from './types';

export const InlineTemplate: GrammarDefinition = {
scopeName: 'inline-template.ng',
injectionSelector: 'L:meta.decorator.ts -comment',
patterns: [{include: '#inlineTemplate'}],
repository: {
inlineTemplate: {
begin: /(template)\s*(:)/,
beginCaptures: {
1: {name: 'meta.object-literal.key.ts'},
2: {name: 'meta.object-literal.key.ts punctuation.separator.key-value.ts'}
},
end: /(?=,|})/,
patterns: [{include: '#tsParenExpression'}, {include: '#ngTemplate'}]
},

tsParenExpression: {
begin: /\G\s*(\()/,
beginCaptures: {1: {name: 'meta.brace.round.ts'}},
end: /\)/,
endCaptures: {0: {name: 'meta.brace.round.ts'}},
patterns: [{include: '#tsParenExpression'}, {include: '#ngTemplate'}]
},

ngTemplate: {
begin: /\G\s*([`|'|"])/,
beginCaptures: {1: {name: 'string'}},
end: /\1/,
endCaptures: {0: {name: 'string'}},
contentName: 'text.html',
patterns: [{include: 'text.html.derivative'}, {include: 'template.ng'}]
}
}
}

0 comments on commit 96c0a9b

Please sign in to comment.