我試圖創建Ruby的內部DSL,我還沒有開始編碼它,但我想知道,如果這句法在Ruby中是可能的:這是Ruby中的內部DSL語法嗎?
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?
有可能,是的。所以你應該開始編碼。 –
:P只是想確保語法不是無效的Ruby。 –
那麼,我希望你能夠在出現問題時能夠彎曲語法要求:) –