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

Non univocal formatting for certain lines #114

Open
LoZack19 opened this issue Sep 2, 2024 · 2 comments
Open

Non univocal formatting for certain lines #114

LoZack19 opened this issue Sep 2, 2024 · 2 comments

Comments

@LoZack19
Copy link

LoZack19 commented Sep 2, 2024

This line:

G = 1.4e9 / (s ^ 2 * (s+4.4e4));

Formats into this line:

G = 1.4e9 / (s ^ 2 * (s + 4.4e4));

Which formats in this line:

G = 1.4e9 / (s ^ 2 * (s +4.4e4));

Observe the spacing in the last parenthesis. I think that this behavior is unintended.

@LoZack19
Copy link
Author

LoZack19 commented Sep 2, 2024

It looks like a bug in the extract() function, probably in the way order it processes stuff. If it matches numbers before sums, it will consider the + sign as a part of the number instead of a part of the sum. In fact, logically the sum is evaluated before its components.

@LoZack19
Copy link
Author

LoZack19 commented Sep 2, 2024

Btw, main() would really benefit from using argparse.

def main():
    parser = argparse.ArgumentParser(
        prog="matlab_parser",
        description="Parser of matlab code",
    )

    parser.add_argument("--startLine", type=int, default=1)
    parser.add_argument("--endLine", type=int, default=None)
    parser.add_argument("--indentWidth", type=int, default=4)
    parser.add_argument("--separateBlocks", type=bool, default=True)
    parser.add_argument("--indentMode", type=str, default="all_functions")
    parser.add_argument("--addSpaces", type=str, default="exclude_pow")
    parser.add_argument("--matrixIndent", type=str, default="aligned")
    parser.add_argument("filename", type=str)
    args = parser.parse_args()

    indentModes = dict(all_functions=1, only_nested_functions=-1, classic=0)
    operatorSpaces = dict(all_operators=1, exclude_pow=0.5, no_spaces=0)
    matrixIndentation = dict(aligned=1, simple=0)

    indent: int = args.indentWidth
    start: int = args.startLine
    end: int = args.endLine
    sep: bool = args.separateBlocks
    mode: int = indentModes.get(args.indentMode)
    opSp: float = operatorSpaces.get(args.addSpaces)
    matInd: int = matrixIndentation.get(args.matrixIndent)

    formatter = Formatter(indent, sep, mode, opSp, matInd)
    formatter.formatFile(args.filename, start, end)

@LoZack19 LoZack19 changed the title Non univocal formattation for certain lines Non univocal formatting for certain lines Sep 7, 2024
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

1 participant