-
This should be an easy one ... the DSL I'm documenting the grammar for has some keywords that have white space (which is annoying). For example ... I have a grammar definition that looks like the following: SDBBlock:
...
'START TIME:' start=REAL uom=TimeUOM
'STOP TIME:' stop=REAL uom=TimeUOM
...
'END SCENARIO' status=SDBStatus
; Understandably, I get a ton of warnings of the type: Is there any easy way to turn this off? It's also possible that I'm doing this all wrong and have missed something completely obvious to real language designers. :) Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hey, so basically the warning is a nice reminder that keywords (even though the spec might say so) should never be whitespace sentitive in regards to lexing. The reasoning for that might not be completely obvious though: When creating a keyword such as On the other hand, there's a more user friendly way to deal with this issue. Obviously, it includes separating checkWhitespace(block: SDBBlock, acceptor) {
const endNode = findKeywordNode(block, 'END');
const scenarioNode = findKeywordNode(block, 'SCENARIO');
const document = getDocument(block);
if (endNode && scenarioNode) {
const spaceStart = endNode.range.end;
const spaceEnd = scenarioNode.range.start;
const range = Range.create(spaceStart, spaceEnd);
const text = document.textDocument.getText(range);
if (text !== ' ') {
acceptor('error', "Expected a single space character between 'END' and 'SCENARIO'", { node: block, range });
}
}
} Anyway, there's no way to turn validations off, we're currently investigating a |
Beta Was this translation helpful? Give feedback.
Hey, so basically the warning is a nice reminder that keywords (even though the spec might say so) should never be whitespace sentitive in regards to lexing. The reasoning for that might not be completely obvious though:
When creating a keyword such as
'END SCENARIO'
, every user error such asEND___SCENARIO
(think each_
as being a whitespace) will be seen as a lexing error. I.e. bothEND
andSCENARIO
will likely be parsed asID
terminal tokens instead of keywords. This in turn will lead to a very difficult to understand parser error, as the parser only seesID ID
instead of the expectedEND SCENARIO
.On the other hand, there's a more user friendly way to deal with this issue. Obviously, …