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

Include an option for where line breaks should occur #5

Open
DelphiWorlds opened this issue Jun 15, 2023 · 1 comment
Open

Include an option for where line breaks should occur #5

DelphiWorlds opened this issue Jun 15, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@DelphiWorlds
Copy link
Collaborator

DelphiWorlds commented Jun 15, 2023

For example when importing the Intents framework, this code is generated:

  INBoatTrip = interface(NSObject)
    ['{AB88A6B6-EFAA-4D6D-A4D2-A55983C4E890}']
    function arrivalBoatTerminalLocation: CLPlacemark; cdecl;
    function boatName: NSString; cdecl;
    function boatNumber: NSString; cdecl;
    function departureBoatTerminalLocation: CLPlacemark; cdecl;
    function initWithProvider(provider: NSString; boatName: NSString; boatNumber: NSString; tripDuration: INDateComponentsRange; departureBoatTerminalLocation: CLPlacemark; arrivalBoatTerminalLocation: CLPlacemark): Pointer; cdecl;
    function provider: NSString; cdecl;
    function tripDuration: INDateComponentsRange; cdecl;
  end;
  TINBoatTrip = class(TOCGenericImport<INBoatTripClass, INBoatTrip>) end;

Line breaks should occur using these rules:

  • Break at the last parameter if any of it, or anything subsequent (e.g. result type etc) crosses the margin - in this case it would be departureBoatTerminalLocation: CLPlacemark; - if any part of this crosses the margin, the whole parameter should begin on the next line, indented 2 spaces from the text directly above it - in this case, the keyword function.
  • If the remainder of the declaration also crosses the margin, apply the rule again, except indent at the same level as the last break
  • Comments related to deprecation etc should not break

Other rules need to be formulated for other declarations. Using the rules above, with a margin of 150 characters, the class declaration would become this:

  INBoatTrip = interface(NSObject)
    ['{AB88A6B6-EFAA-4D6D-A4D2-A55983C4E890}']
    function arrivalBoatTerminalLocation: CLPlacemark; cdecl;
    function boatName: NSString; cdecl;
    function boatNumber: NSString; cdecl;
    function departureBoatTerminalLocation: CLPlacemark; cdecl;
    function initWithProvider(provider: NSString; boatName: NSString; boatNumber: NSString; tripDuration: INDateComponentsRange;
      departureBoatTerminalLocation: CLPlacemark; arrivalBoatTerminalLocation: CLPlacemark): Pointer; cdecl;
    function provider: NSString; cdecl;
    function tripDuration: INDateComponentsRange; cdecl;
  end;
  TINBoatTrip = class(TOCGenericImport<INBoatTripClass, INBoatTrip>) end;
@DelphiWorlds DelphiWorlds added the enhancement New feature or request label Jun 15, 2023
@DelphiWorlds DelphiWorlds self-assigned this Jun 15, 2023
@DelphiWorlds
Copy link
Collaborator Author

This might be implemented in one of a couple of ways:

  1. Modify TSourceWriter to keep track of the number of characters that have been written to the current line so far, have it be aware of what is about to be written (i.e. whether it's a method parameter etc), and "break" if what is about to be written will exceed the margin. This could prove difficult if a rule is to break before a parameter that has already been written.
  2. Write the entire source, then use a parser (such as DelphiAST) to identify where breaks need to occur.

I'm leaning towards option 2

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

No branches or pull requests

1 participant