我正在尝试为 Ruby 创建一个内部 DSL,我还没有开始编写它,我想知道这种语法在 Ruby 中是否可行:
IF more_than: 1, :class smells to: "god class", sense: HIGH and has "no temp attributes", sense: 0.5
THEN problem "some problem"
WITH ponderation percent: 10
并且:
IF more_than: 1, :class
{
smells to: 'god class', sense: 2
and
(
has 'no temp attributes', sense: 0.5 or
smells to: 'extensive coupling', sense: 1.5 or
has 'refused parent Bequest', sense: HIGH or
smells to: 'tradition breaker', sense: LOW
)
and
(
has :Method
{
smells to: 'extensive coupling', sense: 1.5
}
)
}
THEN
{
problem "abusive conceptualization"
}
WITH
{
ponderation percent: 10
}
更新:: D 我仍在定义 DSL 的要求,这是我的出发点,我正在考虑自定义解析器或 Ruby。你会说什么是更好的主意,为它创建一个自定义解析器或使用 Ruby?