[61] | 1 | /* |
---|
| 2 | * generated by Xtext |
---|
| 3 | */
|
---|
| 4 | package de.ugoe.cs.swe.bnftools.formatting
|
---|
| 5 |
|
---|
| 6 | import com.google.inject.Inject
|
---|
| 7 | import de.ugoe.cs.swe.bnftools.services.EbnfGrammarAccess
|
---|
| 8 | import org.eclipse.xtext.Keyword
|
---|
| 9 | import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter
|
---|
| 10 | import org.eclipse.xtext.formatting.impl.FormattingConfig
|
---|
[65] | 11 | import org.eclipse.emf.ecore.EObject
|
---|
| 12 | import de.ugoe.cs.swe.bnftools.ebnf.Rule
|
---|
| 13 | import de.ugoe.cs.swe.bnftools.ebnf.DefinitionList
|
---|
[61] | 14 |
|
---|
| 15 | /** |
---|
| 16 | * This class contains custom formatting description. |
---|
| 17 | * |
---|
| 18 | * see : http://www.eclipse.org/Xtext/documentation.html#formatting |
---|
| 19 | * on how and when to use it |
---|
| 20 | * |
---|
| 21 | * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example |
---|
| 22 | */
|
---|
| 23 | class EbnfFormatter extends AbstractDeclarativeFormatter {
|
---|
| 24 |
|
---|
| 25 | @Inject extension EbnfGrammarAccess
|
---|
| 26 |
|
---|
| 27 | override protected void configureFormatting(FormattingConfig c) {
|
---|
[65] | 28 |
|
---|
[61] | 29 | // They will add and preserve newlines around comments |
---|
| 30 | c.setLinewrap(0, 1, 2).before(SL_COMMENTRule)
|
---|
| 31 | c.setLinewrap(0, 1, 2).before(ML_COMMENTRule)
|
---|
| 32 | c.setLinewrap(0, 1, 1).after(ML_COMMENTRule)
|
---|
[65] | 33 |
|
---|
[61] | 34 | var EbnfGrammarAccess f = getGrammarAccess as EbnfGrammarAccess;
|
---|
| 35 | c.setLinewrap.before(f.ruleRule);
|
---|
[65] | 36 | c.setLinewrap.before(f.importRule);
|
---|
[63] | 37 | c.setNoSpace.after(f.ruleAccess.rulenumberINTTerminalRuleCall_0_0_0)
|
---|
[65] | 38 |
|
---|
| 39 | |
---|
| 40 | // for (Keyword bar : f.findKeywords("|")) {
|
---|
| 41 | //
|
---|
[61] | 42 | // c.setSpace("\n\t\t").before(bar);
|
---|
[65] | 43 | // }
|
---|
[61] | 44 |
|
---|
| 45 | }
|
---|
| 46 | }
|
---|