Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--brackets=attach breaks the code #25

Open
MikeWalrus opened this issue Feb 20, 2022 · 1 comment
Open

--brackets=attach breaks the code #25

MikeWalrus opened this issue Feb 20, 2022 · 1 comment

Comments

@MikeWalrus
Copy link
Contributor

original file:

module a(
        input b
    );
    always @(*) begin      
        if (b)                            
        begin
        end
        else
        begin
        end
    end
endmodule

after formatting using -a

module a(
        input b
    );
    always @(*) begin
        if (b)begin
        end
        elsebegin
        end
    end
    endmodule

expected

module a(
        input b
    );
    always @(*) begin
        if (b) begin
        end
        else begin
        end
    end
endmodule

This might have something to do with #20 and the member function ASFormatter::appendSpacePad().
When there is no character to peek (i.e.: at the end of the line), appendSpacePad refuses to append a space, which causes the content of the next line to "attach" to the current line without a space in between.

To fix this, the implementation of the newer AStyle might be helpful. They have two separate methods to append a space.

/**
 * append a space to the current formattedline, UNLESS the
 * last character is already a white-space character.
 */
void ASFormatter::appendSpacePad()
{
	int len = formattedLine.length();
	if (len > 0 && !isWhiteSpace(formattedLine[len - 1]))
	{
		formattedLine.append(1, ' ');
		spacePadNum++;
		if (maxCodeLength != string::npos)
		{
			// These compares reduce the frequency of function calls.
			if (isOkToSplitFormattedLine())
				updateFormattedLineSplitPoints(' ');
			if (formattedLine.length() > maxCodeLength)
				testForTimeToSplitFormattedLine();
		}
	}
}

/**
 * append a space to the current formattedline, UNLESS the
 * next character is already a white-space character.
 */
void ASFormatter::appendSpaceAfter()
{
	int len = currentLine.length();
	if (charNum + 1 < len && !isWhiteSpace(currentLine[charNum + 1]))
	{
		formattedLine.append(1, ' ');
		spacePadNum++;
		if (maxCodeLength != string::npos)
		{
			// These compares reduce the frequency of function calls.
			if (isOkToSplitFormattedLine())
				updateFormattedLineSplitPoints(' ');
			if (formattedLine.length() > maxCodeLength)
				testForTimeToSplitFormattedLine();
		}
	}
}
@thomasrussellmurphy
Copy link
Owner

Pull requests welcome. I have no good understanding of how old aStyle was converted to support Verilog by the original devs. If you have familiarity with these functions from the distant parent project, please see how they substitute into this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants