Renamed to lyng

This commit is contained in:
Sergey Chernov 2025-06-02 11:38:17 +04:00
parent 6ef94fff65
commit e13dde68b5
34 changed files with 47 additions and 51 deletions

View File

@ -1,4 +1,4 @@
# Ling: scripting lang for kotlin multiplatform # Lying: scripting lang for kotlin multiplatform
in the form of multiplatform library. in the form of multiplatform library.

View File

@ -2,7 +2,7 @@
Mutable list of any objects. Mutable list of any objects.
It's class in Ling is `List`: It's class in Lying is `List`:
[1,2,3]::class [1,2,3]::class
>>> List >>> List

View File

@ -1,4 +1,4 @@
# OO implementation in Ling # OO implementation in Lying
Basic principles: Basic principles:
@ -15,7 +15,7 @@ Basic principles:
## Instances ## Instances
Result of executing of any expression or statement in the Ling is the object that Result of executing of any expression or statement in the Lying is the object that
inherits `Obj`, but is not `Obj`. For example it could be Int, void, null, real, string, bool, etc. 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 This means whatever expression returns or the variable holds, is the first-class

View File

@ -3,7 +3,7 @@
Class that supports double-precision math. Woks much like double in other languages. We honor no floats, so it is ' Class that supports double-precision math. Woks much like double in other languages. We honor no floats, so it is '
Real'. Real'.
It's class in Ling is `Real`: It's class in Lying is `Real`:
(π/2)::class (π/2)::class
>>> Real >>> Real

View File

@ -1,6 +1,6 @@
# Ling tutorial # Lying tutorial
Ling is a very simple language, where we take only most important and popular features from Lying 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]. 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. 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) - [Advanced topics](advanced_topics.md)
- [OOP notes](OOP.md) - [OOP notes](OOP.md)
- [math in Ling](math.md) - [math in Lying](math.md)
- Some class references: [List](List.md), [Real](Real.md), [Range](Range.md) - Some class references: [List](List.md), [Real](Real.md), [Range](Range.md)
# Expressions # Expressions
Everything is an expression in Ling. Even an empty block: Everything is an expression in Lying. Even an empty block:
// empty block // empty block
>>> void >>> 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_. You can use both `fn` and `fun`. Note that function declaration _is an expression returning callable_.
There are default parameters in Ling: There are default parameters in Lying:
fn check(amount, prefix = "answer: ") { fn check(amount, prefix = "answer: ") {
prefix + if( amount > 100 ) prefix + if( amount > 100 )
@ -273,7 +273,7 @@ If you need to create _unnamed_ function, use alternative syntax (TBD, like { ->
# Lists (aka arrays) # Lists (aka arrays)
Ling has built-in mutable array class `List` with simple literals: Lying has built-in mutable array class `List` with simple literals:
[1, "two", 3.33].size [1, "two", 3.33].size
>>> 3 >>> 3
@ -546,7 +546,7 @@ We can skip the rest of the loop and restart it, as usual, with `continue` opera
>>> 0 >>> 0
Notice that `total` remains 0 as the end of the outerLoop@ is not reachable: `continue` is always called and always make Notice that `total` remains 0 as the end of the outerLoop@ is not reachable: `continue` is always called and always make
Ling to skip it. Lying to skip it.
## else statement ## else statement

View File

@ -81,7 +81,7 @@ mavenPublishing {
coordinates(group.toString(), "library", version.toString()) coordinates(group.toString(), "library", version.toString())
pom { pom {
name = "Ling language" name = "Lying language"
description = "Kotlin-bound scripting loanguage" description = "Kotlin-bound scripting loanguage"
inceptionYear = "2025" inceptionYear = "2025"
// url = "https://sergeych.net" // url = "https://sergeych.net"

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
data class ParsedArgument(val value: Statement, val pos: Pos, val isSplat: Boolean = false) data class ParsedArgument(val value: Statement, val pos: Pos, val isSplat: Boolean = false)

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
//fun buildDoubleFromParts( //fun buildDoubleFromParts(
// integerPart: Long, // integerPart: Long,

View File

@ -1,7 +1,7 @@
package net.sergeych.ling package net.sergeych.lying
/** /**
* The LING compiler. * The LYING compiler.
*/ */
class Compiler( class Compiler(
@Suppress("UNUSED_PARAMETER") @Suppress("UNUSED_PARAMETER")

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
internal class CompilerContext(val tokens: List<Token>) : ListIterator<Token> by tokens.listIterator() { internal class CompilerContext(val tokens: List<Token>) : ListIterator<Token> by tokens.listIterator() {
val labels = mutableSetOf<String>() val labels = mutableSetOf<String>()

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
class Context( class Context(
val parent: Context?, val parent: Context?,
@ -16,10 +16,15 @@ class Context(
@Suppress("unused") @Suppress("unused")
fun raiseNPE(): Nothing = raiseError(ObjNullPointerError(this)) fun raiseNPE(): Nothing = raiseError(ObjNullPointerError(this))
@Suppress("unused")
fun raiseIndexOutOfBounds(message: String = "Index out of bounds"): Nothing = fun raiseIndexOutOfBounds(message: String = "Index out of bounds"): Nothing =
raiseError(ObjIndexOutOfBoundsError(this, message)) raiseError(ObjIndexOutOfBoundsError(this, message))
@Suppress("unused")
fun raiseArgumentError(message: String = "Illegal argument error"): Nothing = fun raiseArgumentError(message: String = "Illegal argument error"): Nothing =
raiseError(ObjIllegalArgumentError(this, message)) raiseError(ObjIllegalArgumentError(this, message))
fun raiseClassCastError(msg: String): Nothing = raiseError(ObjClassCastError(this, msg)) fun raiseClassCastError(msg: String): Nothing = raiseError(ObjClassCastError(this, msg))
fun raiseError(message: String): Nothing { fun raiseError(message: String): Nothing {

View File

@ -1,9 +0,0 @@
package net.sergeych.ling
class IfScope(val isTrue: Boolean) {
fun otherwise(f: ()->Unit): Boolean {
if( !isTrue ) f()
return false
}
}

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
sealed class ListEntry { sealed class ListEntry {
data class Element(val accessor: Accessor) : ListEntry() data class Element(val accessor: Accessor) : ListEntry()

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
class LoopBreakContinueException( class LoopBreakContinueException(
val doContinue: Boolean, val doContinue: Boolean,

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
data class ObjBool(val value: Boolean) : Obj() { data class ObjBool(val value: Boolean) : Obj() {
override val asStr by lazy { ObjString(value.toString()) } override val asStr by lazy { ObjString(value.toString()) }

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
class ObjChar(val value: Char): Obj() { class ObjChar(val value: Char): Obj() {

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
val ObjClassType by lazy { ObjClass("Class") } val ObjClassType by lazy { ObjClass("Class") }

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
data class ObjInt(var value: Long) : Obj(), Numeric { data class ObjInt(var value: Long) : Obj(), Numeric {
override val asStr get() = ObjString(value.toString()) override val asStr get() = ObjString(value.toString())

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
class ObjList(val list: MutableList<Obj>) : Obj() { class ObjList(val list: MutableList<Obj>) : Obj() {

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
class ObjRange(val start: Obj?, val end: Obj?, val isEndInclusive: Boolean) : Obj() { class ObjRange(val start: Obj?, val end: Obj?, val isEndInclusive: Boolean) : Obj() {

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
class ObjRangeIterator(val self: ObjRange) : Obj() { class ObjRangeIterator(val self: ObjRange) : Obj() {

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
import kotlin.math.floor import kotlin.math.floor
import kotlin.math.roundToLong import kotlin.math.roundToLong

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
val digitsSet = ('0'..'9').toSet() val digitsSet = ('0'..'9').toSet()
val digits = { d: Char -> d in digitsSet } val digits = { d: Char -> d in digitsSet }

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
data class Pos(val source: Source, val line: Int, val column: Int) { data class Pos(val source: Source, val line: Int, val column: Int) {
override fun toString(): String { override fun toString(): String {

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
import kotlin.math.* import kotlin.math.*

View File

@ -1,6 +1,6 @@
@file:Suppress("CanBeParameter") @file:Suppress("CanBeParameter")
package net.sergeych.ling package net.sergeych.lying
open class ScriptError(val pos: Pos, val errorMessage: String,cause: Throwable?=null) : Exception( open class ScriptError(val pos: Pos, val errorMessage: String,cause: Throwable?=null) : Exception(
""" """

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
class Source(val fileName: String, text: String) { class Source(val fileName: String, text: String) {

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
/** /**
* Whatever [Obj] stored somewhere * Whatever [Obj] stored somewhere

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
data class Token(val value: String, val pos: Pos, val type: Type) { 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 } val isComment: Boolean by lazy { type == Type.SINLGE_LINE_COMMENT || type == Type.MULTILINE_COMMENT }

View File

@ -1,4 +1,4 @@
package net.sergeych.ling package net.sergeych.lying
fun String.toSource(name: String = "eval"): Source = Source(name, this) fun String.toSource(name: String = "eval"): Source = Source(name, this)

View File

@ -1,7 +1,7 @@
package io.github.kotlin.fibonacci package io.github.kotlin.fibonacci
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import net.sergeych.ling.* import net.sergeych.lying.*
import kotlin.test.* import kotlin.test.*
class ScriptTest { class ScriptTest {

View File

@ -3,8 +3,8 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import net.sergeych.ling.Context import net.sergeych.lying.Context
import net.sergeych.ling.ObjVoid import net.sergeych.lying.ObjVoid
import java.nio.file.Files.readAllLines import java.nio.file.Files.readAllLines
import java.nio.file.Paths import java.nio.file.Paths
import kotlin.test.Test import kotlin.test.Test