Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Better fix for "syntax error highlighting quirks" (#2)
- Loading branch information
Showing
10 changed files
with
204 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
grammar Issue2; | ||
|
||
@header { | ||
package org.antlr.intellij.adaptor.issue2; | ||
} | ||
|
||
block | ||
: 'start' ID ';' | ||
usesList | ||
'end' ID ';' | ||
; | ||
|
||
usesList | ||
: 'uses' ID (',' ID)* ';' | ||
; | ||
|
||
ID: [a-zA-Z]+; | ||
WS: [\t\r\n ]+ -> skip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package issue2; | ||
|
||
import com.intellij.openapi.fileTypes.LanguageFileType; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
class Issue2FileType extends LanguageFileType { | ||
|
||
static Issue2FileType INSTANCE = new Issue2FileType(); | ||
|
||
private Issue2FileType() { | ||
super(Issue2Language.INSTANCE); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getName() { | ||
return "Issue 2"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getDescription() { | ||
return "Issue 2"; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getDefaultExtension() { | ||
return "ext"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Icon getIcon() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package issue2; | ||
|
||
import com.intellij.lang.Language; | ||
|
||
class Issue2Language extends Language { | ||
|
||
static Issue2Language INSTANCE = new Issue2Language(); | ||
|
||
private Issue2Language() { | ||
super("Issue2"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package issue2; | ||
|
||
import com.intellij.extapi.psi.PsiFileBase; | ||
import com.intellij.lang.ASTNode; | ||
import com.intellij.lang.ParserDefinition; | ||
import com.intellij.lang.PsiParser; | ||
import com.intellij.lexer.Lexer; | ||
import com.intellij.openapi.fileTypes.FileType; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.FileViewProvider; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.tree.IElementType; | ||
import com.intellij.psi.tree.IFileElementType; | ||
import com.intellij.psi.tree.TokenSet; | ||
import org.antlr.intellij.adaptor.issue2.Issue2Lexer; | ||
import org.antlr.intellij.adaptor.issue2.Issue2Parser; | ||
import org.antlr.intellij.adaptor.lexer.ANTLRLexerAdaptor; | ||
import org.antlr.intellij.adaptor.lexer.PSIElementTypeFactory; | ||
import org.antlr.intellij.adaptor.parser.ANTLRParserAdaptor; | ||
import org.antlr.intellij.adaptor.psi.ANTLRPsiNode; | ||
import org.antlr.v4.runtime.Parser; | ||
import org.antlr.v4.runtime.tree.ParseTree; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class Issue2ParserDefinition implements ParserDefinition { | ||
|
||
public Issue2ParserDefinition() { | ||
PSIElementTypeFactory.defineLanguageIElementTypes( | ||
Issue2Language.INSTANCE, | ||
Issue2Lexer.VOCABULARY, | ||
Issue2Parser.ruleNames | ||
); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Lexer createLexer(Project project) { | ||
return new ANTLRLexerAdaptor(Issue2Language.INSTANCE, new Issue2Lexer(null)); | ||
} | ||
|
||
@Override | ||
public PsiParser createParser(Project project) { | ||
return new ANTLRParserAdaptor(Issue2Language.INSTANCE, new Issue2Parser(null)) { | ||
@Override | ||
protected ParseTree parse(Parser parser, IElementType root) { | ||
return ((Issue2Parser) parser).block(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public IFileElementType getFileNodeType() { | ||
return new IFileElementType(Issue2Language.INSTANCE); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public TokenSet getCommentTokens() { | ||
return TokenSet.EMPTY; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public TokenSet getStringLiteralElements() { | ||
return TokenSet.EMPTY; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public PsiElement createElement(ASTNode node) { | ||
return new ANTLRPsiNode(node); | ||
} | ||
|
||
@Override | ||
public PsiFile createFile(FileViewProvider viewProvider) { | ||
return new PsiFileBase(viewProvider, Issue2Language.INSTANCE) { | ||
@NotNull | ||
@Override | ||
public FileType getFileType() { | ||
return Issue2FileType.INSTANCE; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package issue2; | ||
|
||
import com.intellij.testFramework.ParsingTestCase; | ||
|
||
public class Issue2ParserTest extends ParsingTestCase { | ||
|
||
public Issue2ParserTest() { | ||
super("issue2", "ext", true, new Issue2ParserDefinition()); | ||
} | ||
|
||
public void testIssue2() { | ||
doTest(true); | ||
} | ||
|
||
@Override | ||
protected String getTestDataPath() { | ||
return "src/test/resources/testData"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
start X; | ||
uses ducks | ||
end X; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FILE | ||
ANTLRPsiNode(block) | ||
PsiElement('start')('start ') | ||
PsiElement(ID)('X') | ||
PsiElement(';')(';\n ') | ||
ANTLRPsiNode(usesList) | ||
PsiElement('uses')('uses ') | ||
PsiElement(ID)('ducks\n') | ||
PsiErrorElement:mismatched input 'end ' expecting {';', ','} | ||
PsiElement('end')('end ') | ||
PsiElement(ID)('X') | ||
PsiElement(';')(';') |