-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename TypesafeClause to TypesafePredicate, now includes context
* Some significant changes to preserve usability of the DSL given the new contextual predicates/rules * Moves a lot of unfinished/unused code to a new subproject, dialector-kt-experimental * Adds many tests to improve coverage of rules and core Dialector elements
- Loading branch information
1 parent
9ff9251
commit a6b79a8
Showing
59 changed files
with
738 additions
and
391 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
plugins { | ||
kotlin("jvm") | ||
id("maven-publish") | ||
signing | ||
} | ||
|
||
dependencies { | ||
implementation(project(":dialector-kt")) | ||
implementation(kotlin("reflect")) | ||
|
||
testImplementation("org.jetbrains.kotlin:kotlin-test") | ||
testImplementation("io.mockk:mockk:1.12.0") | ||
} | ||
|
||
kotlin { | ||
explicitApiWarning() | ||
jvmToolchain { | ||
languageVersion.set(JavaLanguageVersion.of(8)) | ||
} | ||
} | ||
|
||
java { | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion
1
...dev/dialector/semantic/TypeConstraints.kt → ...dev/dialector/semantic/TypeConstraints.kt
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
34 changes: 20 additions & 14 deletions
34
dialector-kt/src/main/kotlin/dev/dialector/diagnostic/DiagnosticRule.kt
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 |
---|---|---|
@@ -1,32 +1,38 @@ | ||
package dev.dialector.diagnostic | ||
|
||
import dev.dialector.semantic.SemanticModel | ||
import dev.dialector.syntax.Node | ||
import dev.dialector.syntax.NodeClause | ||
import dev.dialector.syntax.SyntacticModel | ||
import dev.dialector.syntax.NodePredicate | ||
|
||
public interface DiagnosticEvaluationContext : SyntacticModel, SemanticModel { | ||
public interface DiagnosticContext { | ||
/** | ||
* Registers a diagnostic for the given node. | ||
*/ | ||
public fun diagnostic(message: String, node: Node) | ||
} | ||
|
||
/** | ||
* A rule that defines [ModelDiagnostics] that should be produced for nodes matching a [NodeClause] | ||
* A rule that defines [ModelDiagnostics] that should be produced for nodes matching a [NodePredicate] | ||
*/ | ||
public interface DiagnosticRule<T : Node> { | ||
public val isValidFor: NodeClause<T> | ||
public val diagnostics: DiagnosticEvaluationContext.(node: T) -> Unit | ||
public interface DiagnosticRule<T : Node, C : DiagnosticContext> { | ||
public val isValidFor: NodePredicate<T, in C> | ||
public val diagnostics: C.(node: T) -> Unit | ||
|
||
public operator fun invoke(context: DiagnosticEvaluationContext, node: Node) { | ||
public operator fun invoke(node: Node, context: C) { | ||
@Suppress("UNCHECKED_CAST") | ||
if (isValidFor(node)) context.diagnostics(node as T) | ||
if (isValidFor(node, context)) context.diagnostics(node as T) | ||
} | ||
} | ||
|
||
public infix fun <T : Node> NodeClause<T>.check(check: DiagnosticEvaluationContext.(node: T) -> Unit): DiagnosticRule<T> = | ||
object : DiagnosticRule<T> { | ||
override val isValidFor: NodeClause<T> = this@check | ||
override val diagnostics: DiagnosticEvaluationContext.(node: T) -> Unit = check | ||
/** | ||
* Produces a [DiagnosticRule] from the given [NodePredicate] and checking function. | ||
* | ||
* @param T The node type being checked. | ||
* @param C The [DiagnosticContext] type | ||
*/ | ||
public infix fun <T : Node, C : DiagnosticContext> NodePredicate<T, in C>.check( | ||
check: C.(node: T) -> Unit, | ||
): DiagnosticRule<T, C> = | ||
object : DiagnosticRule<T, C> { | ||
override val isValidFor: NodePredicate<T, in C> = this@check | ||
override val diagnostics: C.(node: T) -> Unit = check | ||
} |
52 changes: 0 additions & 52 deletions
52
dialector-kt/src/main/kotlin/dev/dialector/semantic/type/TypeClause.kt
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
dialector-kt/src/main/kotlin/dev/dialector/semantic/type/TypePredicate.kt
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,50 @@ | ||
package dev.dialector.semantic.type | ||
|
||
import dev.dialector.util.ClassifierPredicate | ||
import dev.dialector.util.InstancePredicate | ||
import dev.dialector.util.LogicalPredicate | ||
import dev.dialector.util.TypesafePredicate | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* A clause that describes a type. | ||
*/ | ||
public interface TypePredicate<T : Type, C> : TypesafePredicate<T, C> | ||
|
||
/** | ||
* A special TypeClause that matches against a specific Type. | ||
* | ||
* This specialization facilitates optimizations in TypeLattice implementation. | ||
*/ | ||
public class TypeObjectPredicate<T : Type, C>(type: T) : TypePredicate<T, C>, InstancePredicate<T, C>(type) | ||
|
||
/** | ||
* A special TypeClause that matches against a specific Typeclass | ||
* | ||
* This specialization facilitates optimizations in TypeLattice implementation. | ||
*/ | ||
public class TypeClassPredicate<T : Type, C>( | ||
typeClass: KClass<T>, | ||
) : TypePredicate<T, C>, ClassifierPredicate<T, C>(typeClass) | ||
|
||
public class TypeLogicalPredicate<T : Type, C>( | ||
typeClass: KClass<T>, | ||
predicate: C.(T) -> Boolean, | ||
) : TypePredicate<T, C>, LogicalPredicate<T, C>(typeClass, predicate) | ||
|
||
/** | ||
* Creates a TypeClause that matches against a specific Type. | ||
*/ | ||
public fun <T : Type> type(type: T): TypePredicate<T, Any> = TypeObjectPredicate(type) | ||
|
||
/** | ||
* Creates a TypeClause that matches against a specific Typeclass. | ||
*/ | ||
public inline fun <reified T : Type> typeClass(): TypePredicate<T, Any> = TypeClassPredicate(T::class) | ||
|
||
/** | ||
* Creates a TypeClause that matches types against a given predicate. | ||
*/ | ||
public inline fun <reified T : Type, C> typeClause( | ||
noinline predicate: C.(T) -> Boolean, | ||
): TypePredicate<T, C> = TypeLogicalPredicate(T::class, predicate) |
Oops, something went wrong.