Browse Source

indent after assignment symbol

master
g2384 3 years ago
parent
commit
463eaf27d4
3 changed files with 91 additions and 3 deletions
  1. +7
    -0
      VHDLFormatter.js
  2. +8
    -1
      VHDLFormatter.ts
  3. +76
    -2
      tests/VHDLFormatter.test.ts

+ 7
- 0
VHDLFormatter.js View File

@ -784,6 +784,13 @@ function beautify3(block, result, settings, indent) {
Mode = modeCache;
continue;
}
if (input.regexIndexOf(/:=(\s*@@comments\d+\s*)?$/) > 0) {
let modeCache = Mode;
Mode = FormatMode.EndsWithSemicolon;
beautifySemicolonBlock(block, result, settings, indent);
Mode = modeCache;
continue;
}
if (input.regexStartsWith(/\w+\s*:\s*ENTITY/)) {
let modeCache = Mode;
Mode = FormatMode.EndsWithSemicolon;


+ 8
- 1
VHDLFormatter.ts View File

@ -516,7 +516,7 @@ function GetCloseparentheseEndIndex(block: CodeBlock) {
let openParentheseCount: number = 0;
let closeParentheseCount: number = 0;
let startIndex = block.cursor;
for (;block.cursor <= block.end; block.cursor++) {
for (; block.cursor <= block.end; block.cursor++) {
let input = block.lines[block.cursor];
openParentheseCount += input.count("(");
closeParentheseCount += input.count(")");
@ -866,6 +866,13 @@ export function beautify3(block: CodeBlock, result: (FormattedLine | FormattedLi
Mode = modeCache;
continue;
}
if (input.regexIndexOf(/:=(\s*@@comments\d+\s*)?$/) > 0) {
let modeCache = Mode;
Mode = FormatMode.EndsWithSemicolon;
beautifySemicolonBlock(block, result, settings, indent);
Mode = modeCache;
continue;
}
if (input.regexStartsWith(/\w+\s*:\s*ENTITY/)) {
let modeCache = Mode;
Mode = FormatMode.EndsWithSemicolon;


+ 76
- 2
tests/VHDLFormatter.test.ts View File

@ -119,7 +119,7 @@ describe('VHDLFormatter', function () {
let result = beautify(input, settings);
expect(result).toBe(input);
});
it('support invalid line', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
@ -135,7 +135,7 @@ describe('VHDLFormatter', function () {
let result = beautify(input, settings);
expect(result).toBe(input);
});
it('one-line initial values for constant', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
@ -143,8 +143,82 @@ describe('VHDLFormatter', function () {
let result = beautify(input, settings);
expect(result).toBe(input);
});
it('indent assignment statement (multiline, no comment)', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
let input = "CONSTANT Vcc : SIGNAL :=\r\n'1'; --logic 1 constant\r\nCONSTANT zero4 : bit_vector(0 TO 3) :=\r\n('0', '0', '0', '0');";
let output = "CONSTANT Vcc : SIGNAL :=\r\n '1'; --logic 1 constant\r\nCONSTANT zero4 : bit_vector(0 TO 3) :=\r\n ('0', '0', '0', '0');";
let result = beautify(input, settings);
expect(result).toBe(output);
})
it('indent assignment statement (with comment)', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
let input = "CONSTANT Vcc : SIGNAL := --logic 1 constant\r\n'1';\r\nCONSTANT zero4 : bit_vector(0 TO 3) :=--test\r\n('0', '0', '0', '0');";
let output = "CONSTANT Vcc : SIGNAL := --logic 1 constant\r\n '1';\r\nCONSTANT zero4 : bit_vector(0 TO 3) := --test\r\n ('0', '0', '0', '0');";
let result = beautify(input, settings);
expect(result).toBe(output);
})
it('indent assignment statement (multi line)', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
let input = [
"CONSTANT ALMOST_EMPTY_OFFSET : bit_vector(12 DOWNTO 0) :=",
" to_bitvector(STD_ULOGIC_VECTOR(to_unsigned(C_M_AXI_BURST_LEN - 1, 13)));",
"CONSTANT ALMOST_FULL_OFFSET : bit_vector(12 DOWNTO 0) :=",
" to_bitvector(STD_ULOGIC_VECTOR(to_unsigned(C_M_AXI_BURST_LEN - 1, 13)));"
];
let output = [
"CONSTANT ALMOST_EMPTY_OFFSET : bit_vector(12 DOWNTO 0) :=",
" to_bitvector(STD_ULOGIC_VECTOR(to_unsigned(C_M_AXI_BURST_LEN - 1, 13)));",
"CONSTANT ALMOST_FULL_OFFSET : bit_vector(12 DOWNTO 0) :=",
" to_bitvector(STD_ULOGIC_VECTOR(to_unsigned(C_M_AXI_BURST_LEN - 1, 13)));"
];
let result = beautifyTestHelper(input, settings);
expect(result).toStrictEqual(output);
})
it('indent assignment statement (multi line (2))', function () {
let settings = GetDefaultSettings();
settings.SignAlignSettings = new signAlignSettings(false, true, "", [], false);
let input = [
"CONSTANT ALMOST_EMPTY_OFFSET : bit_vector(12 DOWNTO 0) :=",
"to_bitvector(",
"STD_ULOGIC_VECTOR(",
"to_unsigned(",
"C_M_AXI_BURST_LEN - 1, 13)));",
"CONSTANT ALMOST_FULL_OFFSET : bit_vector(12 DOWNTO 0) :=",
"to_bitvector(",
"STD_ULOGIC_VECTOR(",
"to_unsigned(",
"C_M_AXI_BURST_LEN - 1, 13)));"
];
let output = [
"CONSTANT ALMOST_EMPTY_OFFSET : bit_vector(12 DOWNTO 0) :=",
" to_bitvector(",
" STD_ULOGIC_VECTOR(",
" to_unsigned(",
" C_M_AXI_BURST_LEN - 1, 13)));",
"CONSTANT ALMOST_FULL_OFFSET : bit_vector(12 DOWNTO 0) :=",
" to_bitvector(",
" STD_ULOGIC_VECTOR(",
" to_unsigned(",
" C_M_AXI_BURST_LEN - 1, 13)));"
];
let result = beautifyTestHelper(input, settings);
expect(result).toStrictEqual(output);
})
});
function beautifyTestHelper(array: Array<string>, settings: BeautifierSettings): Array<string> {
let input = array.join("\r\n");
let result = beautify(input, settings);
return result.split("\r\n");
}
function GetDefaultSettings(indentation: string = " "): BeautifierSettings {
let new_line_after_symbols = new NewLineSettings();
new_line_after_symbols.newLineAfter = ["then", ";"];


Loading…
Cancel
Save