-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLyingTreeConverter.java
47 lines (41 loc) · 1.88 KB
/
LyingTreeConverter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package polyfauna.intellihask.parser;
import com.intellij.lang.Language;
import com.intellij.lang.PsiBuilder;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import polyfauna.intellihask.antlr_generated.HaskellLexer;
import org.antlr.intellij.adaptor.parser.ANTLRParseTreeToPSIConverter;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.tree.TerminalNode;
import polyfauna.intellihask.psi.Tokens;
public class LyingTreeConverter extends ANTLRParseTreeToPSIConverter{
public LyingTreeConverter(Language language, Parser parser, PsiBuilder builder){
super(language, parser, builder);
}
public void visitTerminal(TerminalNode node){
int type = node.getSymbol().getType();
if(type != HaskellLexer.SEMI && type != HaskellLexer.VCCURLY && type != HaskellLexer.VOCURLY)
super.visitTerminal(node);
}
public void enterEveryRule(ParserRuleContext ctx){
ProgressIndicatorProvider.checkCanceled();
if(Tokens.INLINED_RULES.contains(ctx.getRuleIndex()))
return;
markers.push(getBuilder().mark());
}
public void exitEveryRule(ParserRuleContext ctx){
ProgressIndicatorProvider.checkCanceled();
if(Tokens.INLINED_RULES.contains(ctx.getRuleIndex()))
return; // TODO: handle errors created directly inside inlined rules
PsiBuilder.Marker marker = markers.pop();
// if the rule has an error and no children, then an error node was not properly created
// have to do it ourselves...
RecognitionException e = ctx.exception;
if(ctx.getChildCount() == 0 && e != null){
// simplified from DefaultErrorStrategy::reportInputMismatch
marker.error("mismatched input %s expecting %s".formatted(e.getOffendingToken().getText(), e.getExpectedTokens().toString(e.getRecognizer().getVocabulary())));
}else
marker.done(getRuleElementTypes().get(ctx.getRuleIndex()));
}
}