idea: comment highlighting support

This commit is contained in:
Alex Zenla 2023-09-10 22:07:38 -04:00
parent 1be098d1c9
commit f6d2fc5165
Signed by: alex
GPG Key ID: C0780728420EBFE5
4 changed files with 24 additions and 7 deletions

View File

@ -19,7 +19,7 @@ class AstCodegen(val pkg: String, val outputDirectory: Path, val world: AstWorld
writeAstType(type)
}
writeNodeType()
writeNodeVisitor()
writeNodeVisitors()
writeNodeCoalescer()
}
@ -45,8 +45,8 @@ class AstCodegen(val pkg: String, val outputDirectory: Path, val world: AstWorld
write("NodeType.kt", KotlinWriter(enumClass))
}
private fun writeNodeVisitor() {
val visitorInterface = KotlinClass(
private fun writeNodeVisitors() {
val nodeVisitorInterface = KotlinClass(
pkg,
"NodeVisitor",
typeParameters = mutableListOf("T"),
@ -60,7 +60,7 @@ class AstCodegen(val pkg: String, val outputDirectory: Path, val world: AstWorld
continue
}
val visitFunction = KotlinFunction(
val nodeVisitFunction = KotlinFunction(
"visit${type.name}",
returnType = "T",
parameters = mutableListOf(
@ -68,9 +68,9 @@ class AstCodegen(val pkg: String, val outputDirectory: Path, val world: AstWorld
),
isInterfaceMethod = true
)
visitorInterface.functions.add(visitFunction)
nodeVisitorInterface.functions.add(nodeVisitFunction)
}
write("NodeVisitor.kt", KotlinWriter(visitorInterface))
write("NodeVisitor.kt", KotlinWriter(nodeVisitorInterface))
val visitorExtensionSet = KotlinFunctionSet(pkg)
val visitAnyFunction = KotlinFunction(

View File

@ -89,8 +89,13 @@ class PorkLexer : LexerBase() {
PorkTokenTypes.Number
token.type == TokenType.Whitespace ->
PorkTokenTypes.Whitespace
token.type == TokenType.BlockComment ->
PorkTokenTypes.BlockComment
token.type == TokenType.LineComment ->
PorkTokenTypes.LineComment
else -> PsiTokenType.CODE_FRAGMENT
}
override fun toString(): String = "Lexer(start=$internalTokenStart, end=$internalTokenEnd)"
override fun toString(): String =
"PorkLexer(start=$internalTokenStart, end=$internalTokenEnd)"
}

View File

@ -40,6 +40,16 @@ object PorkSyntaxHighlighter : SyntaxHighlighter {
"PORK.NUMBER",
DefaultLanguageHighlighterColors.NUMBER
)
PorkTokenTypes.BlockComment ->
TextAttributesKey.createTextAttributesKey(
"PORK.COMMENT.BLOCK",
DefaultLanguageHighlighterColors.BLOCK_COMMENT
)
PorkTokenTypes.LineComment ->
TextAttributesKey.createTextAttributesKey(
"PORK.COMMENT.LINE",
DefaultLanguageHighlighterColors.LINE_COMMENT
)
else -> null
}
return if (attributes == null)

View File

@ -10,4 +10,6 @@ object PorkTokenTypes {
val Operator = IElementType("operator", PorkLanguage)
val String = IElementType("string", PorkLanguage)
val Number = IElementType("number", PorkLanguage)
val BlockComment = IElementType("lineComment", PorkLanguage)
val LineComment = IElementType("blockComment", PorkLanguage)
}