diff --git a/README.md b/README.md
index b014fa4..1544da3 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ VHDL formatter web online written in javascript
- fix exponential notation
- user can choose EOL symbols (or use system's by default)
- align comments (when user chooses "align" option)
+- bugfix "extra whitespaces around unary minus or plus"
Many thanks to [@MihaiBabiac](https://github.com/MihaiBabiac)
diff --git a/VHDLFormatter.js b/VHDLFormatter.js
index b4c24f4..32236c9 100644
--- a/VHDLFormatter.js
+++ b/VHDLFormatter.js
@@ -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);
diff --git a/VHDLFormatter.ts b/VHDLFormatter.ts
index 7f751a2..a7e8d6c 100644
--- a/VHDLFormatter.ts
+++ b/VHDLFormatter.ts
@@ -230,6 +230,8 @@ export function beautify(input: string, settings: BeautifierSettings) {
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");
@@ -239,18 +241,13 @@ export function beautify(input: string, settings: BeautifierSettings) {
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
@@ -267,7 +264,7 @@ export function beautify(input: string, settings: BeautifierSettings) {
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 ');
@@ -281,7 +278,11 @@ export function beautify(input: string, settings: BeautifierSettings) {
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: (FormattedLine | FormattedLine[])[] = [];
beautify3(arr, result, settings, 0, 0);
diff --git a/index.html b/index.html
index 0fd1a26..15881df 100644
--- a/index.html
+++ b/index.html
@@ -311,7 +311,7 @@