Browse Source

align comments (when user chooses "align" option); add main.js

master
g2384 5 years ago
parent
commit
e52d527bb4
8 changed files with 171 additions and 146 deletions
  1. +2
    -0
      README.md
  2. +2
    -71
      VHDLFormatter.js
  3. +2
    -75
      VHDLFormatter.ts
  4. +1
    -0
      index.html
  5. +71
    -0
      main.js
  6. +72
    -0
      main.ts
  7. +20
    -0
      tests/VHDLFormatterUnitTests.ts
  8. +1
    -0
      tsconfig.json

+ 2
- 0
README.md View File

@ -9,6 +9,7 @@ VHDL formatter web online written in javascript
### 2.4 [2018-02-23] ### 2.4 [2018-02-23]
- use local storage to store settings - use local storage to store settings
- add `main.js`
### 2.3 [2018-02-22] ### 2.3 [2018-02-22]
@ -17,6 +18,7 @@ VHDL formatter web online written in javascript
- support extended identifier (backslash names) - support extended identifier (backslash names)
- fix exponential notation - fix exponential notation
- user can choose EOL symbols (or use system's by default) - 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) Many thanks to [@MihaiBabiac](https://github.com/MihaiBabiac)


+ 2
- 71
VHDLFormatter.js View File

@ -82,76 +82,6 @@ Array.prototype.convertToRegexBlockWords = function () {
let result = new RegExp("(" + wordsStr + ")([^\\w]|$)"); let result = new RegExp("(" + wordsStr + ")([^\\w]|$)");
return result; 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) { function EscapeComments(arr) {
var comments = []; var comments = [];
var count = 0; var count = 0;
@ -446,8 +376,9 @@ exports.beautifyPortGenericBlock = beautifyPortGenericBlock;
function AlignSigns(result, startIndex, endIndex) { 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, "<="); AlignSign_(result, startIndex, endIndex, "<=");
AlignSign_(result, startIndex, endIndex, "=>");
AlignSign_(result, startIndex, endIndex, "@@comments");
} }
exports.AlignSigns = AlignSigns; exports.AlignSigns = AlignSigns;
function AlignSign_(result, startIndex, endIndex, symbol) { function AlignSign_(result, startIndex, endIndex, symbol) {


+ 2
- 75
VHDLFormatter.ts View File

@ -53,7 +53,6 @@ function ConstructNewLineSettings(dict): NewLineSettings {
return settings; return settings;
} }
declare global { declare global {
interface String { interface String {
regexIndexOf: (pattern: RegExp, startIndex?: number) => number; regexIndexOf: (pattern: RegExp, startIndex?: number) => number;
@ -112,79 +111,6 @@ Array.prototype.convertToRegexBlockWords = function (): RegExp {
return result; return result;
} }
function wordWrap() {
var d = document.getElementById("result");
if (d.className == "") {
d.className = "wordwrap";
} else {
d.className = "";
}
}
function getHTMLInputElement(id: string): HTMLInputElement {
return <HTMLInputElement>document.getElementById(id);
}
function noFormat() {
let elements: Array<string> = [
"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 = <HTMLCollectionOf<HTMLInputElement>>document.getElementsByTagName("input");
for (let i = 0; i < radioButtons.length; i++) {
if ((<HTMLInputElement>radioButtons[i]).type == "radio") {
(<HTMLInputElement>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<string>): Array<string> { function EscapeComments(arr: Array<string>): Array<string> {
var comments = []; var comments = [];
var count = 0; var count = 0;
@ -514,8 +440,9 @@ export function beautifyPortGenericBlock(inputs: Array<string>, result: (Formatt
export function AlignSigns(result: (FormattedLine | FormattedLine[])[], startIndex: number, endIndex: number) { 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, "<="); AlignSign_(result, startIndex, endIndex, "<=");
AlignSign_(result, startIndex, endIndex, "=>");
AlignSign_(result, startIndex, endIndex, "@@comments");
} }
function AlignSign_(result: (FormattedLine | FormattedLine[])[], startIndex: number, endIndex: number, symbol: string) { function AlignSign_(result: (FormattedLine | FormattedLine[])[], startIndex: number, endIndex: number, symbol: string) {


+ 1
- 0
index.html View File

@ -420,6 +420,7 @@
</script> </script>
<script src="VHDLFormatter.js"></script> <script src="VHDLFormatter.js"></script>
<script src="descriptiveCounter.js"></script> <script src="descriptiveCounter.js"></script>
<script src="main.js"></script>
<script> <script>
const localStorageSettingKey = "settings"; const localStorageSettingKey = "settings";
const localStorageNoFormatKey = "noFormat"; const localStorageNoFormatKey = "noFormat";


+ 71
- 0
main.js View File

@ -0,0 +1,71 @@
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 getHTMLInputElement(id) {
return document.getElementById(id);
}
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 wordWrap() {
var d = document.getElementById("result");
if (d.className == "") {
d.className = "wordwrap";
}
else {
d.className = "";
}
}
//# sourceMappingURL=main.js.map

+ 72
- 0
main.ts View File

@ -0,0 +1,72 @@
function noFormat() {
let elements: Array<string> = [
"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 = <HTMLCollectionOf<HTMLInputElement>>document.getElementsByTagName("input");
for (let i = 0; i < radioButtons.length; i++) {
if ((<HTMLInputElement>radioButtons[i]).type == "radio") {
(<HTMLInputElement>radioButtons[i]).disabled = isDisabled;
}
}
}
function getHTMLInputElement(id: string): HTMLInputElement {
return <HTMLInputElement>document.getElementById(id);
}
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 wordWrap() {
var d = document.getElementById("result");
if (d.className == "") {
d.className = "wordwrap";
} else {
d.className = "";
}
}

+ 20
- 0
tests/VHDLFormatterUnitTests.ts View File

@ -913,6 +913,8 @@ function IntegrationTest() {
IntegrationTest72(); IntegrationTest72();
IntegrationTest73(); IntegrationTest73();
IntegrationTest74(); IntegrationTest74();
IntegrationTest75();
IntegrationTest76();
} }
function IntegrationTest23() { function IntegrationTest23() {
@ -1319,6 +1321,24 @@ function IntegrationTest74() {
assertAndCountTest("end of line 2", expected, actual); assertAndCountTest("end of line 2", expected, actual);
} }
function IntegrationTest75() {
let settings = GetDefaultSettings();
settings.SignAlignAll = true;
let input = 'test := loooong; -- test\r\ntest := short; -- test';
let expected = 'test := loooong; -- test\r\ntest := short; -- test';
let actual = beautify(input, settings);
assertAndCountTest("align comments", expected, actual);
}
function IntegrationTest76() {
let settings = GetDefaultSettings();
settings.SignAlignAll = true;
let input = "a <= (b => '000'); -- test\r\nlooong <= (others => '0'); -- test";
let expected = "a <= (b => '000'); -- test\r\nlooong <= (OTHERS => '0'); -- test";
let actual = beautify(input, settings);
assertAndCountTest("align <= => signs", expected, actual);
}
function GetDefaultSettings(indentation: string = " "): BeautifierSettings { function GetDefaultSettings(indentation: string = " "): BeautifierSettings {
let new_line_after_symbols = new NewLineSettings(); let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"]; new_line_after_symbols.newLineAfter = ["then", ";"];


+ 1
- 0
tsconfig.json View File

@ -6,6 +6,7 @@
"sourceMap": true "sourceMap": true
}, },
"files": [ "files": [
"main.ts",
"descriptiveCounter.ts", "descriptiveCounter.ts",
"VHDLFormatter.ts", "VHDLFormatter.ts",
"tests/VHDLFormatterUnitTests.ts", "tests/VHDLFormatterUnitTests.ts",


Loading…
Cancel
Save