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;
This might be implemented in one of a couple of ways:
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.
Write the entire source, then use a parser (such as DelphiAST) to identify where breaks need to occur.
For example when importing the
Intents
framework, this code is generated:Line breaks should occur using these rules:
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 keywordfunction
.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: