On Tue, 18 Aug 2020, Dwight Schauer via fpc-pascal wrote:

On Tue, 2020-08-18 at 23:17 +0200, Marco van de Voort via fpc-pascal
wrote:
Op 2020-08-18 om 23:01 schreef Sven Barth via fpc-pascal:
> Might be the even better solution as fcl-passrc will be better > maintained due to it being used for both the documentation utility > fpdoc as well as pas2js. > Parsers for compilers or source transformation usually discard whitespace asap, while editor and formatting parsers don't. Usually they are different beasts.

The only signifiicant whitespace I'm concerned about is that found in
string literals and in comments. Other whitespace or manual formatting
does not really apply to any strict standard style conformance. I'm not
looking for something that honors personal tweaking here and there.

As far as whitespace in literal strings, I'm sure those don't get
mangled for pas2js (other than maybe the escaped characters changing,
but the transformed string is still going to be an equivalent one).

Now I've seen formatters for other languages, Go for instance, that
sort imports and removes ones that are not referenced.

I'm not looking to set up something that invasive. I just want
something that I have a few sets of configs that I'm able to tweak
make the code adhere to different standards or formatting style. And
have one for the style I prefer, but if I need something to be in
someone else's style, no problem. (Which I can currently do with clang-
tidy).

clang-tidy in my experience for C/C++ seems to throw away all your
whitespace, and reformat according the standard you have chose (which
you can tweak). With some exception though as far "all whitespace".

As long as the code only gets alterned into something logically
equivalaent, and as long as I can retreive the contents of comments
formatted as they were originally, I'm not concerned. (Other than
enforcing so many so many spaces after something like // and before it,
lining up // on adjacent lines in a configurable manner, etc.)

You cannot easily do this with the current fcl-passrc. In fact, I would
not recommend it.

The comments are not kept and do not appear in the AST built by the parser.
There is a way to keep the comments, but all info as to where they should be
inserted is lost. There are ways to solve this, but you will never be able
to insert all comments again; only some constructs can be recognized and
reproduced.

A second problem is that if you use IFDEFS, you will only see the part of
your code that corresponds to the conditional branches taken in the code.

If you are concerned with reformatting only, then ptop is the better way to go.
It just cares about tokens, and will process all branches of conditional
code.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to