Reputation: 3015
I'm trying to create an internal DSL for Ruby, I haven't started coding it yet, and I'm wondering if this syntax is possible in 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
And also:
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
}
UPDATE: :D I'm still defining the DSL's requirements, such is my starting point, I'm considering either a custom parser or Ruby. What would you say is a better idea, to create a custom parser for it or use Ruby?
Upvotes: 3
Views: 265
Reputation: 3015
Here is an alternative version that is valid ruby syntax:
IF CLASS Student {
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
}
UPDATE: I've been checking out possibilities, it is possible to use IF, THEN, WITH in uppercase.
Upvotes: 1
Reputation: 369458
This is not possible. The problem is with these constructs:
:class to
You cannot pass arguments to a symbol, only to methods.
Upvotes: 2