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

View File

@ -89,8 +89,13 @@ class PorkLexer : LexerBase() {
PorkTokenTypes.Number PorkTokenTypes.Number
token.type == TokenType.Whitespace -> token.type == TokenType.Whitespace ->
PorkTokenTypes.Whitespace PorkTokenTypes.Whitespace
token.type == TokenType.BlockComment ->
PorkTokenTypes.BlockComment
token.type == TokenType.LineComment ->
PorkTokenTypes.LineComment
else -> PsiTokenType.CODE_FRAGMENT 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", "PORK.NUMBER",
DefaultLanguageHighlighterColors.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 else -> null
} }
return if (attributes == null) return if (attributes == null)

View File

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