Blank *not* being hidden (ignored) despite rules demanding it [message #1771312] |
Wed, 23 August 2017 17:59  |
Eclipse User |
|
|
|
Hi,
I have run into a weird situation.
Despite the lines:
grammar org.instrumenteddreams.lang.Sable hidden(WS, ML_COMMENT, SL_COMMENT)
...
terminal WS: (' ' | '\u000A' | '\u000D' | '\u0009' | '\u000B' | '\u000C' | '\u0000')+;
I am having errors when attempting to parse the following line:
The leading whitespaces are (correctly) ignored, but the whitespace after the let word is not, and it is causing the following error:
java.lang.AssertionError: [XtextSyntaxDiagnostic: null:1 no viable alternative at input' ']
I've tried the following:
- Specify the hidden tokens explicitely at a rule-level
- Delete and re-generate the parser
but none of that worked.
Am I missing anything?
Thanks.
[Updated on: Wed, 23 August 2017 18:02] by Moderator
|
|
|
|
|
Re: Blank *not* being hidden (ignored) despite rules demanding it [message #1771391 is a reply to message #1771386] |
Thu, 24 August 2017 11:39   |
Eclipse User |
|
|
|
OK, I've found the problem by reducing the use cases to a minimum.
The following grammar ilustrates my mistake:
grammar org.instrumenteddreams.lang.Sable hidden(WS, ML_COMMENT, SL_COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate sable "http://www.instrumenteddreams.org/lang/Sable"
Sable hidden(WS, ML_COMMENT, SL_COMMENT):
source+=Statement*;
Statement hidden(WS, ML_COMMENT, SL_COMMENT):
((Declaration)) =>(';'?);
Declaration hidden(WS, ML_COMMENT, SL_COMMENT):
ConstantOrVariableDeclaration;
ConstantOrVariableDeclaration hidden(WS, ML_COMMENT, SL_COMMENT):
(ConstantDeclaration);
ConstantDeclaration hidden(WS, ML_COMMENT, SL_COMMENT):
KEYWORD_LET IDENTIFIER '=' LITERAL_DECIMAL;
terminal fragment DECIMAL_DIGIT: '0'..'9';
terminal fragment IDENTIFIER_HEAD:
('a'..'z') | ('A'..'Z') |
'_' |
'\u00A8' | '\u00AA' | '\u00AD' | '\u00AF' | ('\u00B2'..'\u00B5') | ('\u00B7'..'\u00BA') |
('\u00BC'..'\u00BE') | ('\u00C0'..'\u00D6') | ('\u00D8'..'\u00F6') | ('\u00F8'..'\u00FF') |
('\u0100'..'\u02FF') | ('\u0370'..'\u167F') | ('\u1681'..'\u180D') | ('\u180F'..'\u1DBF') |
('\u1E00'..'\u1FFF') |
('\u200B'..'\u200D') | ('\u202A'..'\u202E') | ('\u203F'..'\u2040') | '\u2054' | ('\u2060'..'\u206F') |
('\u2070'..'\u20CF') | ('\u2100'..'\u218F') | ('\u2460'..'\u24FF') | ('\u2776'..'\u2793') |
('\u2C00'..'\u2DFF') | ('\u2E80'..'\u2FFF') |
('\u3004'..'\u3007') | ('\u3021'..'\u302F') | ('\u3031'..'\u303F') | ('\u3040'..'\uD7FF') |
('\uF900'..'\uFD3D') | ('\uFD40'..'\uFDCF') | ('\uFDF0'..'\uFE1F') | ('\uFE30'..'\uFE44') |
('\uFE47'..'\uFFFD');
terminal fragment IDENTIFIER_CHARACTER:
DECIMAL_DIGIT |
('\u0300'..'\u036F') | ('\u1DC0'..'\u1DFF') | ('\u20D0'..'\u20FF') | ('\uFE20'..'\uFE2F') |
IDENTIFIER_HEAD;
terminal fragment IMPLICIT_PARAMETER_NAME: '$' DECIMAL_DIGIT+;
terminal fragment DECIMAL_LITERAL_CHARACTER: DECIMAL_DIGIT | '_';
terminal fragment DECIMAL_LITERAL_CHARACTERS: DECIMAL_LITERAL_CHARACTER+;
terminal LITERAL_DECIMAL: DECIMAL_DIGIT DECIMAL_LITERAL_CHARACTERS?;
terminal KEYWORD_LET: 'let';
terminal CHAR_FROM_U000E_TO_UUU21: ('\u000E'..'\u0021');
terminal IDENTIFIER:
(IDENTIFIER_HEAD IDENTIFIER_CHARACTER*) |
('`'(IDENTIFIER_HEAD IDENTIFIER_CHARACTER*)'`') |
IMPLICIT_PARAMETER_NAME;
terminal ML_COMMENT: '/*' -> '*/';
terminal SL_COMMENT: '//' !('\n'|'\r')* ('\r'? '\n')?;
terminal WS: (' ' | '\u000A' | '\u000D' | '\u0009' | '\u000B' | '\u000C' | '\u0000')+;
The problem is with the line:
terminal CHAR_FROM_U000E_TO_UUU21: ('\u000E'..'\u0021');
Because it defines as a terminal blanks (the u+20 character). But blanks are also told to be hidden by the grammar, as seen above in diverse hidden clauses.
So it's my fault that I've specified inconsistent treatment of blanks.
Thanks for your help anyway!
[Updated on: Thu, 24 August 2017 11:41] by Moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04079 seconds