Skip to content

Syntax/Pascal: Support multiline strings #2731

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

Merged
merged 6 commits into from
Apr 22, 2025

Conversation

baka0815
Copy link
Contributor

@baka0815 baka0815 commented Apr 15, 2025

Delphi introduced multiline strings in version 12. They start with ''' and end with ``'''```.
Supersedes #2720.

Before:
grafik

After:
grafik

@sdottaka is there a better constant that COOKIE_BLOCK_STYLE to use?

Delphi introduced multiline strings in version 12. They start with ''' and end with '''.
The string '''' was not interpreted as a single quotation mark but instead as the start of a multiline string.
Inside a multiline string there is no other syntax highlighting and a single quotation mark (') is valid and does not end the string. The multiline string only ends if a corresponding end (''') is found.
@sdottaka
Copy link
Member

sdottaka commented Apr 15, 2025

Thank you for the correction. However, according to this blog, there are the following rules:

  • It is introduced by a triple quote ('''') and a new line (so no text following the triple quotes on the same line)

  • It can encompass multiple lines of the source code file (with no limitation)

  • It ends with a closing triple quote ('''') in a line without any text preceding it

The current implementation does not seem to follow these rules, and the following is also considered to be multiline strings.
(I'm not familiar with Pascal, so I don't know if the following lines are syntactically correct.)

a = Char('''a');

@baka0815
Copy link
Contributor Author

You're technically right.

This is how it looks in Delphi 12.3 (my color schema):
grafik

Text after the starting or before the ending triple quote will result in compile errors, however it does not affect the syntax highlighting:
grafik grafik

However you're right, that var L := Length('''a'); will be treated as the start of the multi-line string where it should be a single quote and an a ('a).

The start of a multi-line string is three single quotation marks (''') and then a newline (however spaces and tabs are ok). So check if that is the case.
Otherwise ``Test := '''a';`` would be treated as the start of a multi-line string instead of a single quotation mark and an a.
@baka0815
Copy link
Contributor Author

@sdottaka I changed the code to detect text following the start of the multi-line string. This is then not exactly what Delphi renders, but since this would be a syntax error, I think it's fine.

grafik
grafik

@sdottaka
Copy link
Member

There's one more thing I'd like you to fix. d := 1 should be considered a multiline string, but it isn't.
If there are any other issues, I'll adjust them.

image

There may not be any character in front of the end of the multi-line string. This ensures, that the multi-line coloring is not disrupted with single quotation marks.
@baka0815
Copy link
Contributor Author

baka0815 commented Apr 22, 2025

Well, Delphi does not really know what it wants to do here:
grafik
It colors the text as a multi-line string, but at the same time gives the error E2658.

With my latest commit the coloring is ok in WinMerge (I changed the screenshot in the PR message):
grafik

@sdottaka sdottaka merged commit 8f89568 into WinMerge:master Apr 22, 2025
3 checks passed
@sdottaka
Copy link
Member

Thank you for the fix. I've merged this PR.
I plan to make some additional adjustments later, such as changing COOKIE_BLOCK_STYLE to COOKIE_RAWSTRING.

@sdottaka sdottaka added this to the v2.16.48 milestone Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants