Introduce some new standard library modules
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package io.smnp.ext.lang
|
||||
|
||||
import io.smnp.ext.NativeModuleProvider
|
||||
import io.smnp.ext.lang.constructor.IntConstructor
|
||||
import io.smnp.ext.lang.constructor.NoteConstructor
|
||||
import io.smnp.ext.lang.function.TypeOfFunction
|
||||
import io.smnp.ext.lang.method.CharAtMethod
|
||||
import io.smnp.ext.lang.method.ListAccessMethod
|
||||
@@ -9,6 +11,6 @@ import org.pf4j.Extension
|
||||
|
||||
@Extension
|
||||
class LangModule : NativeModuleProvider("smnp.lang") {
|
||||
override fun functions() = listOf(TypeOfFunction())
|
||||
override fun functions() = listOf(IntConstructor(), NoteConstructor(), TypeOfFunction())
|
||||
override fun methods() = listOf(ListAccessMethod(), MapAccessMethod(), CharAtMethod())
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.smnp.ext.lang.constructor
|
||||
|
||||
import io.smnp.callable.function.Function
|
||||
import io.smnp.callable.function.FunctionDefinitionTool
|
||||
import io.smnp.callable.signature.Signature.Companion.simple
|
||||
import io.smnp.type.enumeration.DataType.FLOAT
|
||||
import io.smnp.type.enumeration.DataType.INT
|
||||
import io.smnp.type.matcher.Matcher.Companion.ofType
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class IntConstructor : Function("Int") {
|
||||
override fun define(new: FunctionDefinitionTool) {
|
||||
new function simple(ofType(INT)) body { _, (int) ->
|
||||
int
|
||||
}
|
||||
|
||||
new function simple(ofType(FLOAT)) body { _, (float) ->
|
||||
Value.int((float.value as Float).toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.smnp.ext.lang.constructor
|
||||
|
||||
import io.smnp.callable.function.Function
|
||||
import io.smnp.callable.function.FunctionDefinitionTool
|
||||
import io.smnp.callable.signature.Signature.Companion.simple
|
||||
import io.smnp.data.entity.Note
|
||||
import io.smnp.data.enumeration.Pitch
|
||||
import io.smnp.type.enumeration.DataType.*
|
||||
import io.smnp.type.matcher.Matcher.Companion.ofType
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class NoteConstructor : Function("Note") {
|
||||
override fun define(new: FunctionDefinitionTool) {
|
||||
new function simple(
|
||||
ofType(STRING),
|
||||
ofType(INT),
|
||||
ofType(INT),
|
||||
ofType(BOOL)
|
||||
) body { _, (pitchString, octave, duration, dot) ->
|
||||
val pitch = Pitch.parse((pitchString.value as String).toLowerCase())
|
||||
val note = Note(pitch, octave.value as Int, duration.value as Int, dot.value as Boolean)
|
||||
Value.note(note)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user