Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using AbstractDeclarativeFormatter(AbstractDeclarativeFormatter is being called, but it has no effect)
Using AbstractDeclarativeFormatter [message #1397599] Wed, 09 July 2014 23:57 Go to next message
Nicolas Diaz Aragon is currently offline Nicolas Diaz AragonFriend
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 Smile 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 Smile

This is what I'm doing with the formatter:

import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter
import org.eclipse.xtext.formatting.impl.FormattingConfig
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)

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:
'tell' context=SelectorExpression
	actions+= (Action | Assertion | Step)*
'tell' context=Selector
	 actions+= (Action | Assertion | Step)*
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: '/' !('\\/'|'/')+ '/';
Re: Using AbstractDeclarativeFormatter [message #1398081 is a reply to message #1397599] Thu, 10 July 2014 15:29 Go to previous messageGo to next message
Thomas Fritsch is currently offline Thomas FritschFriend
Messages: 28
Registered: April 2013
Location: Germany
Junior Member
What did you mean by "... I try to format my language" ?
You need to type Ctrl+Shift+F in the editor, or right-mouse-click and select "Format".
The formatter should be triggered then.
Re: Using AbstractDeclarativeFormatter [message #1399838 is a reply to message #1398081] Sun, 13 July 2014 08:14 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 248
Registered: June 2013
Senior Member
Right now, I am experimenting with proposal providers etc.

Sometimes, after a modification of code, my ContentAssist does not show up.
In most of the cases is some NULL which blocks the processing and XTEND resfuses to work.

So if your text is not formatted at all, maybe there is a NULL in your formatter.
Previous Topic:how to use logging
Next Topic:Xtext resource in MWE2
Goto Forum:

Current Time: Mon Aug 03 12:51:05 GMT 2020

Powered by FUDForum. Page generated in 0.01737 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top