deferred(pat)
SatisyTest
satisfy
anyItem, item(value)
element(vararg xs)
range(CharRange)
Seq(data, items)
Until(fold, item)
Repeat(fold, item)
Decide(cases)
Convert(item, from, to)
Contextual(head, body)
SurroundBy(lr, item)
JoinBy(seprator, item)
TriePattern()
InfixPattern(atom, op)
SatisyTest
satisfy
anyItem, item(value)
element(vararg xs)
range(CharRange)
Seq(data, items)
Until(fold, item)
Repeat(fold, item)
Decide(cases)
Convert(item, from, to)
Contextual(head, body)
SurroundBy(lr, item)
JoinBy(seprator, item)
TriePattern()
InfixPattern(atom, op)
satisfy(predicate)
anyItem item(value)
elementIn(vararg xs)
elementIn(CharRange)
Seq(data, items)
Until(fold, item, terminate)
Repeat(fold, item) { open val countBound: Preciate<Cnt> }
Decide(cases)
SatisfyTest { abstract fun test(value: IN): Boolean }
SurroundBy(lr, item)
JoinBy(seprator, item)
Deferred(item)
Convert(item, from, to)
Contextual(head, body)
TriePattern()
InfixPattern(seprator, item)
anyItem item(value)
elementIn(vararg xs)
elementIn(CharRange)
Seq(data, items)
Until(fold, item, terminate)
Repeat(fold, item) { open val countBound: Preciate<Cnt> }
Decide(cases)
SatisfyTest { abstract fun test(value: IN): Boolean }
SurroundBy(lr, item)
JoinBy(seprator, item)
Deferred(item)
Convert(item, from, to)
Contextual(head, body)
TriePattern()
InfixPattern(seprator, item)
/tmp/duangsuse.sock
satisfy(predicate) anyItem item(value) elementIn(vararg xs) elementIn(CharRange) Seq(data, items) Until(fold, item, terminate) Repeat(fold, item) { open val countBound: Preciate<Cnt> } Decide(cases) SatisfyTest { abstract fun test(value: IN): Boolean }…
SURD — Seq, Until, Repeat, Decide
IES — Item, ElementIn, Satisfy
合起来重写的版本不叫 Parser.kt 了,叫 Surdies 吧(迫真)
Seq(data, items)
Until(fold, terminate, item)
Repeat(fold, item) { open val countBound: Preciate<Cnt> }
Decide(cases)
item() item(value)
elementIn(vararg xs) elementIn(CharRange)
satisfy(predicate)
Deferred(item)
JoinBy(seprator, item)
SurroundBy(surround, item)
Convert(item, from, to)
Contextual(head, body)
TriePattern()
InfixPattern(seprator, item)
SatisfyTest 还要加一个逆命题 not() operator。
这样我们就可以 Until(ignore(), !elementIn(whiteSpaces), char)
Pattern<IN, T> 要有 toDefault(defaultValue: T): PositivePattern<IN, T>
需要用到的辅助模型:
Seq — Tuple
Repeat — Fold
TriePattern — Trie, Iterable.toMap, reverseMap, EnumMap
InfixPattern — InfixOp
typealias Producer<T> = () -> T
typealias Consumer<T> = (T) -> Unit
typealias Predicate<T> = (T) -> Boolean
Tuple 要 get/set, Index, toArray, equals, ext:toList
Tuple2
typealias AsList<T> = EffectFold<T, MutableList<T>, List<T>>
typealias BuildStr = ConvertFold<Char, StringBuilder, String>
class JoinFold<T>(initial: T, private val append: T.(T) -> T): Fold<T, T>
输入模型:
interface Feed<out T> {
val peek: T; fun consume(): T
class End: NoSuchElementException("no more")
}
interface Input<T>: Feed<T>, ErrorHandler<T>
abstract class SliceFeed
abstract class StreamFeed
open class CharInput: Input<Char>, SourceLocated
class CharInputCRLF
辅助:
fun <IN> Feed<IN>.consumeIf(predicate: Predicate<IN>): IN
fun <IN> Feed<IN>.takeWhile(predicate: Predicate<IN>): Sequence<IN>
fun <IN> Feed<IN>.take(n: Cnt): Sequence<IN>
fun impossible(): Nothing = error("impossible")
fun <T> MutableList<T>.removeLast() = removeAt(lastIndex)
IES — Item, ElementIn, Satisfy
合起来重写的版本不叫 Parser.kt 了,叫 Surdies 吧(迫真)
Seq(data, items)
Until(fold, terminate, item)
Repeat(fold, item) { open val countBound: Preciate<Cnt> }
Decide(cases)
item() item(value)
elementIn(vararg xs) elementIn(CharRange)
satisfy(predicate)
Deferred(item)
JoinBy(seprator, item)
SurroundBy(surround, item)
Convert(item, from, to)
Contextual(head, body)
TriePattern()
InfixPattern(seprator, item)
SatisfyTest 还要加一个逆命题 not() operator。
这样我们就可以 Until(ignore(), !elementIn(whiteSpaces), char)
Pattern<IN, T> 要有 toDefault(defaultValue: T): PositivePattern<IN, T>
需要用到的辅助模型:
Seq — Tuple
Repeat — Fold
TriePattern — Trie, Iterable.toMap, reverseMap, EnumMap
InfixPattern — InfixOp
typealias Producer<T> = () -> T
typealias Consumer<T> = (T) -> Unit
typealias Predicate<T> = (T) -> Boolean
Tuple 要 get/set, Index, toArray, equals, ext:toList
Tuple2
typealias AsList<T> = EffectFold<T, MutableList<T>, List<T>>
typealias BuildStr = ConvertFold<Char, StringBuilder, String>
class JoinFold<T>(initial: T, private val append: T.(T) -> T): Fold<T, T>
输入模型:
interface Feed<out T> {
val peek: T; fun consume(): T
class End: NoSuchElementException("no more")
}
interface Input<T>: Feed<T>, ErrorHandler<T>
abstract class SliceFeed
abstract class StreamFeed
open class CharInput: Input<Char>, SourceLocated
class CharInputCRLF
辅助:
fun <IN> Feed<IN>.consumeIf(predicate: Predicate<IN>): IN
fun <IN> Feed<IN>.takeWhile(predicate: Predicate<IN>): Sequence<IN>
fun <IN> Feed<IN>.take(n: Cnt): Sequence<IN>
fun impossible(): Nothing = error("impossible")
fun <T> MutableList<T>.removeLast() = removeAt(lastIndex)
分成 Extensions Slice Tuple Fold Input SURD IES MiscPattern TriePattern 这些部分实现?
class SliceFeed<T>(private val slice: Slice<T>): Feed<T> {
private var position = 0
private var tailConsumed = false
override val peek get() = slice[position] // v check for getPeek() v
override fun consume() = try { val got = peek; slice[++position]; got }
catch (_: IndexOutOfBoundsException) {
--position
if (!tailConsumed) peek.also { tailConsumed = true }
else throw Feed.End()
}
override fun toString() = "Slice(${peek}...${slice})"
}
不好看,只是可以加一个 noexcept,弃了弃了。 #Kotlin #codeForwarded from Deleted Account
把 fun 换成 def;interface 换成 trait;泛型的 <> 换成 []、* 换成 _;函数类型的 (T)->R 换成 (T) => R 基本上就可以写 Scala 了
Scala 的闭包 {} 还有 { case A => R1; case B => R2 } 那种写法,相当复杂多样而且风格类似数学……
Scala 的 () => R 还可以直接省略 (),而且这语言不是惰性求值传参的,真是……
Scala 的闭包 {} 还有 { case A => R1; case B => R2 } 那种写法,相当复杂多样而且风格类似数学……
Scala 的 () => R 还可以直接省略 (),而且这语言不是惰性求值传参的,真是……
Forwarded from Deleted Account
感觉这句话可以说三遍,如果觉得无聊了就换本书看,多买几本不同领域的书,比如算法/嵌入式/GUI应用/编译原理/语言实现换着看,是个不错的方法。
Forwarded from Deleted Account
以前有电脑的时候我根本不会看书,现在也是一样……
所以说一定不能让自己经常在电脑旁边…… 会死人的
思维也是不在实操编程的时候会灵活很多
许多不错的设计也都是在吃饭、散步什么的时候想出来的
所以这个下机时间很重要,学习期要多留
像我这样的码农,不太在乎(学习理论、实践理论)提升的,书基本不会看,编程比较多……
所以说一定不能让自己经常在电脑旁边…… 会死人的
思维也是不在实操编程的时候会灵活很多
许多不错的设计也都是在吃饭、散步什么的时候想出来的
所以这个下机时间很重要,学习期要多留
像我这样的码农,不太在乎(学习理论、实践理论)提升的,书基本不会看,编程比较多……
Forwarded from Deleted Account
成天水裙是没前途的 (无恶意,只是说,如果那样的话)
大概帮助,太冷漠太热情都不合适,还是点到为止。
大概帮助,太冷漠太热情都不合适,还是点到为止。