-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
2,147 additions
and
1,671 deletions.
There are no files selected for viewing
28 changes: 18 additions & 10 deletions
28
selector/src/commonMain/kotlin/li/songe/selector/Exception.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,55 +1,63 @@ | ||
package li.songe.selector | ||
|
||
import li.songe.selector.property.BinaryExpression | ||
import li.songe.selector.property.ValueExpression | ||
import kotlin.js.JsExport | ||
|
||
@JsExport | ||
sealed class SelectorCheckException(override val message: String) : Exception(message) | ||
sealed class GkdException(override val message: String) : Exception(message) | ||
|
||
@JsExport | ||
data class SyntaxException(override val message: String) : GkdException(message) | ||
|
||
@JsExport | ||
sealed class TypeException(override val message: String) : GkdException(message) | ||
|
||
@JsExport | ||
data class UnknownIdentifierException( | ||
val value: ValueExpression.Identifier, | ||
) : SelectorCheckException("Unknown Identifier: ${value.stringify()}") | ||
) : TypeException("Unknown Identifier: ${value.stringify()}") | ||
|
||
@JsExport | ||
data class UnknownMemberException( | ||
val value: ValueExpression.MemberExpression, | ||
) : SelectorCheckException("Unknown Member: ${value.stringify()}") | ||
) : TypeException("Unknown Member: ${value.stringify()}") | ||
|
||
@JsExport | ||
data class UnknownIdentifierMethodException( | ||
val value: ValueExpression.Identifier, | ||
) : SelectorCheckException("Unknown Identifier Method: ${value.stringify()}") | ||
) : TypeException("Unknown Identifier Method: ${value.stringify()}") | ||
|
||
@JsExport | ||
data class UnknownIdentifierMethodParamsException( | ||
val value: ValueExpression.CallExpression, | ||
) : SelectorCheckException("Unknown Identifier Method Params: ${value.stringify()}") | ||
) : TypeException("Unknown Identifier Method Params: ${value.stringify()}") | ||
|
||
@JsExport | ||
data class UnknownMemberMethodException( | ||
val value: ValueExpression.MemberExpression, | ||
) : SelectorCheckException("Unknown Member Method: ${value.stringify()}") | ||
) : TypeException("Unknown Member Method: ${value.stringify()}") | ||
|
||
@JsExport | ||
data class UnknownMemberMethodParamsException( | ||
val value: ValueExpression.CallExpression, | ||
) : SelectorCheckException("Unknown Member Method Params: ${value.stringify()}") | ||
) : TypeException("Unknown Member Method Params: ${value.stringify()}") | ||
|
||
@JsExport | ||
data class MismatchParamTypeException( | ||
val call: ValueExpression.CallExpression, | ||
val argument: ValueExpression, | ||
val type: PrimitiveType | ||
) : SelectorCheckException("Mismatch Param Type: ${argument.stringify()} should be ${type.key}") | ||
) : TypeException("Mismatch Param Type: ${argument.stringify()} should be ${type.key}") | ||
|
||
@JsExport | ||
data class MismatchExpressionTypeException( | ||
val exception: BinaryExpression, | ||
val leftType: PrimitiveType, | ||
val rightType: PrimitiveType, | ||
) : SelectorCheckException("Mismatch Expression Type: ${exception.stringify()}") | ||
) : TypeException("Mismatch Expression Type: ${exception.stringify()}") | ||
|
||
@JsExport | ||
data class MismatchOperatorTypeException( | ||
val exception: BinaryExpression, | ||
) : SelectorCheckException("Mismatch Operator Type: ${exception.stringify()}") | ||
) : TypeException("Mismatch Operator Type: ${exception.stringify()}") |
13 changes: 0 additions & 13 deletions
13
selector/src/commonMain/kotlin/li/songe/selector/Expression.kt
This file was deleted.
Oops, something went wrong.
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
26 changes: 0 additions & 26 deletions
26
selector/src/commonMain/kotlin/li/songe/selector/Position.kt
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
selector/src/commonMain/kotlin/li/songe/selector/PropertySegment.kt
This file was deleted.
Oops, something went wrong.
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
67 changes: 67 additions & 0 deletions
67
selector/src/commonMain/kotlin/li/songe/selector/QueryResult.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,67 @@ | ||
package li.songe.selector | ||
|
||
import li.songe.selector.unit.LogicalSelectorExpression | ||
import li.songe.selector.unit.NotSelectorExpression | ||
import li.songe.selector.unit.SelectorExpression | ||
import li.songe.selector.unit.UnitSelectorExpression | ||
import kotlin.js.JsExport | ||
|
||
@JsExport | ||
sealed class QueryResult<T> { | ||
abstract val context: QueryContext<T> | ||
abstract val expression: SelectorExpression | ||
abstract val targetIndex: Int | ||
abstract val matched: Boolean | ||
|
||
@Suppress("unused") | ||
val target: T | ||
get() = context.get(targetIndex).current | ||
|
||
data class UnitResult<T>( | ||
override val context: QueryContext<T>, | ||
override val expression: UnitSelectorExpression, | ||
override val targetIndex: Int, | ||
) : QueryResult<T>() { | ||
override val matched: Boolean | ||
get() = context.matched | ||
} | ||
|
||
data class AndResult<T>( | ||
override val expression: LogicalSelectorExpression, | ||
val left: QueryResult<T>, | ||
val right: QueryResult<T>? = null, | ||
) : QueryResult<T>() { | ||
override val matched: Boolean | ||
get() = left.matched && right?.matched == true | ||
override val context: QueryContext<T> | ||
get() = right?.context ?: error("No matched result") | ||
override val targetIndex: Int | ||
get() = right?.targetIndex ?: error("No matched result") | ||
} | ||
|
||
data class OrResult<T>( | ||
override val expression: LogicalSelectorExpression, | ||
val left: QueryResult<T>, | ||
val right: QueryResult<T>? = null, | ||
) : QueryResult<T>() { | ||
override val matched: Boolean | ||
get() = left.matched || right?.matched == true | ||
override val context: QueryContext<T> | ||
get() = (if (left.matched) left else right)?.context ?: error("No matched result") | ||
override val targetIndex: Int | ||
get() = (if (left.matched) left else right)?.targetIndex ?: error("No matched result") | ||
} | ||
|
||
data class NotResult<T>( | ||
override val expression: NotSelectorExpression, | ||
val originalContext: QueryContext<T>, | ||
val result: QueryResult<T>, | ||
) : QueryResult<T>() { | ||
override val matched: Boolean | ||
get() = !result.matched | ||
override val context: QueryContext<T> | ||
get() = originalContext | ||
override val targetIndex: Int | ||
get() = 0 | ||
} | ||
} |
Oops, something went wrong.