/tmp/duangsuse.sock
23 subscribers
303 photos
3 videos
92 files
337 links
从 duangsuse::Echo (@dsuse) 跟进出来的分支,将在作者恢复原帐号访问的时候合并删除。
Download Telegram
/tmp/duangsuse.sock
真的已经分不清框架的核心和外设了…… 都写在一个文件里 没有规矩
现在 ParserKt 也的确是越来越乱了…… 一些基本模型的实现,也被我质疑是 不够简洁 也能被查出 bug 了么……

看来 严格的工程规范 是必须了
可是我没有硬件条件,用不起 Gradle,而且自动化测试困难
21 行。从规则到 kotlin.Any,再 rebuild 回来。
[duangsuse@susepc pkt_9]$ kotlin MapSyntax
{'das':[1,2, 3,4], 'kas':444}
{das=[1, 2, 3, 4], kas=444}
{'das': [1, 2, 3, 4], 'kas': 444}
{'hello': [1,2,3, 4, 5,6], 'wor' 
{
Exception in thread "main" ParseError: <stdin>:2:0: expecting item for last seprator

{'fff':[1,2,3}
Exception in thread "main" ParseError: <stdin>:1:13: expecting `']'' (from <stdin>:1:8)

{'emm': 2333
Exception in thread "main" ParseError: <stdin>:2:0: expecting `'}'' (from <stdin>:1:1)

而且带完整的错误提示,而且还支持容错解析(就是上文的 clamly)
Forwarded from Justf News (Justf | 盲人)
Forwarded from POLICR · 更新通知
#安全警告 最近出现了一些极其严重的炸群现象,短时间内成百上千的 spammer 涌入到一个群中。

建议暂时关闭普通群成员的拉人(Add Users)功能。特别是一些经常受骚扰的群。注意,如果是公开群,不要轻易转为私有群,username 可能会被抢注。
吊打其他解析器框架实在是太爽了
什么左递归,算法大佬,可是写出来的定义能如 ParserKt 一样好看高性能吗?
补充一下,有人把石狮子的…… 给 宫刑 了
[duangsuse@susepc pkt_9]$ kotlin Arithmetic
1 + (2 - 3) + 4
+ + 1 (- 2 3) 4
= 4
[duangsuse@susepc pkt_9]$ kotlin Arithmetic
1+(2 - 3 + 4
null
= null
[(<stdin>:2:0#13, expecting ')' (from <stdin>:1:3)), (<stdin>:2:0#13, infix 1 parse failed at +)]
又拿 ParserKt 写了个计算器出来
/tmp/duangsuse.sock
现在 ParserKt 也的确是越来越乱了…… 一些基本模型的实现,也被我质疑是 不够简洁 也能被查出 bug 了么…… 看来 严格的工程规范 是必须了 可是我没有硬件条件,用不起 Gradle,而且自动化测试困难
但是我可以很自信地说,ParserKt 再乱也比那一堆 JavaScript 的 parser compiler (CFG, PEG) / parser combinator 好看

别的组合子框架里六行,在 ParserKt 里是一行真正即得易见平凡。
无论是 scannerless parsing 还是 lexer-parser 风格,都能完美兼容,除了异常系统不需要别的特性支撑。
PEG.js is a simple parser generator for JavaScript that produces fast parsers with excellent error reporting. 可惜就是参数名黏糊了一点,不能体现重点。
Ohm is a parser generator consisting of a library and a domain-specific language 可惜就是若要加“语义”,那代码就看不了喽。
Waxeye is a parser generator based on parsing expression grammars (PEGs). It supports C, Java, Javascript, Python, Ruby and Scheme. 我唯一看得上眼的工具,可惜在文档上还是略微欠缺了些。
Parsimmon is a small library for writing big parsers made up of lots of little parsers. The API is inspired by parsec and Promises/A+. 体现不出重点,有 lbrace 好啊,可是语法规则不是与语法本身对仗,而是与解析过程对仗,这就怎么写怎么也比不上 SurroundBy(item('{') to item('}'), wtf) 易读易复用。
Parjs is a JavaScript library of parser combinators, similar in principle and in design to the likes of Parsec and in particular its F# adaptation FParsec. 很学术,可惜没什么暖用,或许有人会觉得这么写很符合自然语言的语序,但编程毕竟不是侃大山,到处 map 最后往往先是别人 map 不回来,甚至以后自己也给 map 晕蛋。顺便提一句,用 ParserKt 的 SatisfyPattern !elementIn('`', '{') 可比 Parjs.noCharOf("`{") 好看多了。
Chevrotain is a very fast and feature rich JavaScript LL(k) Parsing DSL. It can be used to build parsers/compilers/interperters for various use cases ranging from simple configuration files, to full fledged programing languages. 我就不说什么了,没啥学术气息、接口又混乱,到处乱用 {} configure object,还是传统的 lexer-parser 架构。
Bennu is a Javascript parser combinator library based on Parsec. The Bennu library consists of a core set of parser combinators that implement Fantasy Land interfaces. More advanced functionality such as detailed error messaging, custom parser state, memoization, and running unmodified parsers incrementally is also supported. 这种框架就不是为了给人用的,主要还是为了让作者能弄一些非常高大上的函数式数据结构弄的。 val aOrB = elementIn('a', 'b') //item('a') or item('b'); aOrB.read("b")//'b'
/tmp/duangsuse.sock
PEG.js is a simple parser generator for JavaScript that produces fast parsers with excellent error reporting. 可惜就是参数名黏糊了一点,不能体现重点。
以上我把许多同类框架/工具/库 都给得罪了一遍 🤪
得罪得真舒服啊

其实 ParserKt 和它们大部分框架都不在一个思维频道上

如果你试着把一些框架的代码移植到 ParserKt,而不是直接从语法的角度重新设计,你可能会发现自己写了很多错误的置换,
因为 ParserKt 完全面向对象设计,Pattern 就是高复用代名词,用 Pattern 和 PatternWrapper 和用一些很基础复用性灵、活性很低的 组合子,思路完全不一样。
This media is not supported in your browser
VIEW IN TELEGRAM
/tmp/duangsuse.sock
[duangsuse@susepc pkt_9]$ kotlin Arithmetic 1 + (2 - 3) + 4 + + 1 (- 2 3) 4 = 4 [duangsuse@susepc pkt_9]$ kotlin Arithmetic 1+(2 - 3 + 4 null = null [(<stdin>:2:0#13, expecting ')' (from <stdin>:1:3)), (<stdin>:2:0#13, infix 1 parse failed at +)] 又拿 ParserKt…
ParserKt 现在的代码简洁性已经蛮够了,用来实现各种解析器/REPL 都不是问题
因为解析器框架本身很具有复用性,现在又有了 LexicalBasics 对其复用性的利用