diff --git a/README.md b/README.md index 33ea557..b014fa4 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ VHDL formatter web online written in javascript ### 2.4 [2018-02-23] - use local storage to store settings +- add `main.js` ### 2.3 [2018-02-22] @@ -17,6 +18,7 @@ VHDL formatter web online written in javascript - support extended identifier (backslash names) - fix exponential notation - user can choose EOL symbols (or use system's by default) +- align comments (when user chooses "align" option) Many thanks to [@MihaiBabiac](https://github.com/MihaiBabiac) diff --git a/VHDLFormatter.js b/VHDLFormatter.js index d0c670b..14baab5 100644 --- a/VHDLFormatter.js +++ b/VHDLFormatter.js @@ -82,76 +82,6 @@ Array.prototype.convertToRegexBlockWords = function () { let result = new RegExp("(" + wordsStr + ")([^\\w]|$)"); return result; }; -function wordWrap() { - var d = document.getElementById("result"); - if (d.className == "") { - d.className = "wordwrap"; - } - else { - d.className = ""; - } -} -function getHTMLInputElement(id) { - return document.getElementById(id); -} -function noFormat() { - let elements = [ - "remove_comments", - "remove_lines", - "remove_report", - "check_alias", - "sign_align_in", - "sign_align_port", - "sign_align_generic", - "sign_align_function", - "sign_align_procedure", - "sign_align_all", - "new_line_after", - "use_space", - "customise_indentation", - "compress", - "mix_letter", - "cust_eol" - ]; - var isDisabled = getHTMLInputElement("no_format").checked; - elements.forEach(element => { - var htmlElement = getHTMLInputElement(element + "_div"); - try { - getHTMLInputElement(element).disabled = isDisabled; - } - catch (_a) { } - if (isDisabled) { - htmlElement.className += " disabled"; - } - else { - htmlElement.className = htmlElement.className.replace(/\bdisabled\b/g, ""); - } - }); - let radioButtons = document.getElementsByTagName("input"); - for (let i = 0; i < radioButtons.length; i++) { - if (radioButtons[i].type == "radio") { - radioButtons[i].disabled = isDisabled; - } - } -} -function Compress(input) { - input = input.replace(/\r\n/g, ''); - input = input.replace(/[\t ]+/g, ' '); - input = input.replace(/[ ]?([&=:\-<>\+|])[ ]?/g, '$1'); - return input; -} -function MixLetters(input) { - let arr = input.split(""); - for (var k = 0; k < arr.length; k++) { - if (arr[k] === arr[k].toUpperCase() && Math.random() > 0.5) { - arr[k] = arr[k].toLowerCase(); - } - else if (Math.random() > 0.5) { - arr[k] = arr[k].toUpperCase(); - } - } - return arr.join(""); -} function EscapeComments(arr) { var comments = []; var count = 0; @@ -446,8 +376,9 @@ exports.beautifyPortGenericBlock = beautifyPortGenericBlock; function AlignSigns(result, startIndex, endIndex) { AlignSign_(result, startIndex, endIndex, ":"); AlignSign_(result, startIndex, endIndex, ":="); - AlignSign_(result, startIndex, endIndex, "=>"); AlignSign_(result, startIndex, endIndex, "<="); + AlignSign_(result, startIndex, endIndex, "=>"); + AlignSign_(result, startIndex, endIndex, "@@comments"); } exports.AlignSigns = AlignSigns; function AlignSign_(result, startIndex, endIndex, symbol) { diff --git a/VHDLFormatter.ts b/VHDLFormatter.ts index 41eb49a..c635660 100644 --- a/VHDLFormatter.ts +++ b/VHDLFormatter.ts @@ -53,7 +53,6 @@ function ConstructNewLineSettings(dict): NewLineSettings { return settings; } - declare global { interface String { regexIndexOf: (pattern: RegExp, startIndex?: number) => number; @@ -112,79 +111,6 @@ Array.prototype.convertToRegexBlockWords = function (): RegExp { return result; } -function wordWrap() { - var d = document.getElementById("result"); - if (d.className == "") { - d.className = "wordwrap"; - } else { - d.className = ""; - } -} - -function getHTMLInputElement(id: string): HTMLInputElement { - return document.getElementById(id); -} - -function noFormat() { - let elements: Array = [ - "remove_comments", - "remove_lines", - "remove_report", - "check_alias", - "sign_align_in", - "sign_align_port", - "sign_align_generic", - "sign_align_function", - "sign_align_procedure", - "sign_align_all", - "new_line_after", - "use_space", - "customise_indentation", - "compress", - "mix_letter", - "cust_eol" - ]; - var isDisabled = getHTMLInputElement("no_format").checked; - elements.forEach(element => { - var htmlElement = getHTMLInputElement(element + "_div"); - try { - getHTMLInputElement(element).disabled = isDisabled; - } - catch{ } - if (isDisabled) { - htmlElement.className += " disabled"; - } - else { - htmlElement.className = htmlElement.className.replace(/\bdisabled\b/g, ""); - } - }); - let radioButtons = >document.getElementsByTagName("input"); - for (let i = 0; i < radioButtons.length; i++) { - if ((radioButtons[i]).type == "radio") { - (radioButtons[i]).disabled = isDisabled; - } - } -} - -function Compress(input: string) { - input = input.replace(/\r\n/g, ''); - input = input.replace(/[\t ]+/g, ' '); - input = input.replace(/[ ]?([&=:\-<>\+|])[ ]?/g, '$1'); - return input; -} - -function MixLetters(input: string) { - let arr = input.split(""); - for (var k = 0; k < arr.length; k++) { - if (arr[k] === arr[k].toUpperCase() && Math.random() > 0.5) { - arr[k] = arr[k].toLowerCase(); - } else if (Math.random() > 0.5) { - arr[k] = arr[k].toUpperCase(); - } - } - return arr.join(""); -} - function EscapeComments(arr: Array): Array { var comments = []; var count = 0; @@ -514,8 +440,9 @@ export function beautifyPortGenericBlock(inputs: Array, result: (Formatt export function AlignSigns(result: (FormattedLine | FormattedLine[])[], startIndex: number, endIndex: number) { AlignSign_(result, startIndex, endIndex, ":"); AlignSign_(result, startIndex, endIndex, ":="); - AlignSign_(result, startIndex, endIndex, "=>"); AlignSign_(result, startIndex, endIndex, "<="); + AlignSign_(result, startIndex, endIndex, "=>"); + AlignSign_(result, startIndex, endIndex, "@@comments"); } function AlignSign_(result: (FormattedLine | FormattedLine[])[], startIndex: number, endIndex: number, symbol: string) { diff --git a/index.html b/index.html index 8d5dca4..0fd1a26 100644 --- a/index.html +++ b/index.html @@ -420,6 +420,7 @@ +