Skip to content

Commit

Permalink
refactor: move syntax grammars to TS definitions (#592)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ayazhafiz authored Jan 29, 2020
1 parent 4dcfd5f commit 564edb8
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 178 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'}]
}
}
}
4 changes: 2 additions & 2 deletions syntaxes/test/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"name": "inline template",
"scopeName": "inline-template.ng",
"grammarFiles": [
"syntaxes/inline-template.json",
"syntaxes/out/inline-template.json",
"syntaxes/out/template.json"
],
"testFile": "syntaxes/test/data/inline-template.ts"
},
{
"name": "inline styles",
"scopeName": "inline-styles.ng",
"grammarFiles": ["syntaxes/inline-styles.json"],
"grammarFiles": ["syntaxes/out/inline-styles.json"],
"testFile": "syntaxes/test/data/inline-styles.ts"
},
{
Expand Down

0 comments on commit 564edb8

Please sign in to comment.