Skip to content

Commit

Permalink
[ lang ] Update laji code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Apr 20, 2018
1 parent 2bed9db commit c5d03ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 18 additions & 12 deletions common/src/org/ice1000/devkt/lang/languages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,34 @@ import javax.swing.Icon
* @since v1.2
* @see Language
*/
abstract class DevKtLanguage<TextAttributes> internal constructor(
val language: Language
) : Annotator<TextAttributes>, SyntaxHighlighter<TextAttributes> {
interface DevKtLanguage<TextAttributes> : Annotator<TextAttributes>, SyntaxHighlighter<TextAttributes> {
val language: Language

/**
* Check if a file is of this language
* @param fileName String the file name
* @return Boolean is of this language or not
*/
open fun satisfies(fileName: String) = false
@JvmDefault
fun satisfies(fileName: String) = false

/**
* Line comment start, used when pressing <kbd>Ctrl</kbd> + <kbd>/</kbd>
*/
open val lineCommentStart: String? get() = null
@JvmDefault
val lineCommentStart: String? get() = null

/**
* Block comment surrounding, used when pressing
* <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>/</kbd>
*/
open val blockComment: Pair<String, String>? get() = null
@JvmDefault
val blockComment: Pair<String, String>? get() = null

open val icon: Icon get() = DevKtIcons.ANY
@JvmDefault
val icon: Icon get() = DevKtIcons.ANY

abstract fun createLexer(project: Project): Lexer
fun createLexer(project: Project): Lexer

/**
* Called when typing, before the typed character is inserted.
Expand All @@ -59,7 +62,8 @@ abstract class DevKtLanguage<TextAttributes> internal constructor(
* @see org.ice1000.devkt.ui.DevKtDocumentHandler.insertDirectly
* @see org.ice1000.devkt.ui.DevKtDocumentHandler.insert
*/
open fun handleTyping(
@JvmDefault
fun handleTyping(
offset: Int,
text: String?,
element: PsiElement?,
Expand All @@ -76,8 +80,8 @@ abstract class DevKtLanguage<TextAttributes> internal constructor(
sealed class BuiltinDevKtLanguage<TextAttributes>(
annotator: Annotator<TextAttributes>,
syntaxHighlighter: SyntaxHighlighter<TextAttributes>,
language: Language
) : DevKtLanguage<TextAttributes>(language),
override val language: Language
) : DevKtLanguage<TextAttributes>,
Annotator<TextAttributes> by annotator,
SyntaxHighlighter<TextAttributes> by syntaxHighlighter {
override fun satisfies(fileName: String) = false
Expand Down Expand Up @@ -140,11 +144,13 @@ class Kotlin<TextAttributes>(
class PlainText<TextAttributes>(
annotator: Annotator<TextAttributes>,
syntaxHighlighter: SyntaxHighlighter<TextAttributes>
) : DevKtLanguage<TextAttributes>(PlainTextLanguage.INSTANCE),
) : DevKtLanguage<TextAttributes>,
Annotator<TextAttributes> by annotator,
SyntaxHighlighter<TextAttributes> by syntaxHighlighter {
override val language: PlainTextLanguage = PlainTextLanguage.INSTANCE
override fun satisfies(fileName: String) =
fileName.endsWith(".txt") && !fileName.endsWith(".lua.txt") || '.' !in fileName

private val lexer = EmptyLexer()
override fun createLexer(project: Project) = lexer
}
4 changes: 2 additions & 2 deletions common/src/org/ice1000/devkt/openapi/languages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import javax.swing.Icon
* @since v1.2
*/
abstract class ExtendedDevKtLanguage<TextAttributes>(
language: Language,
override val language: Language,
val parserDefinition: ParserDefinition
) : DevKtLanguage<TextAttributes>(language) {
) : DevKtLanguage<TextAttributes> {
/**
* Creates a lexer for syntax highlight
*
Expand Down

0 comments on commit c5d03ec

Please sign in to comment.