[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] Endless Ruby 0.0.2

Caleb Clausen

5/29/2009 2:51:00 AM

endless.rb is a pre-processor for ruby which allows you to use python-ish
indentation to delimit scopes, instead of having to type 'end' every time.

http://gist.github....

Basically, this makes the end keyword optional. If you leave off the
end, the preprocessor inserts an end for you at the next line indented
at or below the level of indentation of the line which started the scope.
Since endless.rb uses RubyLexer, it should be able to handle almost
all ruby syntax.

Examples:

begin
a
b

begin
a
rescue
b
else
d
ensure
c

class A
class B
class C
module D
foo

def a b
c
d

for i in 1..10 do
p i
pp i

To be endless in your own code, you must first require 'endless.rb',
then load files which are written endlessly using Endless.load, rather
than the usual plain vanilla load (or require). (Endless.require isn't
written yet, sorry.)

require 'endless'
Endless.load 'my-endless-code.rb'


Changes in this release:
Re-worked the way the def keyword is processed, to fix several bugs.
The new way is even a little bit less hacky.
Insert a space before implicit ends

Install:
endless.rb is available as a gist (jest?) on github only:
http://gist.github....

21 Answers

Charles Oliver Nutter

5/29/2009 3:15:00 AM

0

Caleb Clausen wrote:
> endless.rb is a pre-processor for ruby which allows you to use python-ish
> indentation to delimit scopes, instead of having to type 'end' every time.

Oh dear god no!

Seriously though...neat :)

- Charlie

Mohit Sindhwani

5/29/2009 4:29:00 AM

0

Charles Oliver Nutter wrote:
> Caleb Clausen wrote:
>> endless.rb is a pre-processor for ruby which allows you to use
>> python-ish
>> indentation to delimit scopes, instead of having to type 'end' every
>> time.
>
> Oh dear god no!
>
> Seriously though...neat :)

Both my emotions neatly summed up!

Cheers,
Mohit.
5/29/2009 | 12:28 PM.


Clifford Heath

5/29/2009 4:43:00 AM

0

Caleb Clausen wrote:
> To be endless in your own code, you must first require 'endless.rb',
> then load files which are written endlessly using Endless.load, rather
> than the usual plain vanilla load (or require). (Endless.require isn't
> written yet, sorry.)

Ouch. But this is a good candidate for using Polyglot. Just name
your files .rbe, and when you require 'endless', it registers that
extension with Polyglot to be used with the endless loader. Then
you can just "require 'fred'", and it will endless-load "fred.rbe".

Roger Pack

5/29/2009 1:29:00 PM

0


> for i in 1..10 do
> p i
> pp i

wonder if do-less ruby would possible, too
for i in 1..10
p i
pp i

or braceless or something

3.times |n|
puts n


:)
-=r
--
Posted via http://www.ruby-....

Juan Zanos

5/29/2009 4:29:00 PM

0


On May 29, 2009, at 12:46 AM, Clifford Heath wrote:

> Caleb Clausen wrote:
>> To be endless in your own code, you must first require 'endless.rb',
>> then load files which are written endlessly using Endless.load,
>> rather
>> than the usual plain vanilla load (or require). (Endless.require
>> isn't
>> written yet, sorry.)
>
> Ouch. But this is a good candidate for using Polyglot. Just name
> your files .rbe, and when you require 'endless', it registers that
> extension with Polyglot to be used with the endless loader. Then
> you can just "require 'fred'", and it will endless-load "fred.rbe".
>

How would this work? Would endless.rb just load the polyglot gem
and automatically set itself up? So all you'd need to do is require
'endless' and
then make some rbe files?


Caleb Clausen

5/29/2009 5:22:00 PM

0

On 5/28/09, Clifford Heath <no@spam.please.net> wrote:
> Caleb Clausen wrote:
>> To be endless in your own code, you must first require 'endless.rb',
>> then load files which are written endlessly using Endless.load, rather
>> than the usual plain vanilla load (or require). (Endless.require isn't
>> written yet, sorry.)
>
> Ouch. But this is a good candidate for using Polyglot. Just name
> your files .rbe, and when you require 'endless', it registers that
> extension with Polyglot to be used with the endless loader. Then
> you can just "require 'fred'", and it will endless-load "fred.rbe".

This is very interesting, I could use this in RubyMacros as well. But
then that brings up another issue; what if I want to use both at once?
Aside from the trouble of actually getting the two to work together,
how does a user specify that some particular combination of
preprocessors is to be used? Extending your example, I could use .rbm
for files with macros in them, but what about files without ends and
with macros? .rbem? While Polyglot's extension registration system is
nice, I'm wanting something more sophisticated as well.

Michael Bruschkewitz wrote: (in another thread)
> At breakfast I had the idea it would be possible to implement/apply it to current file it by
> simply using
> "require 'tool4endH8ers.rb'" or
> "require 'languageConverter_pyi.rb'" or
> "require 'languageConverter_BASIC.rb'" or
> "require 'languageConverter_f77.rb'" or...
> "require 'applySomeOtherWeirdOptions.rb'" or...
> at the beginning of each file or at the beginning of main file.
> I'm sure some Kernel.magic would make this possible.

I'm not entirely sure, but it seems like he's saying that if you
should be able to require "languageConverter_f77.rb", and then write
the rest of the file in fortran. A bit far-fetched, but I like the
idea of being able to declare the format up at the top of the file,
perhaps with a magic comment.

> Why not think about providing a mechanism which provides this possibility?

Hmm, what about it, Clifford? Seems like an appropriate thing to add
to Polyglot....

PS: the examples on this page got damaged somehow:
http://polyglot.ruby...

Caleb Clausen

5/29/2009 5:23:00 PM

0

On 5/29/09, Roger Pack <rogerpack2005@gmail.com> wrote:
> wonder if do-less ruby would possible, too
> for i in 1..10
> p i
> pp i

You can leave off the do in for, until, and while loops already. I usually do.

> or braceless or something
>
> 3.times |n|
> puts n

(shudder). You realize that that one already parses like:

3.times.|(n).|(puts n)

Suraj Kurapati

5/31/2009 1:30:00 AM

0

Caleb Clausen wrote:
> endless.rb [...] makes the end keyword optional.

I love this idea and already implemented it for eRuby:

http://snk.tuxfamily.org/lib/ember/#Infer-blo...

Where '<% end %>' is more laborious to type than 'end'. :)
--
Posted via http://www.ruby-....

Clifford Heath

5/31/2009 3:01:00 AM

0

Juan Zanos wrote:
>> Ouch. But this is a good candidate for using Polyglot. Just name
>> your files .rbe, and when you require 'endless', it registers that
>> extension with Polyglot to be used with the endless loader. Then
>> you can just "require 'fred'", and it will endless-load "fred.rbe".
> How would this work? Would endless.rb just load the polyglot gem
> and automatically set itself up? So all you'd need to do is require
> 'endless' and then make some rbe files?

Exactly. My ActiveFacts gem implements a language called CQL.
When you require 'activefacts/cql', it does this:

require 'polyglot'
module ActiveFacts
class CQLLoader
def self.load(file)
..
end
end
Polyglot.register('cql', CQLLoader)
end

Now you can require 'fred', and CQLLoader gets to load "fred.cql"
(assuming that "fred.rb" isn't found first). The CQL is translated
into Ruby module and class definitions which are then eval'ed.

Same deal with Treetop. When you require 'treetop', it requires
Polyglot, and does this:

Polyglot.register(["treetop", "tt"], Treetop)

where the Treetop class has a self.load method.

Clifford Heath.

Clifford Heath

5/31/2009 3:15:00 AM

0

Caleb Clausen wrote:
>> Ouch. But this is a good candidate for using Polyglot. Just name
>> your files .rbe, and when you require 'endless', it registers that
>> extension with Polyglot to be used with the endless loader. Then
>> you can just "require 'fred'", and it will endless-load "fred.rbe".
>
> This is very interesting, I could use this in RubyMacros as well. But
> then that brings up another issue; what if I want to use both at once?

I think you'd need to create a custom loader that knows how to load the
file having combined syntax.

When Nathan Sobo created Treetop, one of his hopes was that Ruby
could eventually incorporate PEG parsing technology and add his "rule"
keyword. Because PEG parsers are composable, this would allow you to
define new parse rules within a Ruby program, which would integrate
fully into the existing Ruby grammar, or be used to introduce new
sub-languages that mesh in nicely... My take on that was then to
extend Kernel.require so that each file extension used a different
top-level parse rule *from within the combined grammar*, and you have
a full meta-language framework... That's kinda what Polyglot is about.

It's kinda what you're talking about below, but done "properly".

> Aside from the trouble of actually getting the two to work together,
> how does a user specify that some particular combination of
> preprocessors is to be used? Extending your example, I could use .rbm
> for files with macros in them, but what about files without ends and
> with macros? .rbem? While Polyglot's extension registration system is
> nice, I'm wanting something more sophisticated as well.

Rails went with chained processors, like file.html.erb, etc. Polyglot's
loader isn't currently defined to read the input file and yield content
for a subsequent loader, but chaining like that is a possible extension.

> I'm not entirely sure, but it seems like he's saying that if you
> should be able to require "languageConverter_f77.rb", and then write
> the rest of the file in fortran. A bit far-fetched, but I like the
> idea of being able to declare the format up at the top of the file,
> perhaps with a magic comment.
>
>> Why not think about providing a mechanism which provides this possibility?
>
> Hmm, what about it, Clifford? Seems like an appropriate thing to add
> to Polyglot....

It's certainly possible. How would one loader pass output to the next?
I wouldn't want to create the intermediate content as files.

> PS: the examples on this page got damaged somehow:
> http://polyglot.ruby...

Thanks, I'll look at it.

Clifford Heath.