Skip to content
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

Escape characters in Strings #744

Closed
RieksJ opened this issue Jan 18, 2018 · 3 comments
Closed

Escape characters in Strings #744

RieksJ opened this issue Jan 18, 2018 · 3 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior component:parser good first issue Indicates a good issue for first-time contributors

Comments

@RieksJ
Copy link
Contributor

RieksJ commented Jan 18, 2018

I used Ampersand-v3.9.1 [development:b051de7] when compiling the following script:

CONTEXT KvK_ZZPRegForms
INCLUDE "..\SSIF-Generic\SSIF_FormTemplates.adl"
-- etc...
ENDCONTEXT

I expected that the texts between quotes after the INCLUDE statement would be recognized as a string literal. However, It resulted in the following error message:

Lexer error at line 3:9, file C:\Ampersand\Git\tno-models\SSIF-KvK\KvK_ZZPRegistrationForms.adl
  Unterminated string literal
    Correct examples of Strings: "Ampersand (&) is cool" "Helium is cool too!" "abc\ndef" ""
Terminated at ...: 15:57:43,67

Diagnosis

After some tinkering, it turned out that I needed to replace the \ characters with /. Perhaps the \S is treated as a separator that terminates the parsing of a literal, because I also tried the example "abc\ndef" as given in the error message.

It seems to me that if beginners get this error, they would have no clue where to look, let alone where to fix this.

@RieksJ RieksJ added bug Indicates an unexpected problem or unintended behavior component:parser good first issue Indicates a good issue for first-time contributors labels Jan 18, 2018
@hanjoosten
Copy link
Member

hanjoosten commented Jan 18, 2018

Since we like to be able to represent all imaginable strings, we need some way to denote a string that holds a double quote. If nothing was done, the first double quote in the string would be interpreted as the end of the string. Also, we want some way to represent multi-line strings.
To do so, we have \ as an escape character, as is done in C, in Haskell and in many other computer languages. For those interested, we use the same as Haskell does. (documentation is here).

In the above case, I would recommend to write:

CONTEXT KvK_ZZPRegForms
INCLUDE "../SSIF-Generic/SSIF_FormTemplates.adl"
-- etc...
ENDCONTEXT

but you could also write:

CONTEXT KvK_ZZPRegForms
INCLUDE "..\\SSIF-Generic\\SSIF_FormTemplates.adl"
-- etc...
ENDCONTEXT

In the latter case, the escape character is escaped itself!

Feel free to update the documentation if you find that useful.

@hanjoosten hanjoosten changed the title Sting literals parsing error Escape characters in Strings Jan 18, 2018
@RieksJ
Copy link
Contributor Author

RieksJ commented Jan 18, 2018

The bug is not the fact that the parsing is wrong, but that the error message does not help the user - particularly if they are beginners. As I have mentioned before, error messages are there to help the user, and I consider it a bug if they do not. In this example, that is the case.

It would be nice if the error message could be extended to include the text This error may be caused by a missing quote-character ('"'), or by the inadvertent use of the escape character ('\'). Would you be so kind as to grant me this wish?

@RieksJ RieksJ reopened this Jan 18, 2018
@hanjoosten
Copy link
Member

Poof! Wish granted 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior component:parser good first issue Indicates a good issue for first-time contributors
Projects
None yet
Development

No branches or pull requests

3 participants