Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-09

Breaking Pascal source lines

9 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

I'm sure there isn't a single "right" answer to this question, but if transferring Pascal source to a system that enforces short lines (e.g. 78 chars + CRLF) what's the best automatic breaking rule?

One possibility is obviously to break after the rightmost space, but is it valid to break after e.g. . (if not followed by a digit), ^ and possibly others?

Syntax errors are acceptable. Truncation isn't.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Frederic Da Vitoria
to Mark Morgan Lloyd

2013/9/6 Mark Morgan Lloyd

Show quoted text 10 lines
I'm sure there isn't a single "right" answer to this question, but if transferring Pascal source to a system that enforces short lines (e.g. 78 chars + CRLF) what's the best automatic breaking rule? One possibility is obviously to break after the rightmost space, but is it valid to break after e.g. . (if not followed by a digit), ^ and possibly others? Syntax errors are acceptable. Truncation isn't.

Yes.

You could also split after ] and := and ;

More tricky, you could recognize < < <= and <=

But your splitter must be able to know when it is inside a string (no splitting) and outside. Which means your splitter should be able to recognize the right quote too and split after it if suitable.

Frederic Da Vitoria (davitof) Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org

Reply by email

Howard Page-Clark
to Mark Morgan Lloyd: I'm sure there isn't a single "right" answer to this question, but if transferring Pascal…
Mark Morgan Lloyd wrote 10 lines
I'm sure there isn't a single "right" answer to this question, but if transferring Pascal source to a system that enforces short lines (e.g. 78 chars + CRLF) what's the best automatic breaking rule? One possibility is obviously to break after the rightmost space, but is it valid to break after e.g. . (if not followed by a digit), ^ and possibly others? Syntax errors are acceptable. Truncation isn't.

Is it valid...? Yes.
The compiler largely ignores line endings and line breaks (since they're inserted mainly for formatting, not syntax purposes). One exception is string constants, so your parser will have to track the "'" character and ensure a corresponding later match within the short line, or else insert a forced concatenation.
The code

type
PInteger = ^
integer;

has readability shortcomings, but compiles without a murmur.

Reply by email

Mark Morgan Lloyd
to Howard Page-Clark
Howard Page-Clark wrote 18 lines
On 06/09/2013 14:10, Mark Morgan Lloyd wrote: > I'm sure there isn't a single "right" answer to this question, but if > transferring Pascal source to a system that enforces short lines (e.g. > 78 chars + CRLF) what's the best automatic breaking rule? > > One possibility is obviously to break after the rightmost space, but is > it valid to break after e.g. . (if not followed by a digit), ^ and > possibly others? > > Syntax errors are acceptable. Truncation isn't. > Is it valid...? Yes. The compiler largely ignores line endings and line breaks (since they're inserted mainly for formatting, not syntax purposes). One exception is string constants, so your parser will have to track the "'" character and ensure a corresponding later match within the short line, or else insert a forced concatenation. The code

Also single-line comments are obviously broken by wrap, i.e. preceded by //

I can cope without trying to parse for strings etc., since I think that in all cases compiling a broken string would result in a syntax error.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Bernd Oppolzer
to Mark Morgan Lloyd: I'm sure there isn't a single "right" answer to this question, but if transferring Pascal…
Mark Morgan Lloyd wrote 10 lines
I'm sure there isn't a single "right" answer to this question, but if transferring Pascal source to a system that enforces short lines (e.g. 78 chars + CRLF) what's the best automatic breaking rule? One possibility is obviously to break after the rightmost space, but is it valid to break after e.g. . (if not followed by a digit), ^ and possibly others? Syntax errors are acceptable. Truncation isn't.

To keep the syntax correct, you can break after every symbol, that is:

not inside identifiers,
not inside numbers (including floating point constants) not inside quoted strings

but anywhere else

I am using a Pascal pretty print program, that knows about the syntax (a little) and outputs the source in lines of 72 chars at most - this limit can be modified via parameter, IIRC.

But: at the moment it accepts only classical Pascal syntax (my extension of Stanford P4) - no FPC. So it makes not much sense to share it. But I compiled it with FPC recently, and it ran without problems on Windows.

Kind regards

Bernd

Reply by email

Bernd Oppolzer
to Bernd Oppolzer
Bernd Oppolzer wrote 22 lines
To keep the syntax correct, you can break after every symbol, that is: not inside identifiers, not inside numbers (including floating point constants) not inside quoted strings but anywhere else I am using a Pascal pretty print program, that knows about the syntax (a little) and outputs the source in lines of 72 chars at most - this limit can be modified via parameter, IIRC. But: at the moment it accepts only classical Pascal syntax (my extension of Stanford P4) - no FPC. So it makes not much sense to share it. But I compiled it with FPC recently, and it ran without problems on Windows. Kind regards Bernd
it's not quite correct;
if there are symbols like := that consist of more than one char,
you must not break in the middle.

Kind regards

Bernd

Reply by email

Mark Morgan Lloyd
to Bernd Oppolzer: it's not quite correct; if there are symbols like := that consist of more than one char,…
Bernd Oppolzer wrote 27 lines
Am 06.09.2013 18:16, schrieb Bernd Oppolzer: > To keep the syntax correct, you can break after every symbol, that is: > > not inside identifiers, > not inside numbers (including floating point constants) > not inside quoted strings > > but anywhere else > > I am using a Pascal pretty print program, that knows > about the syntax (a little) and outputs the source in > lines of 72 chars at most - this limit can be modified via parameter, > IIRC. > > But: at the moment it accepts only classical Pascal syntax (my extension > of Stanford P4) - no FPC. So it makes not much sense to share it. > But I compiled it with FPC recently, and it ran without problems on > Windows. > > Kind regards > > Bernd > it's not quite correct; if there are symbols like := that consist of more than one char, you must not break in the middle.

In particular things like += which might not be expected by people used to other dialects.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email