Skip to content

Commit 7e8c4c7

Browse files
authored
Merge pull request #64 from sharwell/channels
Fix channels-related bugs
2 parents ffa8fb2 + 32ab16f commit 7e8c4c7

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

org-antlr-works-editor/src/org/antlr/works/editor/grammar/codemodel/impl/ChannelModelImpl.java

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.antlr.v4.runtime.ParserRuleContext;
1515
import org.antlr.v4.runtime.tree.TerminalNode;
1616
import org.antlr.works.editor.grammar.codemodel.ChannelModel;
17+
import org.antlr.works.editor.grammar.codemodel.CodeElementPositionRegion;
1718

1819
/**
1920
*
@@ -33,4 +34,22 @@ public ChannelModelImpl(String name, FileModelImpl file, TerminalNode seek, Pars
3334
public Collection<? extends AbstractCodeElementModel> getMembers() {
3435
return Collections.emptyList();
3536
}
37+
38+
@Override
39+
public CodeElementPositionRegion getSeek() {
40+
if (this.seek == null) {
41+
return super.getSeek();
42+
}
43+
44+
return new CodeElementPositionRegionImpl(this, seek);
45+
}
46+
47+
@Override
48+
public CodeElementPositionRegion getSpan() {
49+
if (this.span == null) {
50+
return super.getSpan();
51+
}
52+
53+
return new CodeElementPositionRegionImpl(this, span);
54+
}
3655
}

org-antlr-works-editor/src/org/antlr/works/editor/grammar/formatting/GrammarIndentTask.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,10 @@ public Tuple2<? extends ParseTree, Integer> visitTokensSpec(TokensSpecContext ct
731731
return Tuple.create(ctx, 0);
732732
}
733733

734-
// align to the previous element
735-
for (int i = priorSiblings.size() - 2; i >= 0; i--) {
734+
// align to the previous element; stop at the first id rule, index 0 is the TOKENS terminal itself
735+
for (int i = priorSiblings.size() - 2; i >= 1; i--) {
736736
ParseTree sibling = priorSiblings.get(i);
737-
// stop at the first id rule, index 0 is the TOKENS terminal itself
738-
if (i == 1 || ParseTrees.elementStartsLine(sibling)) {
737+
if (ParseTrees.elementStartsLine(sibling)) {
739738
return Tuple.create(sibling, 0);
740739
}
741740
}
@@ -754,11 +753,10 @@ public Tuple2<? extends ParseTree, Integer> visitChannelsSpec(ChannelsSpecContex
754753
return Tuple.create(ctx, 0);
755754
}
756755

757-
// align to the previous element
758-
for (int i = priorSiblings.size() - 2; i >= 0; i--) {
756+
// align to the previous element; stop at the first id rule, index 0 is the CHANNELS terminal itself
757+
for (int i = priorSiblings.size() - 2; i >= 1; i--) {
759758
ParseTree sibling = priorSiblings.get(i);
760-
// stop at the first id rule, index 0 is the CHANNELS terminal itself
761-
if (i == 1 || ParseTrees.elementStartsLine(sibling)) {
759+
if (ParseTrees.elementStartsLine(sibling)) {
762760
return Tuple.create(sibling, 0);
763761
}
764762
}

0 commit comments

Comments
 (0)