Formatting Multiple Consecutive Keywords [message #1770581] |
Mon, 14 August 2017 11:57  |
Eclipse User |
|
|
|
I've been following the itemis blog post showing how to provide content assist for multiple consecutive keywords and I am having difficulty figuring out how to format those keywords. Using the domainmodel example from the blog post, I created a simple file with extra spaces between the consecutive keywords:
entity Foo {
is composed of Foo
}
I would like to be able to do something like this in the formatter:
def dispatch void format(Relation relation, extension IFormattableDocument document) {
relation.regionFor.keyword("composed").surround[oneSpace]
}
This doesn't work because the call to keyword("composed") returns null. I printed the textRegionAccess and this is the result:
Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement
Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion
0 0 H
B DomainModel DomainModel
B Entity'Foo' DomainModel:elements+=AbstractElement path:DomainModel/elements[0]
0 6 S "entity" Entity:'entity'
6 1 H " " Whitespace:TerminalRule'WS'
7 3 S "Foo" Entity:name=ValidID
10 1 H " " Whitespace:TerminalRule'WS'
11 1 S "{" Entity:'{'
12 2 H "\n\t" Whitespace:TerminalRule'WS'
B Relation Entity:relations+=Relation path:Entity'Foo'/relations[0]=DomainModel/elements[0]
14 23 S "is compose..." Relation:IsComposedOf
37 1 H " " Whitespace:TerminalRule'WS'
38 3 S "Foo" Relation:referencedEntity=[Entity|ID]
E Relation Entity:relations+=Relation path:Entity'Foo'/relations[0]=DomainModel/elements[0]
41 1 H "\n" Whitespace:TerminalRule'WS'
42 1 S "}" Entity:'}'
E Entity'Foo' DomainModel:elements+=AbstractElement path:DomainModel/elements[0]
E DomainModel DomainModel
43 1 H "\n" Whitespace:TerminalRule'WS'
As you can see, is composed of is one semantic region with no hidden regions between the keywords. For reference, here are the grammar rules of interest:
Relation:
(DependsOn | IsComposedOf) referencedEntity=[Entity]
;
DependsOn:
'depends' 'on'
;
IsComposedOf:
'is' 'composed' 'of'
;
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04291 seconds