[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

is a timepoint DSL possible, like: 10:31 instead of "10:29"?

Dirk Lüsebrink

10/1/2006 9:25:00 AM

i could not think of any way to include the ':' character in a DSL, so
that i could write:

from 10:30 to 11:30

instead

from "10:30" to "11:30"

I mean, it is not that bad, but still.
dirk

ps.: of course i can always parse it,


--
Posted via http://www.ruby-....

10 Answers

Esad Hajdarevic

10/1/2006 12:03:00 PM

0

I know it is not the same, but you could use .. instead of :, that way
you will get ranges, and you can use Range#min and Range#max to get hour
and minute part.

Esad

Dirk Lüsebrink wrote:
> i could not think of any way to include the ':' character in a DSL, so
> that i could write:
>
> from 10:30 to 11:30
>
> instead
>
> from "10:30" to "11:30"
>
> I mean, it is not that bad, but still.
> dirk
>
> ps.: of course i can always parse it,
>
>

David Vallner

10/1/2006 2:55:00 PM

0

Dirk Lüsebrink wrote:
> i could not think of any way to include the ':' character in a DSL, so
> that i could write:
>
> from 10:30 to 11:30
>
> instead
>
> from "10:30" to "11:30"
>
> I mean, it is not that bad, but still.
> dirk
>
> ps.: of course i can always parse it,
>
>

I'd just use the 'from 1030 to 1130' notation - hopefully you don't need
to use both time values and integers in the same context.

Esad Hajdarevic

10/1/2006 3:58:00 PM

0

David Vallner wrote:

> I'd just use the 'from 1030 to 1130' notation - hopefully you don't need
> to use both time values and integers in the same context.

why not even more concise: 1030..1130 :-)

Esad

M. Edward (Ed) Borasky

10/1/2006 5:38:00 PM

0

David Vallner wrote:
> Dirk Lüsebrink wrote:
>> i could not think of any way to include the ':' character in a DSL, so
>> that i could write:
>>
>> from 10:30 to 11:30
>>
>> instead
>>
>> from "10:30" to "11:30"
>>
>> I mean, it is not that bad, but still.
>> dirk
>>
>> ps.: of course i can always parse it,
>>
>>
>
> I'd just use the 'from 1030 to 1130' notation - hopefully you don't need
> to use both time values and integers in the same context.
>

I'd recommend *not* using either integers or floating point (from 10.30
to 11.30) "type puns". The double-quotes are awkward, true, but then
some magic with "strptime" gives you real workable values for time
computations.


samuel.murphy

10/1/2006 6:08:00 PM

0


M. Edward (Ed) Borasky wrote:
> David Vallner wrote:
> > Dirk Lüsebrink wrote:
> >> i could not think of any way to include the ':' character in a DSL, so
> >> that i could write:
> >>
> >> from 10:30 to 11:30
> >>
> >> instead
> >>
> >> from "10:30" to "11:30"
> >>
> >> I mean, it is not that bad, but still.
> >> dirk
> >>
> >> ps.: of course i can always parse it,
> >>
> >>
> >
> > I'd just use the 'from 1030 to 1130' notation - hopefully you don't need
> > to use both time values and integers in the same context.
> >
>
> I'd recommend *not* using either integers or floating point (from 10.30
> to 11.30) "type puns". The double-quotes are awkward, true, but then
> some magic with "strptime" gives you real workable values for time
> computations.

Not only that, re-think the problem and remove *data* from the code.
Put
it in a config file (where quotes would not be necessary), a database,
or an include file of some kind.

Scott

10/1/2006 6:24:00 PM

0

> Not only that, re-think the problem and remove *data* from the code.
> Put
> it in a config file (where quotes would not be necessary), a database,
> or an include file of some kind.


When writing a DSL in Ruby, often the 'config' file is actual ruby code
(at least in my limited experience), which I'm guessing is probably the
case here. Sometimes its nice to have the full power of Ruby available
in your config/dsl file, rather than having to hook up to a database
just to get config data.

-Scott

Christian Neukirchen

10/1/2006 10:18:00 PM

0

David Vallner <david@vallner.net> writes:

> Dirk Lüsebrink wrote:
>> i could not think of any way to include the ':' character in a DSL, so
>> that i could write:
>>
>> from 10:30 to 11:30
>>
>> instead
>>
>> from "10:30" to "11:30"
>>
>> I mean, it is not that bad, but still.
>> dirk
>>
>> ps.: of course i can always parse it,
>>
>>
>
> I'd just use the 'from 1030 to 1130' notation - hopefully you don't need
> to use both time values and integers in the same context.

Beware of leading zeroes and octal numbers.

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

Matthias Reitinger

10/2/2006 3:35:00 AM

0

David Vallner wrote:
> Dirk Lüsebrink wrote:
>> i could not think of any way to include the ':' character in a DSL, so
>> that i could write:
>>
>> from 10:30 to 11:30
>>
>> instead
>>
>> from "10:30" to "11:30"
>>
>> I mean, it is not that bad, but still.
>> dirk
>>
>> ps.: of course i can always parse it,
>>
>>
>
> I'd just use the 'from 1030 to 1130' notation - hopefully you don't need
> to use both time values and integers in the same context.

You could also use 'from 10_30 to 11_30', which is similar in semantics but
a little easier to read.

Dirk Lüsebrink

10/2/2006 9:41:00 AM

0

thank you all for input on my little question. by now i'm quite sure i
can't trick the ruby parser in accepting 10:30 for anything else than a
syntax error. But i'm quite happy with the propsals, the one i like best
is:

'from 1030 to 1130'

this is reasonable close to what i had in mind(but what is with '0900'
Illegal octal digit?). the basic idea is a console based time accounting
implemented as an internal DSL with:

02.10 10:15-21:30 # a days work
13:45-15:15 # time span: task with begin and end time
0:45 # duration: a task given as duration in hours and
minutes
1.5 # a task given as fractions of hours an minutes

but with the feedback from this list i think i go for an external
DSL(http://www.martinfowler.com/bliki/DomainSpecificLan...).
Regex based parsing should be easy enough. This is because '10_30' and
the octal problems with '0900' might be solvable, but DSL should be for
humans, not for parsers. And that was:

02.10 11:00-
0:30 timepoint DSL # thirty minutes on ruby-forum.

have fun
dirk



Matthias Reitinger wrote:
> David Vallner wrote:
>>> I mean, it is not that bad, but still.
>>> dirk
>>>
>>> ps.: of course i can always parse it,
>>>
>>>
>>
>> I'd just use the 'from 1030 to 1130' notation - hopefully you don't need
>> to use both time values and integers in the same context.
>
> You could also use 'from 10_30 to 11_30', which is similar in semantics
> but
> a little easier to read.


--
Posted via http://www.ruby-....

David Vallner

10/2/2006 10:03:00 AM

0

Dirk Lüsebrink wrote:
> thank you all for input on my little question. by now i'm quite sure i
> can't trick the ruby parser in accepting 10:30 for anything else than a
> syntax error. But i'm quite happy with the propsals, the one i like best
> is:
>
> 'from 1030 to 1130'
>
> this is reasonable close to what i had in mind(but what is with '0900'
> Illegal octal digit?).

As Christian Neukirchen corrected me, you can't use times with leading
zeroes like that. Use only 900 instead of 0900? I still can't think
where that would be ambiguous, provided you always indicate hour+minute
times, never mixing them with only hour and only minute times in a context.

David Vallner