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

Inconsistent/unclear whitespace stripping rules #147

Open
sbogie-gdi opened this issue May 4, 2023 · 2 comments
Open

Inconsistent/unclear whitespace stripping rules #147

sbogie-gdi opened this issue May 4, 2023 · 2 comments
Assignees
Labels
bug Something isn't working commercial support required commercial subscriber feature enhancement New feature or request

Comments

@sbogie-gdi
Copy link

The new whitespace stripping logic seems inconsistent/unclear and is in general just difficult to use to achieve the desired result.

  1. The documentation suggests that + and * should stop at a newline, but in practice they will remove multiple newlines, and any leading whitespace of the following line.

    Hello <% "world" *%>
    
    
        Testing
    

    becomes

    Hello·worldTesting
    
  2. The documentation gives conflicting explanations for behavior on blocks. Suggesting that

    ••••<%- if cond *%>••••<NL>
    ••••<% 'hello' %>••••<NL>
    ••••<%- end *%>••••<NL>
    

    will resolve to both

    ••••hello••••<NL>
    

    and

    hello
    

    while ultimately producing

    hello<NL>
    
  3. This application of the <%- at the start of a block to all sub elements means there is no clean way to completely remove the line on which a block starts without also removing any leading whitespace from within the block

  4. The left side stripping indicator on a <%- end *%> statement is ignored resulting in any preceding whitespace being applied to the next line

    <% if true *%>
        asdf
        <%- end *%>
    ghjk
    
    asdf
    ···ghjk
    

These all combine to produce some quite unexpected results with e.g. nested for loops

{
    <% for i := 1 to 2 *%>
    "<% i %>": [
        <% for j := 1 to 2 *%>
        <% j %>,
        <%- end *%>
    ]
    <%- end *%>
}
{
····"1":·[
········1,
········2,
········]
····"2":·[
········1,
········2,
········]
····}
@darnocian darnocian self-assigned this May 4, 2023
@darnocian
Copy link
Collaborator

Yeah, the whitespace issue was a tricky one to conceptualise. Thank you again for the feedback. It is appreciated and will try to improve this.

Btw. I'm not sure if you are aware - you can view the Playground app allows you to view the AST and see how it is going to strip things.

With simple statements, the trim indicator to the left would theoretically apply to the left up until the newline, and the one on the right would be till the next non whitespace/newline. <%- trims to the left, and -%> trims to the right.

The statements having a body were a little more tricky as the consideration was:

  • stripping before the body block
  • stripping inside the body block - left and right
  • stripping after the body block

Maybe needs more simplification, so any suggestions appreciated.

I'll review the scenarios in a bit more detail later and provide more feedback.

@darnocian
Copy link
Collaborator

My thinking at present to simplify things, is that the stripping hints should be only done on the begin tag. the hints will then be applied to all the lines contained within the begin and end tags.

Seperate to that, a feature / option can be included to strip lines that just contain a begin/end tag, and thus minimising empty lines.

Will review this for 1.7.3.

@darnocian darnocian added bug Something isn't working enhancement New feature or request labels Aug 24, 2023
@darnocian darnocian added the commercial support required commercial subscriber feature label Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working commercial support required commercial subscriber feature enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants