epics-extensions / tree-sitter-epics

Parsers for various EPICS-specific syntaxes
MIT License
6 stars 1 forks source link

[.cmd] comments can't be on the same line of dbpf ? #2

Open vnadot opened 1 year ago

vnadot commented 1 year ago

line:

dbpf toto 8 # this is a comment

tree-sitter message:

MISSING "\n"

fix:

dbpf toto 8 
# this is a comment

In my opinion, this should be allowed

minijackson commented 1 year ago

So, after analyzing the iocsh parser, what happens is that # this is a comment is not interpreted as a comment.

What happens is this:

dbpf("toto", "8", "#", "this", "is", "a", "comment")

But dbpf doesn't look at arguments 3 to 7, so it gets ignored.

I'm kinda want to keep the current behavior, since you're using the parser to validate cmd files. We might want to discourage end of line comments to prevent accidents like these:

dbpf "toto" # somehow "#" is written into toto
anjohnson commented 1 year ago

@minijackson This probably indicates a bug in iocsh, could you raise it as an issue against epics-base please? The command parser knows how many arguments most iocsh commands expect (except for those which take a variable number using argc+argv), so maybe it should be displaying a warning or an error when it sees extraneous parameters for the commands it knows about? Alternatively it could allow trailing comments, but the # character must start a new command parameter so this is not valid:

dbpf toto 8# this is not a comment

The dbpf command there would be given the value string 8# but the remaining parameters should raise that "extra parameters" warning/error first. I expect there to be discussion about whether it should be rejected as an error or just print a warning.