Renamed to lyng/2
This commit is contained in:
parent
e13dde68b5
commit
dae09f0dc9
@ -1,4 +1,4 @@
|
||||
# Lying: scripting lang for kotlin multiplatform
|
||||
# Ling: scripting lang for kotlin multiplatform
|
||||
|
||||
in the form of multiplatform library.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
//fun buildDoubleFromParts(
|
||||
// integerPart: Long,
|
||||
|
@ -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()
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
internal class CompilerContext(val tokens: List<Token>) : ListIterator<Token> by tokens.listIterator() {
|
||||
val labels = mutableSetOf<String>()
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
class Context(
|
||||
val parent: Context?,
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
sealed class ListEntry {
|
||||
data class Element(val accessor: Accessor) : ListEntry()
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
class LoopBreakContinueException(
|
||||
val doContinue: Boolean,
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
|
@ -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()) }
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
class ObjChar(val value: Char): Obj() {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
val ObjClassType by lazy { ObjClass("Class") }
|
||||
|
||||
|
@ -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())
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
class ObjList(val list: MutableList<Obj>) : Obj() {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
class ObjRange(val start: Obj?, val end: Obj?, val isEndInclusive: Boolean) : Obj() {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
class ObjRangeIterator(val self: ObjRange) : Obj() {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.roundToLong
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
val digitsSet = ('0'..'9').toSet()
|
||||
val digits = { d: Char -> d in digitsSet }
|
||||
|
@ -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 {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
import kotlin.math.*
|
||||
|
||||
|
@ -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(
|
||||
"""
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
class Source(val fileName: String, text: String) {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
/**
|
||||
* Whatever [Obj] stored somewhere
|
||||
|
@ -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 }
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.sergeych.lying
|
||||
package net.sergeych.ling
|
||||
|
||||
fun String.toSource(name: String = "eval"): Source = Source(name, this)
|
||||
|
||||
|
@ -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("""
|
||||
// x = {
|
||||
// 122
|
||||
// }
|
||||
// x
|
||||
// """.trimIndent())
|
||||
// println(l)
|
||||
// }
|
||||
//
|
||||
@Test
|
||||
fun testLambda1() = runTest {
|
||||
val l = eval("""
|
||||
val x = {
|
||||
122
|
||||
}
|
||||
x
|
||||
""".trimIndent())
|
||||
println(l)
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user