|
|
|
|
Re: missing RULE_BEGIN if using whitespace-aware [message #1707410 is a reply to message #1707407] |
Fri, 04 September 2015 14:42 |
Peter Vanusanik Messages: 7 Registered: June 2015 |
Junior Member |
|
|
Christian Dietrich wrote on Fri, 04 September 2015 14:11(the problematic point is org.eclipse.xtext.parser.antlr.AbstractIndentationTokenSource.computeIndentation(String)
protected int computeIndentation(String text) {
int result = 0;
for(int i = text.length() - 1; i>=0; i--) {
char c = text.charAt(i);
if (c == '\n' || c == '\r') {
return result;
}
if (c == '\t') {
result+=getTabWidth();
} else {
result++;
}
}
return -1;
}
Is what I have in that class.
Is that a bug in the xtext? If so, can I fix it and inject the correct one?
[Updated on: Fri, 04 September 2015 14:46] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: missing RULE_BEGIN if using whitespace-aware [message #1707444 is a reply to message #1707442] |
Fri, 04 September 2015 18:11 |
|
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=TMF&component=Xtext
the following works for me ?!?
grammar org.xtext.example.mydsl3.MyDsl hidden (WS, SL_COMMENT)
generate myDsl "http://www.xtext.org/example/mydsl3/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
file_input:
{file_input}
( los+=stmt )*
;
if_stmt:
'if' tests+=test ':' suite+=suite
;
test:
value="true" | value="false"
;
suite:
simple_stmt=suiteblock
;
suiteblock:
BEGIN
stmts+=stmt+
END
;
stmt:
print_stmt | if_stmt
;
print_stmt:
PRINT vlaue=STRING
;
terminal BEGIN: 'synthetic:BEGIN';
terminal END: 'synthetic:END';
terminal PRINT: 'print';
terminal STRING:
'"' ( '\\' . /* ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') */ | !('\\'|'"') )* '"'? |
"'" ( '\\' . /* ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') */ | !('\\'|"'") )* "'"? |
'"""' -> '"""'?;
terminal SL_COMMENT: '#' !('\n'|'\r')* ('\r'? '\n')?;
terminal WS: ('\r'|'\n'|'\t'|' ')+;
if true:
print "x"
print "x"
print "y"
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: missing RULE_BEGIN if using whitespace-aware [message #1707447 is a reply to message #1707444] |
Fri, 04 September 2015 18:34 |
Peter Vanusanik Messages: 7 Registered: June 2015 |
Junior Member |
|
|
Christian Dietrich wrote on Fri, 04 September 2015 18:11https://bugs.eclipse.org/bugs/enter_bug.cgi?product=TMF&component=Xtext
the following works for me ?!?
grammar org.xtext.example.mydsl3.MyDsl hidden (WS, SL_COMMENT)
generate myDsl "http://www.xtext.org/example/mydsl3/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
file_input:
{file_input}
( los+=stmt )*
;
if_stmt:
'if' tests+=test ':' suite+=suite
;
test:
value="true" | value="false"
;
suite:
simple_stmt=suiteblock
;
suiteblock:
BEGIN
stmts+=stmt+
END
;
stmt:
print_stmt | if_stmt
;
print_stmt:
PRINT vlaue=STRING
;
terminal BEGIN: 'synthetic:BEGIN';
terminal END: 'synthetic:END';
terminal PRINT: 'print';
terminal STRING:
'"' ( '\\' . /* ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') */ | !('\\'|'"') )* '"'? |
"'" ( '\\' . /* ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') */ | !('\\'|"'") )* "'"? |
'"""' -> '"""'?;
terminal SL_COMMENT: '#' !('\n'|'\r')* ('\r'? '\n')?;
terminal WS: ('\r'|'\n'|'\t'|' ')+;
if true:
print "x"
print "x"
print "y"
There are other problematic parts where new line is required. For instance empty lines at module level throw error right now. Also, for instance decorators require new line
[Updated on: Fri, 04 September 2015 19:07] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02998 seconds