How to get the value of a multi-line string literal #1891
-
In our grammar, we want to disallow linebreaks in normal string literals. For multi-line strings, the users shall use triple-quoted strings, e.g.: In both single-line strings and multi-line strings, if the user wants the text to contain a quote or a backslash, then they shall escape them with a backslash. Other characters can also be preceded with a backslash, which will have no effect. To enable all this, we modified the STRING terminal into this: This will accept input such as: Is there a way to tell the engine to trim the quotes, so that we don't have to do it programmatically every time we access the property? We noticed that Langium automatically trims one leading and trailing quote and unescapes the characters when the terminal is called STRING. When I rename the terminal to STRING2, it won't trim or unescape anything. Where's that trimming/unescaping mechanism implemented? Is it possible for me as a developer to adapt it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This is done by the ValueConverter service: https://github.com/eclipse-langium/langium/blob/main/packages/langium/src/parser/value-converter.ts You can customize that (override the default through dependency injection) to provide one that handles your multiline strings by trimming and unescaping. |
Beta Was this translation helpful? Give feedback.
-
Thank you! |
Beta Was this translation helpful? Give feedback.
This is done by the ValueConverter service: https://github.com/eclipse-langium/langium/blob/main/packages/langium/src/parser/value-converter.ts
You can customize that (override the default through dependency injection) to provide one that handles your multiline strings by trimming and unescaping.