[Pas2js] Multiline string and INCLUDESTRING directive

Ben Grasset operator97 at gmail.com
Sat Dec 12 19:20:08 CET 2020


Very cool! And unexpected. That reminds me, I think I actually need to
upload a fresh version of the FPC multiline strings patch to that
bugtracker issue... had to fix some merge conflicts recently in my personal
branch, so the currently uploaded patch probably is not properly applicable.

On Tue, Dec 8, 2020 at 8:33 PM Michael Van Canneyt <michael at freepascal.org>
wrote:

>
> Hello,
>
> I have implemented support for multiline strings and the $INCLUDESTRING or
> INCLUDESTRINGFILE directive.
>
> I have used the same approach as the patches for the same features in
> Free Pascal: These are currently only in the bugtracker, but are scheduled
> to be applied in the hopefully near future...
>
> How does it work ?
>
> Multiline strings must be enabled with a modeswitch:
>
> {$MODESWITCH MULTILINESTRINGS}
>
> When enabled, you can use multiline strings.
>
> The backtick indicates a multi-line string:
>
> Const
>    SMyMulti = `My
> string
> that
> spans multiple lines`;
>
> Will create a multiple-line string.
>
> To include a backtick in the string itself, duplicate it:
> Const
>    SMyMulti = `My
> string
> that   ``is quoted`` and
> spans multiple lines`;
>
> #12 etc. will work as for normal strings.
>
> The line endings in the literal string are controlled by the
> MULTILINESTRINGLINEENDING
> directive:
>
> {$MULTILINESTRINGLINEENDING CR|LF|CRLF|SOURCE|PLATFORM}
>
> The value SOURCE means the line ending of the source file is taken,
> the other values enforce a particular line ending, where PLATFORM is the
> line ending of the compiler platform. CR, LF or CRLF are
> self-explanatory.
>
> 'Platform' is the default.
>
> The multiline string can also have initial spaces stripped; This is
> controlled by the MULTILINESTRINGTRIMLEFT directive:
>
> {$MULTILINESTRINGTRIMLEFT N|AUTO|ALL}
>
> N is an integer: At most N spaces will be stripped.
> AUTO means the position of the initial backtick is used to determine how
> many spaces will be stripped..
> ALL means all spaces will be stripped.
>
> {$MULTILINESTRINGTRIMLEFT AUTO}
> Const
>   S = `SELECT
>          *
>        FROM
>          MyTable`;
>
> is equivalent to
>
> {$MULTILINESTRINGTRIMLEFT 0}
> Const
>   S = `SELECT
>    *
> FROM
>    MyTable`;
>
>
>
> The $INCLUDESTRING directive will include the file as a literal string.
>
> This means that:
>
> Const
>    A = {$INCLUDESTRING myinclude.inc};
>
> Will define a constant A that has as a value the contents of myinclude.inc
> {$INCLUDESTRINGFILE myinclude.inc)
> has the same effect.
>
> The line endings in the constant A are determined also from the
> MULTILINESTRINGLINEENDING directive: the include file is read line by line
> and lines will be separated using the same mechanism as for multiline
> strings.
>
> The include file is searched using the include file path, just as for $I.
>
> These mechanisms have been implemented in the scanner/parser for pas2js in
> trunk. The 2.0 version will not have this.
>
> Some details may change when FPC gets the support for these features (for
> compatibility) but they will probably be minor.
>
> Enjoy,
>
> Michael.
>
> _______________________________________________
> Pas2js maillist  -  Pas2js at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20201212/cd1878cb/attachment.htm>


More information about the Pas2js mailing list