DSL Items Parser: Fix incorrect parsing of keywords encountered in the wrong context - #4928
Conversation
934006e to
36c7227
Compare
36c7227 to
da216da
Compare
|
@jimtng many thanks for picking this up. It seems that the tests, although running, are now failing, but you are obviously on the right track. I have no knowledge of xtext so can’t really help any more with the details.. |
da216da to
f1c4701
Compare
e205dac to
4ba2b73
Compare
|
This passed now. However I've updated the original post with some further explanation |
|
@jimtng I think the ^ prefix is a horrible hack, and IMHO not a solution. The parser should break on new lines, and if the word Switch is at the start of the line it should be interpreted as an item type; and if anywhere else it should be interpreted as a string (label or tag name). I think a simple regex could easily identify the two cases. |
|
Note that if this PR is not merged, the code generating DSL format for item has to be fixed to add the character `^ when expected when generating tags. |
|
^ and we would probably need for safety sake to fix all item getTag(s) and setTag(s) methods to eliminate any stray carets. As I say, I think it is a horrible hack, and I strongly argue to solve this properly. We all know the proper syntax since years, and we should not allow a compromise in order to avoid a fix. |
|
If the current parser really cannot distinguish between Switch at the start of a line and Switch anywhere else, the we should implement a regex pre-parser to do that in an inter- phase between loading the file and passing the stream to the existing parser. |
|
But when the user writes ^Switch, I guess that the XText parser automatically removes the ^. So the resulting tag is Switch as we expect. |
|
Maybe. Who knows. My argument is to make the code accept the syntax that every user knows since OH v1.0 and not introduce some queer kludge to avoid fixing a bug in the code that will confuse everybody. |
|
Apparently noone was annoyed by this "bug" since several years ;) I just checked how I myself solved this problem in my own file. I did not use ^ character at all but all my tags are between double quotes like for example: IMHO, as string are accepted in addition to ID by the parser, it is fine and there is nothing to fix. If the user wants to use a tag that is a special keyword, he just has to surround it with double-quotes. |
|
But @jimtng proposal is also an improvement as it allows a syntax that was not possible before, so why not. |
|
Can either of you explain why the parser is not capable to detect the difference between |
|
I also checked for an item what is the generated code from Main UI and everything is OK, this is not a string that is used but the escape character: So nothing to change/fix in the DSL generator. |
This comment was marked as outdated.
This comment was marked as outdated.
|
I would suggest to not start a big change with risk while this is something that everyone using .items already knows how to handle. Maybe something could be added in our documentation to help someone who could encounter that error for the first time. |
I don't agree. |
|
For tags, including generating DSL syntax, I'd suggest just using quoted strings instead of caret or bare. I tried finding a syntax or solution but haven't found one that's simple/straight forward. |
indeed, that's good to know! |
|
I tried creating an item in the UI:
That worked and generated the correct DSL: Then I set the icon to |
|
Marking this PR as Draft. I'm not happy with the current solution. |
22619a2 to
7d6271b
Compare
…e wrong context When specifying tag names that match one of the valid item types, e.g. `Switch`, the parser incorrectly treated it as a new start of an item definition. Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
…mentUtils Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
… loading behavior Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
ddd329c to
c79a621
Compare
|
Build failed, you need to apply spotless in /org/openhab/core/model/item |
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
Closes openhab#4903 Makes check consistent with what was done for DSL in openhab#4928 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Closes openhab#4903 Makes check consistent with what was done for DSL in openhab#4928 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
Closes openhab#4903 Makes check consistent with what was done for DSL in openhab#4928 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
|
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
When specifying tag names that match one of the valid item types, e.g.
Switch, the parser incorrectly treated it as a new start of an item definition.Fix #4927
Consider backporting to 4.3.xThis is a bigger change than I originally thought, it shouldn't be backportedLonger explanation:
The standard way xtext parser / grammar deals with this is to prefix conflicting literals such as
Switch,AND,Group, etc with a caret^. So even without this PR, this would work:This PR makes this possible:
See Copilot review for more details.
Also "fixed": removed space in the generated DSL item format, from:
to
Copilot Summary
Pull Request Overview
This PR fixes incorrect parsing of DSL items when keywords matching valid item types (like "Switch", "Group", etc.) are used in other contexts such as tag names. Previously, the parser would incorrectly treat these as new item definitions.
ModelGroupItemandModelNormalItemtypes in favor of a unifiedModelItemapproachGroup:Switch:OR(ON,OFF)instead ofGroup:Switch:OR (ON,OFF))Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file