/*******************************************************************************
* Copyright (c) 2013 AKSW Xturtle Project, itemis AG (http://www.itemis.eu).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
/*
* generated by Xtext
*/
package de.itemis.tooling.xturtle.formatting;
import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter;
import org.eclipse.xtext.formatting.impl.FormattingConfig;
import com.google.inject.Inject;
import de.itemis.tooling.xturtle.services.XturtleGrammarAccess;
/**
* This class contains custom formatting description.
*
* see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#formatting
* on how and when to use it
*
* Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
*/
public class XturtleFormatter extends AbstractDeclarativeFormatter {
@Inject
XturtleGrammarAccess grammarAccess;
//formatting is extremely problematic as white spaces are significant as separators...
//use completely separate formatter? try rewriting the grammar? I woudn't like to
//use my own lexer
@Override
protected void configureFormatting(FormattingConfig c) {
c.setAutoLinewrap(200);
c.setLinewrap(0, 1, 2).before(grammarAccess.getSL_COMMENTRule());
//line wrap between direcives
c.setLinewrap(1).between(grammarAccess.getDirectiveAccess().getTRIPELENDTerminalRuleCall_1(),grammarAccess.getPrefixIdAccess().getPrefixKeyword_0());
c.setLinewrap(1).between(grammarAccess.getDirectiveAccess().getTRIPELENDTerminalRuleCall_1(),grammarAccess.getBaseAccess().getBaseKeyword_0());
//spaces in prefix definition
c.setNoSpace().around(grammarAccess.getPrefixIdAccess().getColonKeyword_1_1());
// c.setSpace(" ").after(grammarAccess.getPrefixKeywordRule());
//line wraps between directive and triple
c.setLinewrap(2).between(grammarAccess.getDirectiveAccess().getTRIPELENDTerminalRuleCall_1(),grammarAccess.getUriDefRule());
c.setLinewrap(2).between(grammarAccess.getDirectiveAccess().getTRIPELENDTerminalRuleCall_1(),grammarAccess.getQNameDefRule());
//linw wraps between triple and directive
c.setLinewrap(2).between(grammarAccess.getTriplesAccess().getTRIPELENDTerminalRuleCall_2(),grammarAccess.getPrefixIdAccess().getPrefixKeyword_0());
c.setLinewrap(2).between(grammarAccess.getTriplesAccess().getTRIPELENDTerminalRuleCall_2(),grammarAccess.getBaseAccess().getBaseKeyword_0());
//line wraps between triples
c.setLinewrap(1,2,2).between(grammarAccess.getTriplesAccess().getTRIPELENDTerminalRuleCall_2(),grammarAccess.getUriDefRule());
c.setLinewrap(1,2,2).between(grammarAccess.getTriplesAccess().getTRIPELENDTerminalRuleCall_2(),grammarAccess.getQNameDefRule());
//line wraps in predicate object list of triple
c.setLinewrap(0,0,1).after(grammarAccess.getQNameDefRule());
c.setLinewrap(0,0,1).after(grammarAccess.getUriDefRule());
c.setIndentationIncrement().after(grammarAccess.getQNameDefRule());
c.setIndentationIncrement().after(grammarAccess.getUriDefRule());
c.setIndentationDecrement().after(grammarAccess.getTriplesAccess().getTRIPELENDTerminalRuleCall_2());
c.setLinewrap(1).before(grammarAccess.getTriplesAccess().getPredObjsAssignment_1_1_1());
//no space before , and ;
c.setNoSpace().before(grammarAccess.getTriplesAccess().getSemicolonKeyword_1_1_0_0());
c.setNoSpace().before(grammarAccess.getTriplesAccess().getSemicolonKeyword_1_2());
c.setNoSpace().before(grammarAccess.getBlankObjectsAccess().getSemicolonKeyword_2_1_0());
c.setNoSpace().before(grammarAccess.getBlankObjectsAccess().getSemicolonKeyword_2_2());
c.setNoSpace().before(grammarAccess.getPredicateObjectListAccess().getCommaKeyword_2_0());
//WS in QName
c.setNoSpace().between(grammarAccess.getQNameRefAccess().getPrefixAssignment_1(), grammarAccess.getQNameRefAccess().getRefAssignment_2());
c.setNoSpace().between(grammarAccess.getQNameDefAccess().getPrefixAssignment_1(), grammarAccess.getQNameDefAccess().getIdAssignment_2());
//WS in String literals
c.setNoSpace().around(grammarAccess.getStringLiteralAccess().getCircumflexAccentCircumflexAccentKeyword_1_0_0());
c.setNoSpace().before(grammarAccess.getStringLiteralAccess().getLanguageAssignment_1_1());
//blank objects
c.setNoSpace().between(grammarAccess.getBlankObjectsAccess().getLeftSquareBracketKeyword_0(), grammarAccess.getBlankObjectsAccess().getRightSquareBracketKeyword_3());
c.setIndentationIncrement().after(grammarAccess.getBlankObjectsAccess().getLeftSquareBracketKeyword_0());
c.setIndentationDecrement().before(grammarAccess.getBlankObjectsAccess().getRightSquareBracketKeyword_3());
c.setLinewrap(0,0,1).after(grammarAccess.getBlankObjectsAccess().getLeftSquareBracketKeyword_0());
c.setLinewrap(0,0,1).before(grammarAccess.getBlankObjectsAccess().getRightSquareBracketKeyword_3());
c.setLinewrap(0,1,1).after(grammarAccess.getBlankObjectsAccess().getSemicolonKeyword_2_1_0());
c.setLinewrap(0,1,1).after(grammarAccess.getBlankObjectsAccess().getSemicolonKeyword_2_2());
//blank objects
c.setNoSpace().between(grammarAccess.getBlankCollectionAccess().getLeftParenthesisKeyword_0(), grammarAccess.getBlankCollectionAccess().getRightParenthesisKeyword_3());
c.setIndentationIncrement().after(grammarAccess.getBlankCollectionAccess().getLeftParenthesisKeyword_0());
c.setIndentationDecrement().before(grammarAccess.getBlankCollectionAccess().getRightParenthesisKeyword_3());
c.setLinewrap(0,0,1).before(grammarAccess.getBlankCollectionAccess().getObjectsAssignment_2_0());
c.setLinewrap(0,0,1).before(grammarAccess.getBlankCollectionAccess().getObjectsAssignment_2_1());
c.setLinewrap(0,0,1).before(grammarAccess.getBlankCollectionAccess().getRightParenthesisKeyword_3());
}
}