Skip to content

Commit 85ffc40

Browse files
committed
update builder
1 parent e60384e commit 85ffc40

File tree

2 files changed

+8
-96
lines changed

2 files changed

+8
-96
lines changed

build/build.js

+4-44
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,12 @@ function readJson(fileName) {
1010
var text = fs.readFileSync(fileName, "utf8");
1111
return JSON.parse(text);
1212
}
13-
function transformGrammarRule(rule, propertyNames, transformProperty) {
14-
for (var _i = 0, propertyNames_1 = propertyNames; _i < propertyNames_1.length; _i++) {
15-
var propertyName_1 = propertyNames_1[_i];
16-
var value = rule[propertyName_1];
17-
if (typeof value === 'string') {
18-
rule[propertyName_1] = transformProperty(value);
19-
}
20-
}
21-
for (var propertyName in rule) {
22-
var value = rule[propertyName];
23-
if (typeof value === 'object') {
24-
transformGrammarRule(value, propertyNames, transformProperty);
25-
}
26-
}
27-
}
28-
function transformGrammarRepository(grammar, propertyNames, transformProperty) {
29-
var repository = grammar.repository;
30-
for (var key in repository) {
31-
transformGrammarRule(repository[key], propertyNames, transformProperty);
32-
}
33-
}
34-
function getLuaGrammar(getVariables) {
35-
var luaGrammarBeforeTransformation = readJson('lua.tmLanguage.json');
36-
return updateGrammarVariables(luaGrammarBeforeTransformation, getVariables(luaGrammarBeforeTransformation.variables));
37-
}
38-
function replacePatternVariables(pattern, variableReplacers) {
39-
var result = pattern;
40-
for (var _i = 0, variableReplacers_1 = variableReplacers; _i < variableReplacers_1.length; _i++) {
41-
var _a = variableReplacers_1[_i], variableName = _a[0], value = _a[1];
42-
result = result.replace(variableName, value);
43-
}
44-
return result;
45-
}
46-
function updateGrammarVariables(grammar, variables) {
47-
delete grammar.variables;
48-
var variableReplacers = [];
49-
for (var variableName in variables) {
50-
// Replace the pattern with earlier variables
51-
var pattern = replacePatternVariables(variables[variableName], variableReplacers);
52-
variableReplacers.push([new RegExp("{{" + variableName + "}}", "gim"), pattern]);
53-
}
54-
transformGrammarRepository(grammar, ["begin", "end", "match"], function (pattern) { return replacePatternVariables(pattern, variableReplacers); });
55-
return grammar;
13+
function getLuaGrammar() {
14+
var luaGrammar = readJson('lua.tmLanguage.json');
15+
return luaGrammar;
5616
}
5717
function buildGrammar() {
58-
var luaGrammar = getLuaGrammar(function (grammarVariables) { return grammarVariables; });
18+
var luaGrammar = getLuaGrammar();
5919
// Write TypeScript.tmLanguage
6020
writePlistFile(luaGrammar, 'Syntaxes/Lua.plist');
6121
}

build/build.ts

+4-52
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,13 @@ function readJson(fileName: string) {
1111
return JSON.parse(text);
1212
}
1313

14-
function transformGrammarRule(rule: any, propertyNames: string[], transformProperty: (ruleProperty: string) => string) {
15-
for (const propertyName of propertyNames) {
16-
const value = rule[propertyName];
17-
if (typeof value === 'string') {
18-
rule[propertyName] = transformProperty(value);
19-
}
20-
}
21-
22-
for (var propertyName in rule) {
23-
const value = rule[propertyName];
24-
if (typeof value === 'object') {
25-
transformGrammarRule(value, propertyNames, transformProperty);
26-
}
27-
}
28-
}
29-
30-
function transformGrammarRepository(grammar: TmGrammar, propertyNames: string[], transformProperty: (ruleProperty: string) => string) {
31-
const repository = grammar.repository;
32-
for (let key in repository) {
33-
transformGrammarRule(repository[key], propertyNames, transformProperty);
34-
}
35-
}
36-
37-
function getLuaGrammar(getVariables: (luaGrammarVariables: MapLike<string>) => MapLike<string>) {
38-
const luaGrammarBeforeTransformation = readJson('lua.tmLanguage.json') as TmGrammar;
39-
return updateGrammarVariables(luaGrammarBeforeTransformation, getVariables(luaGrammarBeforeTransformation.variables as MapLike<string>));
40-
}
41-
42-
function replacePatternVariables(pattern: string, variableReplacers: VariableReplacer[]) {
43-
let result = pattern;
44-
for (const [variableName, value] of variableReplacers) {
45-
result = result.replace(variableName, value);
46-
}
47-
return result;
48-
}
49-
50-
type VariableReplacer = [RegExp, string];
51-
function updateGrammarVariables(grammar: TmGrammar, variables: MapLike<string>) {
52-
delete grammar.variables;
53-
const variableReplacers: VariableReplacer[] = [];
54-
for (const variableName in variables) {
55-
// Replace the pattern with earlier variables
56-
const pattern = replacePatternVariables(variables[variableName], variableReplacers);
57-
variableReplacers.push([new RegExp(`{{${variableName}}}`, "gim"), pattern]);
58-
}
59-
transformGrammarRepository(
60-
grammar,
61-
["begin", "end", "match"],
62-
pattern => replacePatternVariables(pattern, variableReplacers)
63-
);
64-
return grammar;
14+
function getLuaGrammar() {
15+
const luaGrammar = readJson('lua.tmLanguage.json') as TmGrammar;
16+
return luaGrammar;
6517
}
6618

6719
function buildGrammar() {
68-
const luaGrammar = getLuaGrammar(grammarVariables => grammarVariables);
20+
const luaGrammar = getLuaGrammar();
6921

7022
// Write TypeScript.tmLanguage
7123
writePlistFile(luaGrammar, 'Syntaxes/Lua.plist');

0 commit comments

Comments
 (0)