mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
[formatter/textregions] make sure the root has a proper grammar element
Even though the root has been created via an {Action}, the grammar element should be the root parser rule. Signed-off-by: Moritz Eysholdt <moritz.eysholdt@typefox.io>
This commit is contained in:
parent
29ddc6b881
commit
173450d637
3 changed files with 27 additions and 2 deletions
|
@ -191,7 +191,10 @@ public class NodeModelBasedRegionAccessBuilder {
|
|||
if (tokens.getSemanticElement() == null) {
|
||||
if (node.getParent() == null) {
|
||||
tokens.setSemantcElement(resource.getContents().get(0));
|
||||
tokens.setGrammarElement(node.getGrammarElement());
|
||||
EObject element = node.getGrammarElement();
|
||||
if (element instanceof Action)
|
||||
element = ((ICompositeNode) node).getFirstChild().getGrammarElement();
|
||||
tokens.setGrammarElement(element);
|
||||
} else if (node.hasDirectSemanticElement()) {
|
||||
tokens.setSemantcElement(node.getSemanticElement());
|
||||
tokens.setGrammarElement(findGrammarElement(node, tokens.getSemanticElement()));
|
||||
|
|
|
@ -615,6 +615,28 @@ class RegionAccessBuilderTest {
|
|||
31 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
@Test def void testMixedRootAction() {
|
||||
'''
|
||||
7 action (foo)
|
||||
'''.toString.trim === '''
|
||||
0 0 H
|
||||
B RootAction Root
|
||||
0 1 S "7" Root:'7'
|
||||
1 1 H " " Whitespace:TerminalRule'WS'
|
||||
2 6 S "action" Root:'action'
|
||||
8 1 H " " Whitespace:TerminalRule'WS'
|
||||
B Mixed'foo' Root:mixed=Mixed path:RootAction/mixed
|
||||
9 1 S "(" Mixed:'('
|
||||
10 0 H
|
||||
10 3 S "foo" Mixed:name=ID
|
||||
13 0 H
|
||||
13 1 S ")" Mixed:')'
|
||||
E Mixed'foo' Root:mixed=Mixed path:RootAction/mixed
|
||||
E RootAction Root
|
||||
14 0 H
|
||||
'''
|
||||
}
|
||||
|
||||
private def ===(CharSequence file, CharSequence expectation) {
|
||||
val exp = expectation.toString
|
||||
|
|
|
@ -12,7 +12,7 @@ with org.eclipse.xtext.common.Terminals
|
|||
generate regionaccesstestlanguage "http://formatter2/regionaccesstestlanguage"
|
||||
|
||||
Root:
|
||||
Simple | Delegation | Unassigned | PrefixedUnassigned | "5" Expression | "6" Mixed | "7" mixed=Mixed;
|
||||
Simple | Delegation | Unassigned | PrefixedUnassigned | "5" Expression | "6" Mixed | "7" ({RootAction} "action")? mixed=Mixed;
|
||||
|
||||
Simple:
|
||||
"1" name=ID;
|
||||
|
|
Loading…
Reference in a new issue