Browse Source

align concurrent signal assignment

master
g2384 4 years ago
parent
commit
b0c4c68b2c
3 changed files with 42 additions and 2 deletions
  1. +17
    -1
      VHDLFormatter.js
  2. +18
    -1
      VHDLFormatter.ts
  3. +7
    -0
      tests/VHDLFormatter.test.ts

+ 17
- 1
VHDLFormatter.js View File

@ -656,11 +656,27 @@ function beautifySemicolonBlock(inputs, result, settings, startIndex, parentEndI
[endIndex, parentEndIndex] = getSemicolonBlockEndIndex(inputs, settings, startIndex, parentEndIndex);
result.push(new FormattedLine(inputs[startIndex], indent));
if (endIndex != startIndex) {
let i = beautify3(inputs, result, settings, startIndex + 1, indent + 1, endIndex);
beautify3(inputs, result, settings, startIndex + 1, indent + 1, endIndex);
alignSignalAssignmentBlock(settings, inputs, startIndex, endIndex, result);
}
return [endIndex, parentEndIndex];
}
exports.beautifySemicolonBlock = beautifySemicolonBlock;
function alignSignalAssignmentBlock(settings, inputs, startIndex, endIndex, result) {
if (settings.Indentation.replace(/ +/g, "").length == 0) {
let reg = new RegExp("^([\\w\\\\]+[\\s]*<=\\s*)");
let match = reg.exec(inputs[startIndex]);
if (match != null) {
let length = match[0].length;
let prefixLength = length - settings.Indentation.length;
let prefix = new Array(prefixLength + 1).join(" ");
for (let i = startIndex + 1; i <= endIndex; i++) {
let fl = result[i];
fl.Line = prefix + fl.Line;
}
}
}
}
function beautify3(inputs, result, settings, startIndex, indent, endIndex) {
let i;
let regexOneLineBlockKeyWords = new RegExp(/(PROCEDURE)[^\w](?!.+[^\w]IS([^\w]|$))/); //match PROCEDURE..; but not PROCEDURE .. IS;


+ 18
- 1
VHDLFormatter.ts View File

@ -725,12 +725,29 @@ export function beautifySemicolonBlock(inputs: Array<string>, result: (Formatted
[endIndex, parentEndIndex] = getSemicolonBlockEndIndex(inputs, settings, startIndex, parentEndIndex);
result.push(new FormattedLine(inputs[startIndex], indent));
if (endIndex != startIndex) {
let i = beautify3(inputs, result, settings, startIndex + 1, indent + 1, endIndex);
beautify3(inputs, result, settings, startIndex + 1, indent + 1, endIndex);
alignSignalAssignmentBlock(settings, inputs, startIndex, endIndex, result);
}
return [endIndex, parentEndIndex];
}
function alignSignalAssignmentBlock(settings: BeautifierSettings, inputs: string[], startIndex: number, endIndex: number, result: (FormattedLine | FormattedLine[])[]) {
if (settings.Indentation.replace(/ +/g, "").length == 0) {
let reg: RegExp = new RegExp("^([\\w\\\\]+[\\s]*<=\\s*)");
let match = reg.exec(inputs[startIndex]);
if (match != null) {
let length = match[0].length;
let prefixLength = length - settings.Indentation.length;
let prefix = new Array(prefixLength + 1).join(" ");
for (let i = startIndex + 1; i <= endIndex; i++) {
let fl = (result[i] as FormattedLine);
fl.Line = prefix + fl.Line;
}
}
}
}
export function beautify3(inputs: Array<string>, result: (FormattedLine | FormattedLine[])[], settings: BeautifierSettings, startIndex: number, indent: number, endIndex?: number): number {
let i: number;
let regexOneLineBlockKeyWords: RegExp = new RegExp(/(PROCEDURE)[^\w](?!.+[^\w]IS([^\w]|$))/);//match PROCEDURE..; but not PROCEDURE .. IS;


+ 7
- 0
tests/VHDLFormatter.test.ts View File

@ -95,6 +95,13 @@ describe('VHDLFormatter', function () {
let result = beautify(input, setting);
expect(result).toBe(expected);
});
it('semicolon blocks are aligned', function () {
let settings = GetDefaultSettings();
let input = 'OUT <= In0 AFTER 2ns WHEN "00",\r\n In1 AFTER 2ns WHEN "01",\r\n In2 AFTER 2ns WHEN "10",\r\n In3 AFTER 2ns WHEN "11";';
let result = beautify(input, settings);
expect(result).toBe(input);
});
});
function GetDefaultSettings(indentation: string = " "): BeautifierSettings {


Loading…
Cancel
Save