|
|
@ -181,6 +181,8 @@ function beautify(input, settings) { |
|
|
|
var arr = input.split("\r\n"); |
|
|
|
var comments = EscapeComments(arr); |
|
|
|
var backslashes = escapeText(arr, "\\\\[^\\\\]+\\\\", ILBackslash); |
|
|
|
let quotes = escapeText(arr, '"([^"]+)"', ILQuote); |
|
|
|
let singleQuotes = escapeText(arr, "'[^']'", ILSingleQuote); |
|
|
|
RemoveLeadingWhitespaces(arr); |
|
|
|
input = arr.join("\r\n"); |
|
|
|
if (settings.RemoveComments) { |
|
|
@ -188,17 +190,13 @@ function beautify(input, settings) { |
|
|
|
input = input.replace(/@@comments[0-9]+/g, ''); |
|
|
|
comments = []; |
|
|
|
} |
|
|
|
input = SetKeywordCase(input, "uppercase", KeyWords, TypeNames); |
|
|
|
input = RemoveExtraNewLines(input); |
|
|
|
input = input.replace(/[\t ]+/g, ' '); |
|
|
|
input = input.replace(/\([\t ]+/g, '\('); |
|
|
|
input = input.replace(/[ ]+;/g, ';'); |
|
|
|
input = input.replace(/:[ ]*(PROCESS|ENTITY)/gi, ':$1'); |
|
|
|
arr = input.split("\r\n"); |
|
|
|
let quotes = escapeText(arr, '"([^"]+)"', ILQuote); |
|
|
|
let singleQuotes = escapeText(arr, "'[^']'", ILSingleQuote); |
|
|
|
input = arr.join("\r\n"); |
|
|
|
input = SetKeywordCase(input, "uppercase", KeyWords, TypeNames); |
|
|
|
arr = input.split("\r\n"); |
|
|
|
if (settings.RemoveAsserts) { |
|
|
|
RemoveAsserts(arr); //RemoveAsserts must be after EscapeQuotes
|
|
|
|
} |
|
|
@ -212,7 +210,7 @@ function beautify(input, settings) { |
|
|
|
input = arr.join("\r\n"); |
|
|
|
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(/(\d+e) +([+\-]) +(\d+)/g, '$1$2$3'); // Fix exponential notation format broken by previous step
|
|
|
|
input = input.replace(/(\d+e) +([+\-]) +(\d+)/g, '$1$2$3'); // fix exponential notation format broken by previous step
|
|
|
|
input = input.replace(/[ ]?([,])[ ]?/g, '$1 '); |
|
|
|
input = input.replace(/[ ]?(['"])(THEN)/g, '$1 $2'); |
|
|
|
input = input.replace(/[ ]?(\?)?[ ]?(<|:|>|\/)?[ ]+(=)?[ ]?/g, ' $1$2$3 '); |
|
|
@ -226,7 +224,11 @@ function beautify(input, settings) { |
|
|
|
input = input.replace(/\r\n\r\n\r\n/g, '\r\n'); |
|
|
|
input = input.replace(/[\r\n\s]+$/g, ''); |
|
|
|
input = input.replace(/[ \t]+\)/g, ')'); |
|
|
|
input = input.replace(/\s*\)\s+RETURN\s+([\w]+;)/g, '\r\n) RETURN $1'); //function(..\r\n)return type; -> function(..\r\n)return type;
|
|
|
|
input = input.replace(/\s*\)\s+RETURN\s+([\w]+;)/g, '\r\n) RETURN $1'); //function(..)\r\nreturn type; -> function(..\r\n)return type;
|
|
|
|
let keywordAndSignRegex = new RegExp("(\\b" + KeyWords.join("\\b|\\b") + "\\b) +([\\-+]) +(\\w)", "g"); |
|
|
|
input = input.replace(keywordAndSignRegex, "$1 $2$3"); // `WHEN - 2` -> `WHEN -2`
|
|
|
|
input = input.replace(/([,|]) +([+\-]) +(\w)/g, '$1 $2$3'); // `1, - 2)` -> `1, -2)`
|
|
|
|
input = input.replace(/(\() +([+\-]) +(\w)/g, '$1$2$3'); // `( - 2)` -> `(-2)`
|
|
|
|
arr = input.split("\r\n"); |
|
|
|
let result = []; |
|
|
|
beautify3(arr, result, settings, 0, 0); |
|
|
|