adobe / htl-spec

HTML Template Language Specification
Apache License 2.0
280 stars 146 forks source link

Questions about grammar #34

Closed karollewandowski closed 7 years ago

karollewandowski commented 7 years ago

I analysed HTL grammar and it seems to me, that there are two issues:

  1. Lack of bracket notation property access (properties['key']) - where is it? Maybe it's implicitly included, but I tried to find it without success.
  2. Why only spaces are allowed around colon in ternary branches separator? I understand the reason for spaces - identifiers can contain :, but I think that it's nothing uncommon to format HTML files with tabs and have something like:
    ${someVal ? "Lorem ipsum dolor sit amet"
    <tab><tab>: ""}

Branches separator can't be properly parsed in such code and it can be confusing for developers ("why the hell it doesn't work?"). In my opinion all white spaces should be allowed.

vladbailescu commented 7 years ago
  1. Bracket property access is specified both in the grammar and in the more detailed expression examples: https://github.com/Adobe-Marketing-Cloud/htl-spec/blob/master/SPECIFICATION.md#112-expressions

  2. The ternary operator specifies whitespaces around branches and these are defined as either space, tab, carriage return or new line in the grammar. The following expression works (second line as a tab and three spaces:

    ${true ? "true" 
       : "false"}
karollewandowski commented 7 years ago

Thanks for your answer, but it's still unclear.

  1. Could you please point me where exactly it is? I mean grammar, not examples in documentation. I'm developing IntelliJ plugin for HTL and want to be consistent with grammar from official specification, that's why it's important to me.

  2. Hmm, in grammar I can only see:

    /* Note required space characters around ':' */
    exprNode = binaryOp , '?' , binaryOp , ws , ' : ' , ws , binaryOp
         | binaryOp ;

    Token ' : ' has spaces around colon (as comment states). Whitespaces are around full ' : ' token. Maybe it works for current implementation, but grammar does not allow tabs/new lines just before colon. Again - it's important from HTL plugins developers point of view. Edit: I missed that you pasted <tab><3 spaces>. The question is why can't we put tab/new line just before colon? Is there any reason?

vladbailescu commented 7 years ago

Yes, I think there things that need improvement, thanks for bringing it up!

raducotescu commented 7 years ago

@karollewandowski, I've updated the EBNF in b9168a5. Hope this makes it clearer.

karollewandowski commented 7 years ago

@raducotescu, thank you for update. It's correct and clear now.