Browse Source

better html; align sign locally

master
g2384 5 years ago
parent
commit
e9eb144aa7
7 changed files with 269 additions and 178 deletions
  1. +2
    -0
      README.md
  2. +31
    -18
      VHDLFormatter.js
  3. +36
    -21
      VHDLFormatter.ts
  4. +156
    -116
      index.html
  5. +4
    -1
      main.js
  6. +4
    -1
      main.ts
  7. +36
    -21
      tests/VHDLFormatterUnitTests.ts

+ 2
- 0
README.md View File

@ -11,6 +11,8 @@ VHDL formatter web online written in javascript
- use local storage to store settings
- add `main.js`
- treat key words and type names separately
- expand/hide setting options
- align signs locally or globally
### 2.3 [2018-02-22]


+ 31
- 18
VHDLFormatter.js View File

@ -155,13 +155,21 @@ function SetNewLinesAfterSymbols(text, newLineSettings) {
return text;
}
exports.SetNewLinesAfterSymbols = SetNewLinesAfterSymbols;
class signAlignSettings {
constructor(isRegional, isAll, mode, keyWords) {
this.isRegional = isRegional;
this.isAll = isAll;
this.mode = mode;
this.keyWords = keyWords;
}
}
exports.signAlignSettings = signAlignSettings;
class BeautifierSettings {
constructor(removeComments, removeReport, checkAlias, signAlign, signAlignAll, keywordCase, typeNameCase, indentation, newLineSettings, endOfLine) {
constructor(removeComments, removeReport, checkAlias, signAlignSettings, keywordCase, typeNameCase, indentation, newLineSettings, endOfLine) {
this.RemoveComments = removeComments;
this.RemoveAsserts = removeReport;
this.CheckAlias = checkAlias;
this.SignAlignRegional = signAlign;
this.SignAlignAll = signAlignAll;
this.SignAlignSettings = signAlignSettings;
this.KeywordCase = keywordCase;
this.TypeNameCase = typeNameCase;
this.Indentation = indentation;
@ -233,8 +241,9 @@ function beautify(input, settings) {
arr = input.split("\r\n");
let result = [];
beautify3(arr, result, settings, 0, 0);
if (settings.SignAlignAll) {
AlignSigns(result, 0, result.length - 1);
var alignSettings = settings.SignAlignSettings;
if (alignSettings != null && alignSettings.isAll) {
AlignSigns(result, 0, result.length - 1, alignSettings.mode);
}
arr = FormattedLineToString(result, settings.Indentation);
input = arr.join("\r\n");
@ -368,24 +377,27 @@ function beautifyPortGenericBlock(inputs, result, settings, startIndex, parentEn
result[i].Indent--;
blockBodyEndIndex--;
}
if (settings.SignAlignRegional && !settings.SignAlignAll
&& settings.SignAlignKeyWords != null
&& settings.SignAlignKeyWords.indexOf(mode) >= 0) {
blockBodyStartIndex++;
AlignSigns(result, blockBodyStartIndex, blockBodyEndIndex);
var alignSettings = settings.SignAlignSettings;
if (alignSettings != null) {
if (alignSettings.isRegional && !alignSettings.isAll
&& alignSettings.keyWords != null
&& alignSettings.keyWords.indexOf(mode) >= 0) {
blockBodyStartIndex++;
AlignSigns(result, blockBodyStartIndex, blockBodyEndIndex, alignSettings.mode);
}
}
return [i, parentEndIndex];
}
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, "@@comments");
function AlignSigns(result, startIndex, endIndex, mode) {
AlignSign_(result, startIndex, endIndex, ":", mode);
AlignSign_(result, startIndex, endIndex, ":=", mode);
AlignSign_(result, startIndex, endIndex, "<=", mode);
AlignSign_(result, startIndex, endIndex, "=>", mode);
AlignSign_(result, startIndex, endIndex, "@@comments", mode);
}
exports.AlignSigns = AlignSigns;
function AlignSign_(result, startIndex, endIndex, symbol) {
function AlignSign_(result, startIndex, endIndex, symbol, mode) {
let maxSymbolIndex = -1;
let symbolIndices = {};
let startLine = startIndex;
@ -411,7 +423,8 @@ function AlignSign_(result, startIndex, endIndex, symbol) {
maxSymbolIndex = Math.max(maxSymbolIndex, colonIndex);
symbolIndices[i] = colonIndex;
}
else if (!line.startsWith(ILCommentPrefix) && line.length != 0) {
else if ((mode != "local" && !line.startsWith(ILCommentPrefix) && line.length != 0)
|| (mode == "local")) {
if (startLine < i - 1) // if cannot find the symbol, a block of symbols ends
{
AlignSign(result, startLine, i - 1, symbol, maxSymbolIndex, symbolIndices);


+ 36
- 21
VHDLFormatter.ts View File

@ -191,26 +191,36 @@ export function SetNewLinesAfterSymbols(text: string, newLineSettings: NewLineSe
return text;
}
export class signAlignSettings {
isRegional: boolean;
isAll: boolean;
mode: string;
keyWords: Array<string>;
constructor(isRegional: boolean, isAll: boolean, mode: string, keyWords: Array<string>) {
this.isRegional = isRegional;
this.isAll = isAll;
this.mode = mode;
this.keyWords = keyWords;
}
}
export class BeautifierSettings {
RemoveComments: boolean;
RemoveAsserts: boolean;
CheckAlias: boolean;
SignAlignRegional: boolean;
SignAlignAll: boolean;
SignAlignKeyWords: Array<string>;
SignAlignSettings: signAlignSettings;
KeywordCase: string;
TypeNameCase: string;
Indentation: string;
NewLineSettings: NewLineSettings;
EndOfLine: string;
constructor(removeComments: boolean, removeReport: boolean, checkAlias: boolean,
signAlign: boolean, signAlignAll: boolean, keywordCase: string, typeNameCase: string, indentation: string,
signAlignSettings: signAlignSettings, keywordCase: string, typeNameCase: string, indentation: string,
newLineSettings: NewLineSettings, endOfLine: string) {
this.RemoveComments = removeComments;
this.RemoveAsserts = removeReport;
this.CheckAlias = checkAlias;
this.SignAlignRegional = signAlign;
this.SignAlignAll = signAlignAll;
this.SignAlignSettings = signAlignSettings;
this.KeywordCase = keywordCase;
this.TypeNameCase = typeNameCase;
this.Indentation = indentation;
@ -287,8 +297,9 @@ export function beautify(input: string, settings: BeautifierSettings) {
arr = input.split("\r\n");
let result: (FormattedLine | FormattedLine[])[] = [];
beautify3(arr, result, settings, 0, 0);
if (settings.SignAlignAll) {
AlignSigns(result, 0, result.length - 1);
var alignSettings = settings.SignAlignSettings;
if (alignSettings != null && alignSettings.isAll) {
AlignSigns(result, 0, result.length - 1, alignSettings.mode);
}
arr = FormattedLineToString(result, settings.Indentation);
@ -430,24 +441,27 @@ export function beautifyPortGenericBlock(inputs: Array<string>, result: (Formatt
(<FormattedLine>result[i]).Indent--;
blockBodyEndIndex--;
}
if (settings.SignAlignRegional && !settings.SignAlignAll
&& settings.SignAlignKeyWords != null
&& settings.SignAlignKeyWords.indexOf(mode) >= 0) {
blockBodyStartIndex++;
AlignSigns(result, blockBodyStartIndex, blockBodyEndIndex);
var alignSettings = settings.SignAlignSettings;
if (alignSettings != null) {
if (alignSettings.isRegional && !alignSettings.isAll
&& alignSettings.keyWords != null
&& alignSettings.keyWords.indexOf(mode) >= 0) {
blockBodyStartIndex++;
AlignSigns(result, blockBodyStartIndex, blockBodyEndIndex, alignSettings.mode);
}
}
return [i, parentEndIndex];
}
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, "@@comments");
export function AlignSigns(result: (FormattedLine | FormattedLine[])[], startIndex: number, endIndex: number, mode: string) {
AlignSign_(result, startIndex, endIndex, ":", mode);
AlignSign_(result, startIndex, endIndex, ":=", mode);
AlignSign_(result, startIndex, endIndex, "<=", mode);
AlignSign_(result, startIndex, endIndex, "=>", mode);
AlignSign_(result, startIndex, endIndex, "@@comments", mode);
}
function AlignSign_(result: (FormattedLine | FormattedLine[])[], startIndex: number, endIndex: number, symbol: string) {
function AlignSign_(result: (FormattedLine | FormattedLine[])[], startIndex: number, endIndex: number, symbol: string, mode: string) {
let maxSymbolIndex: number = -1;
let symbolIndices = {};
let startLine = startIndex;
@ -474,7 +488,8 @@ function AlignSign_(result: (FormattedLine | FormattedLine[])[], startIndex: num
maxSymbolIndex = Math.max(maxSymbolIndex, colonIndex);
symbolIndices[i] = colonIndex;
}
else if (!line.startsWith(ILCommentPrefix) && line.length != 0) {
else if ((mode != "local" && !line.startsWith(ILCommentPrefix) && line.length != 0)
|| (mode == "local")) {
if (startLine < i - 1) // if cannot find the symbol, a block of symbols ends
{
AlignSign(result, startLine, i - 1, symbol, maxSymbolIndex, symbolIndices);


+ 156
- 116
index.html View File

@ -93,6 +93,7 @@
padding: 2px 5px;
border-radius: 3px;
font-size: 0.8em;
cursor: pointer;
}
a:hover {
@ -208,6 +209,15 @@
margin-left: 10px;
display: inline-block;
}
.hide {
display: none;
}
#settings_control {
margin: 10px 0px;
display: inline-block;
}
</style>
<link href="highlight.css" rel="stylesheet" />
<script src="highlight.js"></script>
@ -247,7 +257,7 @@
<input type="checkbox" id="no_format" onclick="noFormat()">
<label for="no_format">Only highlight, don't format</label>
</div>
<form id="keyword">Keyword case:
<form id="keyword_div">Keyword case:
<label>
<input type="radio" name="keywordcase" value="UpperCase" checked="checked">UPPERCASE</label> |
<label>
@ -258,7 +268,7 @@
e.g. begin, case, when
</div>
</form>
<form id="typename">Type name case:
<form id="typename_div">Type name case:
<label>
<input type="radio" name="typenamecase" value="UpperCase" checked="checked">UPPERCASE</label> |
<label>
@ -269,113 +279,125 @@
e.g. boolean, natural, string
</div>
</form>
<fieldset id="new_line_after_div">
<legend>New line after</legend>
<form id="new_line_after_then">
<span class="code">THEN</span>
<label>
<input type="radio" name="new_line_after_thencase" value="NewLine" checked="checked">New Line</label>
<label>
<input type="radio" name="new_line_after_thencase" value="NoNewLine">No New Line</label>
<label>
<input type="radio" name="new_line_after_thencase" value="None">None</label>
</form>
<form id="new_line_after_semicolon">
<span class="code">semicolon ";"</span>
<label>
<input type="radio" name="new_line_after_semicoloncase" value="NewLine" checked="checked">New Line</label>
<label>
<input type="radio" name="new_line_after_semicoloncase" value="NoNewLine">No New Line</label>
<label>
<input type="radio" name="new_line_after_semicoloncase" value="None">None</label>
</form>
<form id="new_line_after_else">
<span class="code">ELSE</span>
<label>
<input type="radio" name="new_line_after_elsecase" value="NewLine">New Line</label>
<label>
<input type="radio" name="new_line_after_elsecase" value="NoNewLine">No New Line</label>
<label>
<input type="radio" name="new_line_after_elsecase" value="None" checked="checked">None</label>
</form>
<form id="new_line_after_port">
<span class="code">PORT | PORT MAP</span>
<label>
<input type="radio" name="new_line_after_portcase" value="NewLine">New Line</label>
<label>
<input type="radio" name="new_line_after_portcase" value="NoNewLine">No New Line</label>
<label>
<input type="radio" name="new_line_after_portcase" value="None" checked="checked">None</label>
</form>
<form id="new_line_after_generic">
<span class="code">GENERIC</span>
<label>
<input type="radio" name="new_line_after_genericcase" value="NewLine">New Line</label>
<div class="hide" id="settings_div">
<fieldset id="new_line_after_div">
<legend>New line after</legend>
<form id="new_line_after_then">
<span class="code">THEN</span>
<label>
<input type="radio" name="new_line_after_thencase" value="NewLine" checked="checked">New Line</label>
<label>
<input type="radio" name="new_line_after_thencase" value="NoNewLine">No New Line</label>
<label>
<input type="radio" name="new_line_after_thencase" value="None">None</label>
</form>
<form id="new_line_after_semicolon">
<span class="code">semicolon ";"</span>
<label>
<input type="radio" name="new_line_after_semicoloncase" value="NewLine" checked="checked">New Line</label>
<label>
<input type="radio" name="new_line_after_semicoloncase" value="NoNewLine">No New Line</label>
<label>
<input type="radio" name="new_line_after_semicoloncase" value="None">None</label>
</form>
<form id="new_line_after_else">
<span class="code">ELSE</span>
<label>
<input type="radio" name="new_line_after_elsecase" value="NewLine">New Line</label>
<label>
<input type="radio" name="new_line_after_elsecase" value="NoNewLine">No New Line</label>
<label>
<input type="radio" name="new_line_after_elsecase" value="None" checked="checked">None</label>
</form>
<form id="new_line_after_port">
<span class="code">PORT | PORT MAP</span>
<label>
<input type="radio" name="new_line_after_portcase" value="NewLine">New Line</label>
<label>
<input type="radio" name="new_line_after_portcase" value="NoNewLine">No New Line</label>
<label>
<input type="radio" name="new_line_after_portcase" value="None" checked="checked">None</label>
</form>
<form id="new_line_after_generic">
<span class="code">GENERIC</span>
<label>
<input type="radio" name="new_line_after_genericcase" value="NewLine">New Line</label>
<label>
<input type="radio" name="new_line_after_genericcase" value="NoNewLine">No New Line</label>
<label>
<input type="radio" name="new_line_after_genericcase" value="None" checked="checked">None</label>
</form>
</fieldset>
<div class="checkbox inline" id="remove_comments_div">
<input type="checkbox" id="remove_comments">
<label for="remove_comments">Remove commments</label> |
</div>
<div class="checkbox inline" id="remove_lines_div">
<input type="checkbox" id="remove_lines">
<label for="remove_lines">Remove blank lines</label> |
</div>
<div class="checkbox inline" id="remove_report_div">
<input type="checkbox" id="remove_report">
<label for="remove_report">Remove REPORT</label>
</div>
<br>
<div class="checkbox" id="check_alias_div">
<input type="checkbox" id="check_alias">
<label for="check_alias">Check ALIAS (all long names will be replaced by ALIAS names)</label>
</div>
<div id="sign_align_in_div">
Align signs in
<div class="checkbox inline" id="sign_align_port_div">
<input type="checkbox" id="sign_align_port">
<label for="sign_align_port" class="code">PORT()</label>
</div>
<div class="checkbox inline" id="sign_align_generic_div">
<input type="checkbox" id="sign_align_generic">
<label for="sign_align_generic" class="code">GENERIC()</label></div>
<div class="checkbox inline" id="sign_align_procedure_div">
<input type="checkbox" id="sign_align_procedure">
<label for="sign_align_procedure" class="code">PROCEDURE()</label>
</div>
<div class="checkbox inline" id="sign_align_function_div">
<input type="checkbox" id="sign_align_function">
<label for="sign_align_function" class="code">FUNCTION()</label>
</div>
</div>
<div class="checkbox inline" id="sign_align_all_div">
<input type="checkbox" id="sign_align_all">
<label for="sign_align_all">Align signs in all places</label>
</div>
<form class="inline" id="sign_align_mode_div">
<span>Mode: </span>
<label>
<input type="radio" name="new_line_after_genericcase" value="NoNewLine">No New Line</label>
<input type="radio" name="sign_align_modecase" value="local">Local</label>
<label>
<input type="radio" name="new_line_after_genericcase" value="None" checked="checked">None</label>
<input type="radio" name="sign_align_modecase" value="global">Global</label>
</form>
</fieldset>
<div class="checkbox inline" id="remove_comments_div">
<input type="checkbox" id="remove_comments">
<label for="remove_comments">Remove commments</label> |
</div>
<div class="checkbox inline" id="remove_lines_div">
<input type="checkbox" id="remove_lines">
<label for="remove_lines">Remove blank lines</label> |
</div>
<div class="checkbox inline" id="remove_report_div">
<input type="checkbox" id="remove_report">
<label for="remove_report">Remove REPORT</label>
</div>
<br>
<div class="checkbox" id="check_alias_div">
<input type="checkbox" id="check_alias">
<label for="check_alias">Check ALIAS (all long names will be replaced by ALIAS names)</label>
</div>
<div id="sign_align_in_div">
Align signs in
<div class="checkbox inline" id="sign_align_port_div">
<input type="checkbox" id="sign_align_port">
<label for="sign_align_port" class="code">PORT()</label>
<div id="customise_indentation_div">
<div class="checkbox inline" id="use_space_div">
<input type="checkbox" id="use_space">
<label for="use_space">Customise Indentation: </label>
</div>(tab is \t)
<input type="text" id="customise_indentation" size="8" onKeyUp="counterDecode('customise_indentation', 'indent_s')" value=" " /> (
<span id="indent_s">four blankspaces</span>)
</div>
<div class="checkbox inline" id="sign_align_generic_div">
<input type="checkbox" id="sign_align_generic">
<label for="sign_align_generic" class="code">GENERIC()</label></div>
<div class="checkbox inline" id="sign_align_procedure_div">
<input type="checkbox" id="sign_align_procedure">
<label for="sign_align_procedure" class="code">PROCEDURE()</label>
<div id="cust_eol_div">
End of line:
<input type="text" id="cust_eol" size="8" onKeyUp="counterDecode('cust_eol', 'eol_s')" value="\r\n" /> (
<span id="eol_s">one \r & one \n</span>)
</div>
<div class="checkbox inline" id="sign_align_function_div">
<input type="checkbox" id="sign_align_function">
<label for="sign_align_function" class="code">FUNCTION()</label>
<div class="checkbox" id="compress_div">
<input type="checkbox" id="compress">
<label for="compress">! EVIL - compress VHDL (\r\n, comments will be removed)</label>
</div>
<div class="checkbox" id="mix_letter_div">
<input type="checkbox" id="mix_letter">
<label for="mix_letter">! EVIL - unreadable (mix upper/lower-case letters)</label>
</div>
</div>
<div class="checkbox" id="sign_align_all_div">
<input type="checkbox" id="sign_align_all">
<label for="sign_align_all">Align signs in all places</label>
</div>
<div id="customise_indentation_div">
<div class="checkbox inline" id="use_space_div">
<input type="checkbox" id="use_space">
<label for="use_space">Customise Indentation: </label>
</div>(tab is \t)
<input type="text" id="customise_indentation" size="8" onKeyUp="counterDecode('customise_indentation', 'indent_s')" value=" " /> (
<span id="indent_s">four blankspaces</span>)
</div>
<div id="cust_eol_div">
End of line:
<input type="text" id="cust_eol" size="8" onKeyUp="counterDecode('cust_eol', 'eol_s')" value="\r\n" /> (
<span id="eol_s">one \r & one \n</span>)
</div>
<div class="checkbox" id="compress_div">
<input type="checkbox" id="compress">
<label for="compress">! EVIL - compress VHDL (\r\n, comments will be removed)</label>
</div>
<div class="checkbox" id="mix_letter_div">
<input type="checkbox" id="mix_letter">
<label for="mix_letter">! EVIL - unreadable (mix upper/lower-case letters)</label>
<div>
<a id="settings_control" onclick="showHideSettings();">Show More Settings ▼</a>
</div>
<input type="button" class="btn" onclick="f()" value="start" />
<span class="show">
@ -446,6 +468,19 @@
const localStorageSettingKey = "settings";
const localStorageNoFormatKey = "noFormat";
function showHideSettings() {
var settingsDiv = document.getElementById("settings_div");
var control = document.getElementById("settings_control");
if (settingsDiv.className.indexOf("hide") >= 0) {
settingsDiv.className = settingsDiv.className.replace(/\s*hide/, "");
control.innerHTML = "Show Less ▲";
}
else {
settingsDiv.className += "hide";
control.innerHTML = "Show More Settings ▼";
}
}
function onLoad() {
let global_endOfLine = navigator.platform === 'Win32' ? '\\r\\n' : '\\n';
document.getElementById("cust_eol").value = global_endOfLine;
@ -459,14 +494,18 @@
document.getElementById("remove_lines").checked = setting.removeLines;
document.getElementById("remove_report").checked = beautifierSettings.RemoveAsserts;
document.getElementById("check_alias").checked = beautifierSettings.CheckAlias;
var signAlignKeywords = beautifierSettings.SignAlignKeyWords;
if (signAlignKeywords != null && signAlignKeywords.length > 0) {
document.getElementById("sign_align_port").checked = signAlignKeywords.indexOf("PORT") >= 0;
document.getElementById("sign_align_function").checked = signAlignKeywords.indexOf("FUNCTION") >= 0;
document.getElementById("sign_align_procedure").checked = signAlignKeywords.indexOf("PROCEDURE") >= 0;
document.getElementById("sign_align_generic").checked = signAlignKeywords.indexOf("GENERIC") >= 0;
var alignSettings = beautifierSettings.SignAlignSettings;
if (alignSettings != null) {
var signAlignKeywords = alignSettings.keyWords;
if (signAlignKeywords != null && signAlignKeywords.length > 0) {
document.getElementById("sign_align_port").checked = signAlignKeywords.indexOf("PORT") >= 0;
document.getElementById("sign_align_function").checked = signAlignKeywords.indexOf("FUNCTION") >= 0;
document.getElementById("sign_align_procedure").checked = signAlignKeywords.indexOf("PROCEDURE") >= 0;
document.getElementById("sign_align_generic").checked = signAlignKeywords.indexOf("GENERIC") >= 0;
}
document.getElementById("sign_align_all").checked = alignSettings.isAll;
document.getElementById("sign_align_mode_div").elements.namedItem("sign_align_modecase").value = alignSettings.mode;
}
document.getElementById("sign_align_all").checked = beautifierSettings.SignAlignAll;
var newLineSettings = beautifierSettings.NewLineSettings;
var newLineAfter = newLineSettings.newLineAfter;
var noNewLineAfter = newLineSettings.noNewLineAfter;
@ -479,8 +518,8 @@
var indentation = beautifierSettings.Indentation;
document.getElementById("use_space").checked = indentation != "\t";
document.getElementById("customise_indentation").value = indentation;
document.getElementById("keyword").elements.namedItem("keywordcase").value = beautifierSettings.KeywordCase;
document.getElementById("typename").elements.namedItem("typenamecase").value = beautifierSettings.TypeNameCase;
document.getElementById("keyword_div").elements.namedItem("keywordcase").value = beautifierSettings.KeywordCase;
document.getElementById("typename_div").elements.namedItem("typenamecase").value = beautifierSettings.TypeNameCase;
document.getElementById("mix_letter").checked = setting.mixLetter;
var eof = beautifierSettings.EndOfLine
eof = eof.replace(/\r/g, "\\r");
@ -527,6 +566,7 @@
var sign_align_procedure = document.getElementById("sign_align_procedure").checked;
var sign_align_generic = document.getElementById("sign_align_generic").checked;
var sign_align_all = document.getElementById("sign_align_all").checked;
var sign_align_mode = document.getElementById("sign_align_mode_div").elements.namedItem("sign_align_modecase").value;
var new_line_after_port = document.getElementById("new_line_after_port").elements.namedItem("new_line_after_portcase").value;
var new_line_after_then = document.getElementById("new_line_after_then").elements.namedItem("new_line_after_thencase").value;
var new_line_after_semicolon = document.getElementById("new_line_after_semicolon").elements.namedItem("new_line_after_semicoloncase").value;
@ -535,8 +575,8 @@
var use_space = document.getElementById("use_space").checked;
var compress = document.getElementById("compress").checked;
var cust_indent = document.getElementById("customise_indentation").value;
var keywordcase = document.getElementById("keyword").elements.namedItem("keywordcase").value;
var typenamecase = document.getElementById("typename").elements.namedItem("typenamecase").value;
var keywordcase = document.getElementById("keyword_div").elements.namedItem("keywordcase").value;
var typenamecase = document.getElementById("typename_div").elements.namedItem("typenamecase").value;
var mix_letter = document.getElementById("mix_letter").checked;
var endOfLine = document.getElementById("cust_eol").value;
endOfLine = endOfLine.replace(/\\r/g, "\r");
@ -575,15 +615,15 @@
signAlignKeywords.push("PROCEDURE");
}
sign_align = signAlignKeywords.length > 0;
let alignSettings = new signAlignSettings(sign_align, sign_align_all, sign_align_mode, signAlignKeywords)
beautifierSettings = new BeautifierSettings(remove_comments, remove_report, check_alias, sign_align,
sign_align_all,
beautifierSettings = new BeautifierSettings(remove_comments, remove_report, check_alias,
alignSettings,
keywordcase,
typenamecase,
indentation,
newLineSettings,
endOfLine);
beautifierSettings.SignAlignKeyWords = signAlignKeywords;
vhdlSettings = new VhdlSettings(beautifierSettings, remove_lines, compress, mix_letter);
saveSetting(vhdlSettings);


+ 4
- 1
main.js View File

@ -15,7 +15,10 @@ function noFormat() {
"customise_indentation",
"compress",
"mix_letter",
"cust_eol"
"cust_eol",
"sign_align_mode",
"keyword",
"typename"
];
var isDisabled = getHTMLInputElement("no_format").checked;
elements.forEach(element => {


+ 4
- 1
main.ts View File

@ -15,7 +15,10 @@ function noFormat() {
"customise_indentation",
"compress",
"mix_letter",
"cust_eol"
"cust_eol",
"sign_align_mode",
"keyword",
"typename"
];
var isDisabled = getHTMLInputElement("no_format").checked;
elements.forEach(element => {


+ 36
- 21
tests/VHDLFormatterUnitTests.ts View File

@ -1,4 +1,4 @@
import { beautify } from "../VHDLFormatter";
import { beautify, signAlignSettings } from "../VHDLFormatter";
import { NewLineSettings } from "../VHDLFormatter";
import { BeautifierSettings } from "../VHDLFormatter";
import { RemoveAsserts } from "../VHDLFormatter";
@ -853,7 +853,7 @@ function IntegrationTest() {
assertAndCountTest("Double BEGIN", expected, actual);
let newSettings2 = deepCopy(newSettings);
newSettings2.SignAlignAll = true;
newSettings2.SignAlignSettings = new signAlignSettings(false, true, "", []);
newSettings2.NewLineSettings.newLineAfter = ["then", ";", "generic", "port"];
newSettings2.NewLineSettings.noNewLineAfter = [];
input = "entity a is\r\n port ( w : in std_logic_vector (7 downto 0) ;\r\n w_s : out std_logic_vector (3 downto 0) ; ) ;\r\nend a ;\r\narchitecture b of a is\r\nbegin\r\n process ( w )\r\n variable t : std_logic_vector (4 downto 0) ;\r\n variable bcd : std_logic_vector (11 downto 0) ;\r\nbegin\r\n b(2 downto 0) := w(7 downto 5) ;\r\n t := w(4 downto 0) ;\r\n w_s <= b(11 downto 8) ;\r\n w <= b(3 downto 0) ;\r\nend process ;\r\nend b ;";
@ -919,6 +919,7 @@ function IntegrationTest() {
IntegrationTest78();
IntegrationTest79();
IntegrationTest80();
IntegrationTest82();
}
function IntegrationTest23() {
@ -1118,8 +1119,7 @@ function IntegrationTest48() {
function IntegrationTest49() {
let settings = GetDefaultSettings();
settings.SignAlignRegional = true;
settings.SignAlignKeyWords = ["PROCEDURE"];
settings.SignAlignSettings = new signAlignSettings(true, false, "", ["PROCEDURE"]);
let input = 'PROCEDURE wait_until(\r\n SIGNAL a : IN data_status;\r\n b : data_status\r\n);';
let actual = beautify(input, settings);
assertAndCountTest("align sign in procedure", input, actual);
@ -1127,7 +1127,7 @@ function IntegrationTest49() {
function IntegrationTest50() {
let settings = GetDefaultSettings();
settings.SignAlignRegional = true;
settings.SignAlignSettings = new signAlignSettings(true, false, "", []);
let input = 'PROCEDURE wait_until(\r\n SIGNAL a : IN data_status;\r\n b : data_status\r\n);';
let actual = beautify(input, settings);
assertAndCountTest("does not align sign in procedure", input, actual);
@ -1135,7 +1135,7 @@ function IntegrationTest50() {
function IntegrationTest51() {
let settings = GetDefaultSettings();
settings.SignAlignAll = true;
settings.SignAlignSettings = new signAlignSettings(false, true, "", []);
let input = 'architecture behaviour of a is\r\nbegin\r\n main : process\r\n variable b : e := (others => DR_INIT);\r\n variable c, d : positive := 8;\r\n begin\r\n end process main;\r\nend architecture behaviour;';
let expected = 'ARCHITECTURE behaviour OF a IS\r\nBEGIN\r\n main : PROCESS\r\n VARIABLE b : e := (OTHERS => DR_INIT);\r\n VARIABLE c, d : POSITIVE := 8;\r\n BEGIN\r\n END PROCESS main;\r\nEND ARCHITECTURE behaviour;';
let actual = beautify(input, settings);
@ -1169,7 +1169,7 @@ function IntegrationTest54() {
function IntegrationTest55() {
let settings = GetDefaultSettings();
settings.SignAlignAll = true;
settings.SignAlignSettings = new signAlignSettings(false, true, "", []);
let input = 'main :\r\nPROCESS\r\n VARIABLE b : a := (OTHERS => DR_INIT);\r\nBEGIN';
let actual = beautify(input, settings);
assertAndCountTest("package with label and align all symbols", input, actual);
@ -1177,7 +1177,7 @@ function IntegrationTest55() {
function IntegrationTest56() {
let settings = GetDefaultSettings();
settings.SignAlignAll = true;
settings.SignAlignSettings = new signAlignSettings(false, true, "", []);
let input = 'a <= (2 => DR_ONE, 5 => DR_ZERO);\r\nbc <= (32 => DR_ONE);';
let actual = beautify(input, settings);
assertAndCountTest("package with label and align all symbols", input, actual);
@ -1335,7 +1335,7 @@ function IntegrationTest74() {
function IntegrationTest75() {
let settings = GetDefaultSettings();
settings.SignAlignAll = true;
settings.SignAlignSettings = new signAlignSettings(false, true, "", []);
let input = 'test := loooong; -- test\r\ntest := short; -- test';
let expected = 'test := loooong; -- test\r\ntest := short; -- test';
let actual = beautify(input, settings);
@ -1344,7 +1344,7 @@ function IntegrationTest75() {
function IntegrationTest76() {
let settings = GetDefaultSettings();
settings.SignAlignAll = true;
settings.SignAlignSettings = new signAlignSettings(false, 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);
@ -1367,8 +1367,7 @@ function IntegrationTest78() {
}
function IntegrationTest79() {
let settings = new BeautifierSettings(false, false, false, false, false, "lowercase", "uppercase", null, null, "\r\n");
settings.SignAlignAll = true;
let settings = new BeautifierSettings(false, false, false, null, "lowercase", "uppercase", null, null, "\r\n");
let input = "case when others;\r\nx : STRING;\r\ny : BIT;";
let actual = beautify(input, settings);
assertAndCountTest("uppercase typename and lowercase keyword", input, actual);
@ -1381,18 +1380,37 @@ function IntegrationTest80() {
assertAndCountTest("function name in quotes", input, actual);
}
function IntegrationTest81() { // TODO
let settings = GetDefaultSettings();
let input = 'test : IN type := 0\r\ntest : OUT type := 0\r\ntest : INOUT type := 0\r\ntest : BUFFER type := 0\r\ntest : LINKAGE type := 0';
let expected = 'test : IN type := 0\r\ntest : OUT type := 0\r\ntest : INOUT type := 0\r\ntest : BUFFER type := 0\r\ntest : LINKAGE type := 0';
let actual = beautify(input, settings);
assertAndCountTest("signal in out alignment", expected, actual);
}
function IntegrationTest82() {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "local", []);
let input = 'long : test;\r\n-- comment\r\nloooooong : test;';
let actual = beautify(input, settings);
assertAndCountTest("block alignment local", input, actual);
}
function GetDefaultSettings(indentation: string = " "): BeautifierSettings {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = getDefaultBeautifierSettings(new_line_after_symbols, indentation);
let signAligns = new signAlignSettings(false, false, "", []);
let settings = getDefaultBeautifierSettings(new_line_after_symbols, signAligns, indentation);
return settings;
}
function getDefaultBeautifierSettings(newLineSettings: NewLineSettings, indentation: string = " "): BeautifierSettings {
return new BeautifierSettings(false, false, false, false, false, "uppercase", "uppercase", indentation, newLineSettings, "\r\n");
function getDefaultBeautifierSettings(newLineSettings: NewLineSettings, signAlignSettings: signAlignSettings = null, indentation: string = " "): BeautifierSettings {
return new BeautifierSettings(false, false, false, signAlignSettings, "uppercase", "uppercase", indentation, newLineSettings, "\r\n");
}
function IntegrationTest20() {
let settings = GetDefaultSettings();
let input = "process xyx (vf,fr,\r\nde -- comment\r\n)";
@ -1403,8 +1421,7 @@ function IntegrationTest20() {
function IntegrationTest5() {
let settings = GetDefaultSettings();
settings.SignAlignRegional = true;
settings.SignAlignKeyWords = ["PORT"];
settings.SignAlignSettings = new signAlignSettings(true, false, "", ["PORT"]);
let input = "port map(\r\ninput_1 => input_1_sig,\r\ninput_2 => input_2_sig,\r\noutput => output_sig\r\n);";
let expected = "PORT MAP(\r\n input_1 => input_1_sig,\r\n input_2 => input_2_sig,\r\n output => output_sig\r\n);";
let actual = beautify(input, settings);
@ -1416,8 +1433,7 @@ function IntegrationTest6() {
new_line_after_symbols.newLineAfter = ["then", ";", "port map"];
new_line_after_symbols.noNewLineAfter = ["generic"];
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
settings.SignAlignRegional = true;
settings.SignAlignKeyWords = ["PORT"];
settings.SignAlignSettings = new signAlignSettings(true, false, "", ["PORT"]);
let input = "port map(\r\ninput_1 => input_1_sig,\r\ninput_2 => input_2_sig,\r\noutput => output_sig\r\n);";
let expected = "PORT MAP\r\n(\r\n input_1 => input_1_sig,\r\n input_2 => input_2_sig,\r\n output => output_sig\r\n);";
let actual = beautify(input, settings);
@ -1428,8 +1444,7 @@ function IntegrationTest7() {
let new_line_after_symbols: NewLineSettings = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];
let settings = getDefaultBeautifierSettings(new_line_after_symbols);
settings.SignAlignRegional = true;
settings.SignAlignKeyWords = ["PORT", "GENERIC"];
settings.SignAlignSettings = new signAlignSettings(true, false, "global", ["PORT", "GENERIC"]);
let input = "entity p is\r\n generic\r\n (\r\n -- INCLK\r\n INCLK0_INPUT_FREQUENCY : natural;\r\n\r\n -- CLK1\r\n CLK1_DIVIDE_BY : natural := 1;\r\n CLK1_MULTIPLY_BY : unnatural:= 1;\r\n CLK1_PHASE_SHIFT : string := \"0\"\r\n );\r\n port\r\n (\r\n inclk0 : in std_logic := '0';\r\n c0 : out std_logic ;\r\n c1 : out std_logic \r\n );\r\nEND pll;";
let expected = "ENTITY p IS\r\n GENERIC (\r\n -- INCLK\r\n INCLK0_INPUT_FREQUENCY : NATURAL;\r\n\r\n -- CLK1\r\n CLK1_DIVIDE_BY : NATURAL := 1;\r\n CLK1_MULTIPLY_BY : unnatural := 1;\r\n CLK1_PHASE_SHIFT : STRING := \"0\"\r\n );\r\n PORT (\r\n inclk0 : IN std_logic := '0';\r\n c0 : OUT std_logic;\r\n c1 : OUT std_logic\r\n );\r\nEND pll;";
let actual = beautify(input, settings);


Loading…
Cancel
Save