|
@ -1,9 +1,11 @@ |
|
|
"use strict"; |
|
|
"use strict"; |
|
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
|
let isTesting = false; |
|
|
let isTesting = false; |
|
|
const ILCommentPrefix = "@@comments"; |
|
|
|
|
|
const ILQuotesPrefix = "@@quotes"; |
|
|
|
|
|
const ILSingleQuotesPrefix = "@@singlequotes"; |
|
|
|
|
|
|
|
|
const ILEscape = "@@"; |
|
|
|
|
|
const ILCommentPrefix = ILEscape + "comments"; |
|
|
|
|
|
const ILQuotesPrefix = ILEscape + "quotes"; |
|
|
|
|
|
const ILSingleQuotesPrefix = ILEscape + "singlequotes"; |
|
|
|
|
|
const ILBackslashesPrefix = ILEscape + "backslash"; |
|
|
var FormatMode; |
|
|
var FormatMode; |
|
|
(function (FormatMode) { |
|
|
(function (FormatMode) { |
|
|
FormatMode[FormatMode["Default"] = 0] = "Default"; |
|
|
FormatMode[FormatMode["Default"] = 0] = "Default"; |
|
@ -150,17 +152,19 @@ function MixLetters(input) { |
|
|
} |
|
|
} |
|
|
return arr.join(""); |
|
|
return arr.join(""); |
|
|
} |
|
|
} |
|
|
function EscapeComments(arr, comments, commentIndex) { |
|
|
|
|
|
|
|
|
function EscapeComments(arr) { |
|
|
|
|
|
var comments = []; |
|
|
|
|
|
var count = 0; |
|
|
for (var i = 0; i < arr.length; i++) { |
|
|
for (var i = 0; i < arr.length; i++) { |
|
|
let line = arr[i]; |
|
|
|
|
|
|
|
|
var line = arr[i]; |
|
|
var commentStartIndex = line.indexOf("--"); |
|
|
var commentStartIndex = line.indexOf("--"); |
|
|
if (commentStartIndex >= 0) { |
|
|
if (commentStartIndex >= 0) { |
|
|
comments.push(line.substr(commentStartIndex)); |
|
|
comments.push(line.substr(commentStartIndex)); |
|
|
arr[i] = line.substr(0, commentStartIndex) + ILCommentPrefix + commentIndex; |
|
|
|
|
|
commentIndex++; |
|
|
|
|
|
|
|
|
arr[i] = line.substr(0, commentStartIndex) + ILCommentPrefix + count; |
|
|
|
|
|
count++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return commentIndex; |
|
|
|
|
|
|
|
|
return comments; |
|
|
} |
|
|
} |
|
|
function ToLowerCases(arr) { |
|
|
function ToLowerCases(arr) { |
|
|
for (var i = 0; i < arr.length; i++) { |
|
|
for (var i = 0; i < arr.length; i++) { |
|
@ -243,14 +247,14 @@ function beautify(input, settings) { |
|
|
input = input.replace(/\r\n/g, "\n"); |
|
|
input = input.replace(/\r\n/g, "\n"); |
|
|
input = input.replace(/\n/g, "\r\n"); |
|
|
input = input.replace(/\n/g, "\r\n"); |
|
|
var arr = input.split("\r\n"); |
|
|
var arr = input.split("\r\n"); |
|
|
var comments = [], commentsIndex = 0; |
|
|
|
|
|
commentsIndex = EscapeComments(arr, comments, commentsIndex); |
|
|
|
|
|
|
|
|
var comments = EscapeComments(arr); |
|
|
|
|
|
var backslashes = escapeBackslashes(arr); |
|
|
RemoveLeadingWhitespaces(arr); |
|
|
RemoveLeadingWhitespaces(arr); |
|
|
input = arr.join("\r\n"); |
|
|
input = arr.join("\r\n"); |
|
|
if (settings.RemoveComments) { |
|
|
if (settings.RemoveComments) { |
|
|
input = input.replace(/\r\n[ \t]*@@comments[0-9]+[ \t]*\r\n/g, '\r\n'); |
|
|
input = input.replace(/\r\n[ \t]*@@comments[0-9]+[ \t]*\r\n/g, '\r\n'); |
|
|
input = input.replace(/@@comments[0-9]+/g, ''); |
|
|
input = input.replace(/@@comments[0-9]+/g, ''); |
|
|
commentsIndex = 0; |
|
|
|
|
|
|
|
|
comments = []; |
|
|
} |
|
|
} |
|
|
input = RemoveExtraNewLines(input); |
|
|
input = RemoveExtraNewLines(input); |
|
|
input = input.replace(/[\t ]+/g, ' '); |
|
|
input = input.replace(/[\t ]+/g, ' '); |
|
@ -274,9 +278,10 @@ function beautify(input, settings) { |
|
|
arr = input.split("\r\n"); |
|
|
arr = input.split("\r\n"); |
|
|
ApplyNoNewLineAfter(arr, settings.NewLineSettings.noNewLineAfter); |
|
|
ApplyNoNewLineAfter(arr, settings.NewLineSettings.noNewLineAfter); |
|
|
input = arr.join("\r\n"); |
|
|
input = arr.join("\r\n"); |
|
|
//new
|
|
|
|
|
|
input = input.replace(/([a-zA-Z0-9\); ])\);(@@comments[0-9]+)?@@end/g, '$1\r\n);$2@@end'); |
|
|
input = input.replace(/([a-zA-Z0-9\); ])\);(@@comments[0-9]+)?@@end/g, '$1\r\n);$2@@end'); |
|
|
input = input.replace(/[ ]?([&=:\-<>\+|\*])[ ]?/g, ' $1 '); |
|
|
input = input.replace(/[ ]?([&=:\-<>\+|\*])[ ]?/g, ' $1 '); |
|
|
|
|
|
// Fix reals in expoential format broken by previous step
|
|
|
|
|
|
input = input.replace(/(\d+e) +([+\-]) +(\d+)/g, '$1$2$3'); |
|
|
input = input.replace(/[ ]?([,])[ ]?/g, '$1 '); |
|
|
input = input.replace(/[ ]?([,])[ ]?/g, '$1 '); |
|
|
input = input.replace(/[ ]?(['"])(THEN)/g, '$1 $2'); |
|
|
input = input.replace(/[ ]?(['"])(THEN)/g, '$1 $2'); |
|
|
input = input.replace(/[ ]?(\?)?[ ]?(<|:|>|\/)?[ ]+(=)?[ ]?/g, ' $1$2$3 '); |
|
|
input = input.replace(/[ ]?(\?)?[ ]?(<|:|>|\/)?[ ]+(=)?[ ]?/g, ' $1$2$3 '); |
|
@ -300,20 +305,35 @@ function beautify(input, settings) { |
|
|
arr = FormattedLineToString(result, settings.Indentation); |
|
|
arr = FormattedLineToString(result, settings.Indentation); |
|
|
input = arr.join("\r\n"); |
|
|
input = arr.join("\r\n"); |
|
|
input = SetKeywordCase(input, settings.KeywordCase, KeyWords, TypeNames); |
|
|
input = SetKeywordCase(input, settings.KeywordCase, KeyWords, TypeNames); |
|
|
for (var k = 0; k < quotes.length; k++) { |
|
|
|
|
|
input = input.replace(ILQuotesPrefix + k, quotes[k]); |
|
|
|
|
|
} |
|
|
|
|
|
for (var k = 0; k < singleQuotes.length; k++) { |
|
|
|
|
|
input = input.replace(ILSingleQuotesPrefix + k, singleQuotes[k]); |
|
|
|
|
|
} |
|
|
|
|
|
for (var k = 0; k < commentsIndex; k++) { |
|
|
|
|
|
input = input.replace(ILCommentPrefix + k, comments[k]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
input = replaceEscapedWords(input, quotes, ILQuotesPrefix); |
|
|
|
|
|
input = replaceEscapedWords(input, singleQuotes, ILSingleQuotesPrefix); |
|
|
|
|
|
input = replaceEscapedWords(input, comments, ILCommentPrefix); |
|
|
|
|
|
input = replaceEscapedWords(input, backslashes, ILBackslashesPrefix); |
|
|
input = input.replace(/@@semicolon/g, ";"); |
|
|
input = input.replace(/@@semicolon/g, ";"); |
|
|
input = input.replace(/@@[a-z]+/g, ""); |
|
|
input = input.replace(/@@[a-z]+/g, ""); |
|
|
return input; |
|
|
return input; |
|
|
} |
|
|
} |
|
|
exports.beautify = beautify; |
|
|
exports.beautify = beautify; |
|
|
|
|
|
function replaceEscapedWords(input, arr, prefix) { |
|
|
|
|
|
for (var i = 0; i < arr.length; i++) { |
|
|
|
|
|
input = input.replace(prefix + i, arr[i]); |
|
|
|
|
|
} |
|
|
|
|
|
return input; |
|
|
|
|
|
} |
|
|
|
|
|
function escapeBackslashes(arr) { |
|
|
|
|
|
var escaped = []; |
|
|
|
|
|
var count = 0; |
|
|
|
|
|
for (var i = 0; i < arr.length; i++) { |
|
|
|
|
|
var sequence = arr[i].match(/\\[^\\]+\\/g); |
|
|
|
|
|
if (sequence != null) { |
|
|
|
|
|
for (var j = 0; j < sequence.length; j++) { |
|
|
|
|
|
arr[i] = arr[i].replace(sequence[j], ILBackslashesPrefix + count); |
|
|
|
|
|
escaped[count++] = sequence[j]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return escaped; |
|
|
|
|
|
} |
|
|
function RemoveLeadingWhitespaces(arr) { |
|
|
function RemoveLeadingWhitespaces(arr) { |
|
|
for (var i = 0; i < arr.length; i++) { |
|
|
for (var i = 0; i < arr.length; i++) { |
|
|
arr[i] = arr[i].replace(/^\s+/, ""); |
|
|
arr[i] = arr[i].replace(/^\s+/, ""); |
|
|