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

Proper ways for Multiline String and String Interpolation #481

Closed
swety2003 opened this issue Sep 14, 2024 · 9 comments
Closed

Proper ways for Multiline String and String Interpolation #481

swety2003 opened this issue Sep 14, 2024 · 9 comments

Comments

@swety2003
Copy link

Is there a suitable way to implement multi-line string and string interpolation like C #?

@b3b00
Copy link
Owner

b3b00 commented Sep 20, 2024

hello @swety2003 , using GenericLexer , the String lexeme should natively handle multiline strings.

Regarding string interpolation, I think the best way is using GenericLexer modes

hope this would help

Olivier

@b3b00
Copy link
Owner

b3b00 commented Sep 21, 2024

@swety2003 are you ok with my answer ?
Could you close thé issue please ?

@swety2003
Copy link
Author

Well, GenericLexer can indeed solve the problem of multi line strings, but the delimiter can only be one character. How can we parse strings with multiple characters as delimiters?

    [String(delimiter:"\"\"")]
    STRING,

LEXER_STRING_DELIMITER_MUST_BE_1_CHAR [FATAL] bad lexem "" : StringToken lexeme delimiter char must be 1 character length

@b3b00
Copy link
Owner

b3b00 commented Sep 22, 2024

@swety2003 could you please explain precisely what kind of token you are trying to parse ?

@swety2003
Copy link
Author

For example:

configureFlags = ""
  -system-zlib -system-libpng -system-libjpeg
  ${if openglSupport then "-dlopen-opengl
    -L${mesa}/lib -I${mesa}/include
    -L${libXmu}/lib -I${libXmu}/include" else ""}
  ${if threadSupport then "-thread" else "-no-thread"}
"";

@b3b00
Copy link
Owner

b3b00 commented Sep 22, 2024

So, to sum up you need a string that

  • starts and ends with double double quotes ""...""
  • Can contain interpolated expressions surrounded by braces {}. Those expressions may contains strings, with one double quote as delimiter

Then the generic lexer modes is the way to go.

@swety2003
Copy link
Author

OK, thank you for your help, I'll try to use it to solve the problem.

@b3b00
Copy link
Owner

b3b00 commented Sep 22, 2024

You Can take a look at https://github.com/b3b00/csly/tree/dev/src/samples/SimpleTemplate for inspiration.

@b3b00
Copy link
Owner

b3b00 commented Nov 8, 2024

@swety2003 , to fix issue #495 i've done what you want in the IndentedwhileParser. you can take a look it should answer most of your need

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

No branches or pull requests

2 participants