diff --git a/README.md b/README.md index 3794ae0..5237e0a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Lying: scripting lang for kotlin multiplatform +# Ling: scripting lang for kotlin multiplatform in the form of multiplatform library. diff --git a/docs/List.md b/docs/List.md index de706f1..abf6576 100644 --- a/docs/List.md +++ b/docs/List.md @@ -2,7 +2,7 @@ Mutable list of any objects. -It's class in Lying is `List`: +It's class in Ling is `List`: [1,2,3]::class >>> List diff --git a/docs/OOP.md b/docs/OOP.md index 32720b4..ae6026e 100644 --- a/docs/OOP.md +++ b/docs/OOP.md @@ -1,4 +1,4 @@ -# OO implementation in Lying +# OO implementation in Ling Basic principles: @@ -15,7 +15,7 @@ Basic principles: ## Instances -Result of executing of any expression or statement in the Lying is the object that +Result of executing of any expression or statement in the Ling is the object that inherits `Obj`, but is not `Obj`. For example it could be Int, void, null, real, string, bool, etc. This means whatever expression returns or the variable holds, is the first-class diff --git a/docs/Real.md b/docs/Real.md index 251850f..8010701 100644 --- a/docs/Real.md +++ b/docs/Real.md @@ -3,7 +3,7 @@ Class that supports double-precision math. Woks much like double in other languages. We honor no floats, so it is ' Real'. -It's class in Lying is `Real`: +It's class in Ling is `Real`: (π/2)::class >>> Real diff --git a/docs/tutorial.md b/docs/tutorial.md index 43b4cb1..b72b37d 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -1,6 +1,6 @@ -# Lying tutorial +# Ling tutorial -Lying is a very simple language, where we take only most important and popular features from +Ling is a very simple language, where we take only most important and popular features from other scripts and languages. In particular, we adopt _principle of minimal confusion_[^1]. In other word, the code usually works as expected when you see it. So, nothing unusual. @@ -8,12 +8,12 @@ __Other documents to read__ maybe after this one: - [Advanced topics](advanced_topics.md) - [OOP notes](OOP.md) -- [math in Lying](math.md) +- [math in Ling](math.md) - Some class references: [List](List.md), [Real](Real.md), [Range](Range.md) # Expressions -Everything is an expression in Lying. Even an empty block: +Everything is an expression in Ling. Even an empty block: // empty block >>> void @@ -221,7 +221,7 @@ Notice how function definition return a value, instance of `Callable`. You can use both `fn` and `fun`. Note that function declaration _is an expression returning callable_. -There are default parameters in Lying: +There are default parameters in Ling: fn check(amount, prefix = "answer: ") { prefix + if( amount > 100 ) @@ -273,7 +273,7 @@ If you need to create _unnamed_ function, use alternative syntax (TBD, like { -> # Lists (aka arrays) -Lying has built-in mutable array class `List` with simple literals: +Ling has built-in mutable array class `List` with simple literals: [1, "two", 3.33].size >>> 3 @@ -546,7 +546,7 @@ We can skip the rest of the loop and restart it, as usual, with `continue` opera >>> 0 Notice that `total` remains 0 as the end of the outerLoop@ is not reachable: `continue` is always called and always make -Lying to skip it. +Ling to skip it. ## else statement diff --git a/library/build.gradle.kts b/library/build.gradle.kts index a677b11..6fdf536 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -81,7 +81,7 @@ mavenPublishing { coordinates(group.toString(), "library", version.toString()) pom { - name = "Lying language" + name = "Ling language" description = "Kotlin-bound scripting loanguage" inceptionYear = "2025" // url = "https://sergeych.net" diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/Arguments.kt b/library/src/commonMain/kotlin/net/sergeych/ling/Arguments.kt index dcd2989..2cc1431 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/Arguments.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/Arguments.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling data class ParsedArgument(val value: Statement, val pos: Pos, val isSplat: Boolean = false) diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/BuildDoubleFromParts.kt b/library/src/commonMain/kotlin/net/sergeych/ling/BuildDoubleFromParts.kt index 1db6157..edcc0cf 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/BuildDoubleFromParts.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/BuildDoubleFromParts.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling //fun buildDoubleFromParts( // integerPart: Long, diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/Compiler.kt b/library/src/commonMain/kotlin/net/sergeych/ling/Compiler.kt index b1a2d67..bcc7931 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/Compiler.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/Compiler.kt @@ -1,7 +1,7 @@ -package net.sergeych.lying +package net.sergeych.ling /** - * The LYING compiler. + * The LING compiler. */ class Compiler( @Suppress("UNUSED_PARAMETER") @@ -315,6 +315,12 @@ class Compiler( } } +// Token.Type.LBRACE -> { +// if( operand != null ) { +// throw ScriptError(t.pos, "syntax error: lambda expression not allowed here") +// } +// } + else -> { cc.previous() diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/CompilerContext.kt b/library/src/commonMain/kotlin/net/sergeych/ling/CompilerContext.kt index b44f6ad..a6d71fb 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/CompilerContext.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/CompilerContext.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling internal class CompilerContext(val tokens: List) : ListIterator by tokens.listIterator() { val labels = mutableSetOf() diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/Context.kt b/library/src/commonMain/kotlin/net/sergeych/ling/Context.kt index a3f3228..cd5a3fe 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/Context.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/Context.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling class Context( val parent: Context?, diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ListEntry.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ListEntry.kt index 3d1e35c..82dbb58 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ListEntry.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ListEntry.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling sealed class ListEntry { data class Element(val accessor: Accessor) : ListEntry() diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/LoopBreakContinueException.kt b/library/src/commonMain/kotlin/net/sergeych/ling/LoopBreakContinueException.kt index 560a93b..39af279 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/LoopBreakContinueException.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/LoopBreakContinueException.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling class LoopBreakContinueException( val doContinue: Boolean, diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/Obj.kt b/library/src/commonMain/kotlin/net/sergeych/ling/Obj.kt index 42b66c8..fe7cb97 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/Obj.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/Obj.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ObjBool.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ObjBool.kt index d948e2c..1fac6ab 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ObjBool.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ObjBool.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling data class ObjBool(val value: Boolean) : Obj() { override val asStr by lazy { ObjString(value.toString()) } diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ObjChar.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ObjChar.kt index 0b08a72..733bce5 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ObjChar.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ObjChar.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling class ObjChar(val value: Char): Obj() { diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ObjClass.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ObjClass.kt index 37cbfc9..61aca8c 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ObjClass.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ObjClass.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling val ObjClassType by lazy { ObjClass("Class") } diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ObjInt.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ObjInt.kt index a69f9b1..659dbe7 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ObjInt.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ObjInt.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling data class ObjInt(var value: Long) : Obj(), Numeric { override val asStr get() = ObjString(value.toString()) diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ObjList.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ObjList.kt index a93bc2b..1e82d62 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ObjList.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ObjList.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling class ObjList(val list: MutableList) : Obj() { diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ObjRange.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ObjRange.kt index 0a0b443..2fb51d2 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ObjRange.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ObjRange.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling class ObjRange(val start: Obj?, val end: Obj?, val isEndInclusive: Boolean) : Obj() { diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ObjRangeIterator.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ObjRangeIterator.kt index 8e23ac7..592545e 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ObjRangeIterator.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ObjRangeIterator.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling class ObjRangeIterator(val self: ObjRange) : Obj() { diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ObjReal.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ObjReal.kt index 6aafa14..7e6fc73 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ObjReal.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ObjReal.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling import kotlin.math.floor import kotlin.math.roundToLong diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ObjString.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ObjString.kt index 981d828..bc2949a 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ObjString.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ObjString.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/Parser.kt b/library/src/commonMain/kotlin/net/sergeych/ling/Parser.kt index f10eaae..3cdf7c2 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/Parser.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/Parser.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling val digitsSet = ('0'..'9').toSet() val digits = { d: Char -> d in digitsSet } diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/Pos.kt b/library/src/commonMain/kotlin/net/sergeych/ling/Pos.kt index 0c041b9..f826fe8 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/Pos.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/Pos.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling data class Pos(val source: Source, val line: Int, val column: Int) { override fun toString(): String { diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/Script.kt b/library/src/commonMain/kotlin/net/sergeych/ling/Script.kt index 60b7486..75234ed 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/Script.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/Script.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling import kotlin.math.* diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/ScriptError.kt b/library/src/commonMain/kotlin/net/sergeych/ling/ScriptError.kt index 9860a8d..d8f59e8 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/ScriptError.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/ScriptError.kt @@ -1,6 +1,6 @@ @file:Suppress("CanBeParameter") -package net.sergeych.lying +package net.sergeych.ling open class ScriptError(val pos: Pos, val errorMessage: String,cause: Throwable?=null) : Exception( """ diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/Source.kt b/library/src/commonMain/kotlin/net/sergeych/ling/Source.kt index 3073970..0a92d04 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/Source.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/Source.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling class Source(val fileName: String, text: String) { diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/StoredObj.kt b/library/src/commonMain/kotlin/net/sergeych/ling/StoredObj.kt index ea67688..193828f 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/StoredObj.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/StoredObj.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling /** * Whatever [Obj] stored somewhere diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/Token.kt b/library/src/commonMain/kotlin/net/sergeych/ling/Token.kt index a56c1a7..094f92a 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/Token.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/Token.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling data class Token(val value: String, val pos: Pos, val type: Type) { val isComment: Boolean by lazy { type == Type.SINLGE_LINE_COMMENT || type == Type.MULTILINE_COMMENT } diff --git a/library/src/commonMain/kotlin/net/sergeych/ling/statements.kt b/library/src/commonMain/kotlin/net/sergeych/ling/statements.kt index 5ba2be2..da4f64d 100644 --- a/library/src/commonMain/kotlin/net/sergeych/ling/statements.kt +++ b/library/src/commonMain/kotlin/net/sergeych/ling/statements.kt @@ -1,4 +1,4 @@ -package net.sergeych.lying +package net.sergeych.ling fun String.toSource(name: String = "eval"): Source = Source(name, this) diff --git a/library/src/commonTest/kotlin/ScriptTest.kt b/library/src/commonTest/kotlin/ScriptTest.kt index c3f47ae..89ba50e 100644 --- a/library/src/commonTest/kotlin/ScriptTest.kt +++ b/library/src/commonTest/kotlin/ScriptTest.kt @@ -1,7 +1,7 @@ package io.github.kotlin.fibonacci import kotlinx.coroutines.test.runTest -import net.sergeych.lying.* +import net.sergeych.ling.* import kotlin.test.* class ScriptTest { @@ -1039,16 +1039,15 @@ class ScriptTest { ) } + @Test + fun testLambda1() = runTest { + val l = eval(""" + val x = { + 122 + } + x + """.trimIndent()) + println(l) + } -// @Test -// fun testLambda1() = runTest { -// val l = eval(""" -// x = { -// 122 -// } -// x -// """.trimIndent()) -// println(l) -// } -// } \ No newline at end of file diff --git a/library/src/jvmTest/kotlin/BookTest.kt b/library/src/jvmTest/kotlin/BookTest.kt index a7f261b..962bf2e 100644 --- a/library/src/jvmTest/kotlin/BookTest.kt +++ b/library/src/jvmTest/kotlin/BookTest.kt @@ -3,8 +3,8 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.test.runTest -import net.sergeych.lying.Context -import net.sergeych.lying.ObjVoid +import net.sergeych.ling.Context +import net.sergeych.ling.ObjVoid import java.nio.file.Files.readAllLines import java.nio.file.Paths import kotlin.test.Test