diff --git a/README.md b/README.md index 66a5b8d..83bd16d 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ VHDL formatter web online written in javascript - add `tests` folder, improve the project management - support extended identifier (backslash names) - fix exponential notation +- user can choose EOL symbols (or use system's by default) + +Many thanks to @MihaiBabiac ### 2.2 [2018-10-16] diff --git a/VHDLFormatter.js b/VHDLFormatter.js index 60b3cec..6eb6d11 100644 --- a/VHDLFormatter.js +++ b/VHDLFormatter.js @@ -229,7 +229,7 @@ function SetNewLinesAfterSymbols(text, newLineSettings) { } exports.SetNewLinesAfterSymbols = SetNewLinesAfterSymbols; class BeautifierSettings { - constructor(removeComments, removeReport, checkAlias, signAlign, signAlignAll, keywordCase, indentation, newLineSettings) { + constructor(removeComments, removeReport, checkAlias, signAlign, signAlignAll, keywordCase, indentation, newLineSettings, endOfLine) { this.RemoveComments = removeComments; this.RemoveAsserts = removeReport; this.CheckAlias = checkAlias; @@ -238,6 +238,7 @@ class BeautifierSettings { this.KeywordCase = keywordCase; this.Indentation = indentation; this.NewLineSettings = newLineSettings; + this.EndOfLine = endOfLine; } } exports.BeautifierSettings = BeautifierSettings; @@ -280,8 +281,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 '); - // Fix reals in expoential format broken by previous step - input = input.replace(/(\d+e) +([+\-]) +(\d+)/g, '$1$2$3'); + 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 '); @@ -311,6 +311,7 @@ function beautify(input, settings) { input = replaceEscapedWords(input, backslashes, ILBackslashesPrefix); input = input.replace(/@@semicolon/g, ";"); input = input.replace(/@@[a-z]+/g, ""); + input = input.replace(/\r\n/g, settings.EndOfLine); return input; } exports.beautify = beautify; diff --git a/VHDLFormatter.ts b/VHDLFormatter.ts index 7ce3ae3..d403c61 100644 --- a/VHDLFormatter.ts +++ b/VHDLFormatter.ts @@ -277,10 +277,11 @@ export class BeautifierSettings { SignAlignKeyWords: Array; KeywordCase: string; Indentation: string; - NewLineSettings: NewLineSettings + NewLineSettings: NewLineSettings; + EndOfLine: string; constructor(removeComments: boolean, removeReport: boolean, checkAlias: boolean, signAlign: boolean, signAlignAll: boolean, keywordCase: string, indentation: string, - newLineSettings: NewLineSettings) { + newLineSettings: NewLineSettings, endOfLine: string) { this.RemoveComments = removeComments; this.RemoveAsserts = removeReport; this.CheckAlias = checkAlias; @@ -289,6 +290,7 @@ export class BeautifierSettings { this.KeywordCase = keywordCase; this.Indentation = indentation; this.NewLineSettings = newLineSettings; + this.EndOfLine = endOfLine; } } @@ -371,6 +373,7 @@ export function beautify(input: string, settings: BeautifierSettings) { input = input.replace(/@@semicolon/g, ";"); input = input.replace(/@@[a-z]+/g, ""); + input = input.replace(/\r\n/g, settings.EndOfLine); return input; } diff --git a/descriptiveCounter.js b/descriptiveCounter.js index 37deb63..253e59e 100644 --- a/descriptiveCounter.js +++ b/descriptiveCounter.js @@ -1,12 +1,14 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -function indent_decode() { - var custom_indent = document.getElementById("cust_indent").value; +function counterDecode(inputId, outputId) { + var custom_indent = document.getElementById(inputId).value; var result = descriptiveCounter(custom_indent); - document.getElementById("indent_s").innerHTML = result; + document.getElementById(outputId).innerHTML = result; } function descriptiveCounter(input) { input = input.replace(/\\t/g, " "); + input = input.replace(/\\r/g, "\r"); + input = input.replace(/\\n/g, "\n"); var tokens = input.split(""); var result = ""; var repeatedCharCount = 0; @@ -23,6 +25,12 @@ function descriptiveCounter(input) { case "\t": char = "tab"; break; + case "\n": + char = "\\n"; + break; + case "\r": + char = "\\r"; + break; default: char = "'" + char + "'"; } diff --git a/descriptiveCounter.ts b/descriptiveCounter.ts index 963e1c3..3a353a0 100644 --- a/descriptiveCounter.ts +++ b/descriptiveCounter.ts @@ -1,12 +1,14 @@ -function indent_decode() { - var custom_indent: string = (document.getElementById("cust_indent")).value; +function counterDecode(inputId: string, outputId: string) { + var custom_indent: string = (document.getElementById(inputId)).value; var result: string = descriptiveCounter(custom_indent); - document.getElementById("indent_s").innerHTML = result; + document.getElementById(outputId).innerHTML = result; } export function descriptiveCounter(input: string): string { input = input.replace(/\\t/g, " "); - + input = input.replace(/\\r/g, "\r"); + input = input.replace(/\\n/g, "\n"); + var tokens: Array = input.split(""); var result = ""; var repeatedCharCount = 0; @@ -22,6 +24,12 @@ export function descriptiveCounter(input: string): string { case "\t": char = "tab"; break; + case "\n": + char = "\\n"; + break; + case "\r": + char = "\\r"; + break; default: char = "'" + char + "'"; } diff --git a/index.html b/index.html index d4ae014..9e58d4f 100644 --- a/index.html +++ b/index.html @@ -253,47 +253,47 @@
THEN + New Line + No New Line + None
semicolon ";" + New Line + No New Line + None
ELSE + New Line + No New Line + None
PORT | PORT MAP + New Line + No New Line + None
GENERIC + New Line + No New Line + None
@@ -340,7 +340,7 @@
(tab is \t) - ( + ( four blankspaces)
@@ -351,10 +351,14 @@
+
+ End of line: + ( + one \r & one \n) +
- +
@@ -417,6 +421,9 @@