Comments (9)
DSL要得是对特定场景的语言表达力,用Go Parser把同样的语法换一个地方写,那就真的是没事找事了
from blog_comment.
好文
from blog_comment.
不用Go内置的Parser主要是因为它是和Go Language Spec绑定的,DSL主要是想创造新语法和新Token,你用内置Parser能够实现in_array(c, []int{1,2,3,4})
但是实现不了 c in [1,2,3,4]
。不过这个原理都是差不多,DSL讲究的就是一个“*”,如果语法啥的都没变那不如直接写Go代码,codegen就行了,DSL没啥意义了
from blog_comment.
@caibirdme ,实现得了。IDENT 可以随意扩充,in 后面的定义成业务规则就行了。
而且我文中已经说过了,再加上函数的扩展功能,大部分需求都可以实现,况且所谓规则引擎没有任何特殊场景一说,本质就是布尔表达式
from blog_comment.
不论怎么扩充,parse出来的都是Go spec的Token,IDENT只是token的一种,只能解析可以被用来声明成变量名的字符串。[1,2,3]
,这个解析出来显然是没有IDENT的,你怎么通过扩展IDENT实现这个的解析?a in b
符合词法,但不符合文法,也就无从构建AST了。你把你的实例中的bool表达式a==1&&b==2
换成a in b
,就返回error了。加了新词法和新文法,就不可能用原来的编译器直接parse
from blog_comment.
in_array(ident, f(1,2,3,4))
in(ident, f(1,2,3,4))
in(ident, PRESET_BUSINESS_ARR)
没必要抱着一个写法用到死,模仿sql的扩展方式什么都可以做
from blog_comment.
那这和
func in(a,b interface{}) bool {
}
in(ident, f(1,2,3,4))
有啥区别,干嘛还要用DSL…直接写Go代码就行了,DSL肯定得改语法啊
from blog_comment.
规则是在数据库里的。。
from blog_comment.
@caibirdme
那这和func in(a,b interface{}) bool { } in(ident, f(1,2,3,4))
有啥区别,干嘛还要用DSL…直接写Go代码就行了,DSL肯定得改语法啊
直接写go代码需要编译发布,很麻烦。 搞规则引擎是希望获得动态能力,通过修改DB或配置来灵活修改程序的行为。然后配合一个管理后台,可以让产品和运营通过web页面操作来控制程序逻辑。
至于语法规则,各种语言大同小异,新搞个DSL也没有简化多少,确实是没有必要搞新的DSL的,王垠也有类似观点。
from blog_comment.
Related Issues (20)
- 为什么要旗帜鲜明地反对 orm 和 sql builder HOT 25
- memory ballast 和 gc tuner 成为历史 HOT 8
- go-redis 和 redis server 版本错位导致的高延时问题一例 HOT 2
- 为什么大公司讲的效率如此虚伪 HOT 11
- 自动调整 GOGC 优化 GO 的 GC CPU 占用 HOT 3
- aws 上 kafka 服务更新导致断连一例 HOT 4
- 平台到底有什么价值 HOT 9
- 如何在 kv 系统中支持简单的 SQL HOT 2
- 微服务税 HOT 6
- 谈一谈es的优势和限制 HOT 2
- sarama producer hang 又一例 HOT 2
- 下一次工业革命近在眼前了 HOT 13
- 非协作式抢占详解 HOT 1
- 给面试官一点小小的 gpt 震撼 HOT 4
- 中台 2023 HOT 3
- 杂谈 HOT 6
- 关于复杂度的一些想法 HOT 2
- 新加坡保本理财指南 HOT 2
- 一些鬼故事 HOT 11
- 怎样提升研发效率(1) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog_comment.