04c59867

By: Tom Sydney Kerckhove <syd@cs-syd.eu>

Add end-of-line comments and comments within declarations

A comment used to be a declaration of its own, so a comment written at the
end of a line, or between the lines of a transaction, was either a parse
error or was moved onto its own line by the formatter.

Every line can now carry a comment at the end of it, and comments on
indented lines of their own.  A comment on a line of its own belongs to the
line below it, so a comment cannot be the last line of a declaration: it
would belong to no line at all, which is an error that points at the
comment.

A comment on a line of its own has to be indented to belong to the
declaration it is in: a "--" at the first column starts a new declaration.
Comments above a declaration are already declarations of their own, so the
lines that a declaration cannot contain, an import, a currency, a tag, a
price, an account line and a timestamp line, hold only an end-of-line
comment.

The one line that cannot carry a comment at the end of it is a description,
because a description is the whole rest of its line.

Note that the lines of a transaction are one chain of productions rather
than three lists.  The comments above a line have to be read before it is
known which kind of line follows them, so a list per kind of line makes the
description/posting and posting/extra boundaries reduce/reduce conflicts.

Fix two bugs in the process, both of which the extra comment positions would
otherwise have made much easier to hit:

  * A comment whose text was only whitespace swallowed the declaration below
    it.  Nothing could match the rest of the line, so '$white+' matched the
    newline instead and left the lexer in the comment start code, reading the
    next declaration as comment text.  A comment is now a single token, so
    there is no start code left to be stranded in.

  * A file path was lexed with a character set containing an unescaped '.',
    which means "any character but a newline", so a path ran to the end of
    the line.  A trailing comment ended up inside the path.  A path may now
    contain spaces but not the "-- " that starts a comment.

Suite timing

Time to Start Worker time Duration Time to finish Idle
Config 0s 1s 1s 1s 0s
Eval 1s 17s 17s 18s 0s
Build 16s 4m30s 2m23s 2m39s 0s
Suite 0s 4m49s 2m39s 2m39s 0s

Timeline

0s20s40s1m1m20s1m40s2m2m20s