Using AbstractDeclarativeFormatter [message #1397599] |
Wed, 09 July 2014 23:57 |
Nicolas Diaz Aragon Messages: 1 Registered: July 2014 |
Junior Member |
|
|
Hello everyone,
I'm trying to get the IDE to format my DSL, but in spite of the configureFormatting method being called, nothing is happening on the editor window. All text remains the same I was hoping you could point me in the right direction to get the formatter to work!
I'm a newbie on using XText. I just wrote my 1st grammar definition and I'm using validators and the generator to compile my language into javascript. It's amazing! But I haven't been able to get the AbstractDeclarativeFormatter to format my language
This is what I'm doing with the formatter:
import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter
import org.eclipse.xtext.formatting.impl.FormattingConfig
import com.google.inject.Inject;
import com.devfactory.services.KeyStoneGrammarAccess
class KeyStoneFormatter extends AbstractDeclarativeFormatter {
@Inject extension KeyStoneGrammarAccess
override protected void configureFormatting(FormattingConfig c) {
c.setIndentation(getStepAccess.tellKeyword_1, getStepAccess.endKeyword_4)
c.setIndentation(getRootStepAccess.tellKeyword_2, getRootStepAccess.endKeyword_5)
c.setLinewrap(1,1,2).after(getStepRule)
c.setLinewrap(1,1,2).after(getRootStepRule)
}
}
My grammar is rather "simple" and I've tried all sorts of combinations to get the above to work, but it has been to no avail. The "configureFormatting" method is indeed being triggered, it just has no effect when I try to format my language.
This is my grammar:
grammar com.devfactory.KeyStone hidden(WHITESPACE, NEWLINE, SL_COMMENT)
import ".. ecore url goes here.." as ecore
generate keyStone ".. another url goes here .."
ExpressionStatement: (expression+=RootStep)+;
Expression: SelectorExpression|Literal;
RootStep returns Step:
{RootStep}folderName=SINGLELINE?
'tell' context=SelectorExpression
actions+= (Action | Assertion | Step)*
'end';
Step:
folderName=SINGLELINE?
'tell' context=Selector
actions+= (Action | Assertion | Step)*
'end';
Selector returns Expression: SelectorExpression | SearchSettings;
SearchSettings returns Expression: {SearchSettings}op='['properties+=Identifier expected+=Expression (','properties+=Identifier expected+=Expression)*']'('->'depth=NumberLiteral)?(':'index=NumberLiteral);
Action: (name=('click'|'right click'|'middle click'|'double click'|'hover') (actionParams=MouseActionParams)?)
| (name='type' actionParams=KeyboardActionParams)
| (name='wait' 'for' actionParams=WaitActionParams)
| (name='pause' 'for' actionParams=PauseActionParams)
| (name='drag' 'to' actionParams=DragActionParams)
| (name='open' 'browser' actionParams=OpenBrowserActionParams)
| (name='browse' 'to' actionParams=BrowseToActionParams)
| (name=('close'|'terminate'|'maximize'|'run'))
;
BrowseToActionParams: url=Expression;
OpenBrowserActionParams: browserName=('InternetExplorer'|'Firefox'|'Chrome'|'Opera'|'Safari');
DragActionParams: (x=NUMBER y=NUMBER) | (target=Expression (x=NUMBER y=NUMBER)?);
PauseActionParams: timePaused=NUMBER;
WaitActionParams: ('property' propertyName=Expression)? expectedValue=Expression delayTime=NUMBER;
MouseActionParams: (x=NUMBER y=NUMBER (chord=KeyboardChord)?);
KeyboardActionParams: text=STRING;
KeyboardChord: keys+=MetaKey (('and') keys+=MetaKey)*;
MetaKey: 'shift'| 'alt'| 'ctrl'| 'none';
Assertion: 'assert' filter=FilterExpression;
FilterExpression returns KeyValuePair: KeyValuePair =>({KeyValuePair.left=current} 'and' right=FilterExpression)*;
KeyValuePair: {KeyValuePair} property=Expression (valueIsRegex?='regex')? value=Expression;
SelectorExpression returns Expression: MemberExpression ({Expression.left=current} op='of' right=MemberExpression)*;
MemberExpression returns Expression: CallExpression =>({Expression.left=current} op='.' right=CallExpression)*;
CallExpression returns Expression: Identifier =>({Expression.left=current} op='(' (arguments+=Expression)?(','arguments+=Expression)* ')')*;
Identifier returns Expression: {Identifier}value=ID;
Literal returns Expression: {BooleanLiteral}value=BOOL | {NumberLiteral}value=NUMBER | {StringLiteral}value=STRING | {RegularExpression}value=REGULAR_EXPRESSION;
BooleanLiteral returns Expression: value=BOOL;
NumberLiteral returns Expression: value=NUMBER;
StringLiteral returns Expression: value=STRING;
RegularExpression returns Expression: value=REGULAR_EXPRESSION;
terminal BOOL: 'true'|'false';
terminal NUMBER: ('0'..'9')+ ('.' ('0'..'9')*)?;
terminal STRING: ('"'->'"') | ("'"->"'");
terminal ID: (('a'..'z')|('A'..'Z')|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal WHITESPACE: (' '|'\t')+;
terminal NEWLINE: ('\r' | '\n')+;
terminal SINGLELINE returns ecore::EString: '#' !('\n'|'\r')* ('\r'? '\n')?;
terminal SL_COMMENT: '//' !('\n'|'\r')* ('\r'? '\n')?;
terminal REGULAR_EXPRESSION: '/' !('\\/'|'/')+ '/';
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01667 seconds