how to get all the reserved words? 
Author Message
 how to get all the reserved words?

Hi;

how can I get all the reserved words, like
   begin
   in
   end
etc.?

TIA,

Tobi
--
http://www.*-*-*.com/



Sat, 03 Jul 2004 23:51:59 GMT  
 how to get all the reserved words?

Quote:

> how can I get all the reserved words,[...]

If there is no way (global var, method, etc.) to get a list of all
reserved words, then another question:

What's missing in the following list?
(considering all versions of Ruby, even planned ones)

   reserved_words = [
    'BEGIN',  'END',   'alias',  'and',      'begin',
    'break',  'case',  'class',  'def',      'defined?',
    'do',     'else',  'elsif',  'end',      'module',
    'ensure', 'false', 'for',    'if',       'in',
    'next',   'nil',   'not',    'or',       'redo',
    'rescue', 'retry', 'return', 'self',     'super',
    'then',   'true',  'undef',  'unless',   'until',
    'when',   'while', 'yield',  '__FILE__', '__LINE__'
      ]

Tobi

--
http://www.pinkjuice.com/



Sun, 04 Jul 2004 02:59:41 GMT  
 how to get all the reserved words?

Quote:
----- Original Message -----


Sent: Tuesday, January 15, 2002 12:58 PM
Subject: Re: how to get all the reserved words?

> What's missing in the following list?
> (considering all versions of Ruby, even planned ones)

>    reserved_words = [
>     'BEGIN',  'END',   'alias',  'and',      'begin',
>     'break',  'case',  'class',  'def',      'defined?',
>     'do',     'else',  'elsif',  'end',      'module',
>     'ensure', 'false', 'for',    'if',       'in',
>     'next',   'nil',   'not',    'or',       'redo',
>     'rescue', 'retry', 'return', 'self',     'super',
>     'then',   'true',  'undef',  'unless',   'until',
>     'when',   'while', 'yield',  '__FILE__', '__LINE__'
>       ]

Here is my list. (I think yours has some that are not
really reserved, such as __FILE__.)

     BEGIN END alias and begin
     break case class def defined
     do else elsif end ensure
     false for if in module
     next nil not or redo
     rescue retry return self super
     then true undef unless until
     when while yield

Actually, I'm questioning nil, true, and false also;
but they've been in my list forever. Someone care
to comment?

Of course, even a reserved word isn't really reserved.
For example, you can define a method called "in"
if you wish. It's a matter of context.

Hal



Sun, 04 Jul 2004 03:15:53 GMT  
 how to get all the reserved words?

Quote:

> Here is my list. (I think yours has some that are not
> really reserved, such as __FILE__.)

Hmm; they are included in the list in RiaN, p9.

Quote:
>   break case class def defined

should that be "defined?" ?

Quote:
> Actually, I'm questioning nil, true, and false also;

Why? (I think they are reserved words, and RiaN includes them in the list.)

Quote:
> Of course, even a reserved word isn't really reserved.
> For example, you can define a method called "in"
> if you wish. It's a matter of context.

In a generated set of classes with sets of methods, Ruby choked on
method names "in", "begin", and "end" (could also have been "in=" etc.),
so I simply avoid anything that could cause trouble, and use different
names where collisions could occur.

RiaN says: "These reserved word may not be used as constant or local
variable names. They can, however, be used as method names if a receiver
is specified."
Can anyone provide examples for this?

Tobi

--
http://www.pinkjuice.com/



Sun, 04 Jul 2004 04:03:53 GMT  
 how to get all the reserved words?

Quote:

> In a generated set of classes with sets of methods, Ruby choked on
> method names "in", "begin", and "end" (could also have been "in=" etc.),
> so I simply avoid anything that could cause trouble, and use different
> names where collisions could occur.

def $:

and all also give parse error, so I have to check for those too.

Tobi

--
http://www.pinkjuice.com/



Sun, 04 Jul 2004 06:49:13 GMT  
 how to get all the reserved words?

Quote:
----- Original Message -----


Sent: Tuesday, January 15, 2002 2:02 PM
Subject: Re: how to get all the reserved words?

> > Here is my list. (I think yours has some that are not
> > really reserved, such as __FILE__.)

> Hmm; they are included in the list in RiaN, p9.

OK, I was working from an older doc... obviously
Matz's book supersedes anything I have to say.

Quote:
> >   break case class def defined

> should that be "defined?" ?

Yes... I guess so. I'm always confused as to whether
the ? is a real part of a word or just a suffix.

Quote:
> > Actually, I'm questioning nil, true, and false also;
> Why? (I think they are reserved words, and RiaN includes them in the

list.)

I read something that classified these as pseudo-
variables... we usually don't think of variables as
reserved words, do we? (My old Pascal background
is showing, perhaps -- I always distinguished sharply
between reserved words and predefined identifiers.)

But again, I don't have _RiaN_ yet... I am sure that
(barring possible minor errors) it is authoritative.

Quote:
> > Of course, even a reserved word isn't really reserved.
> > For example, you can define a method called "in"
> > if you wish. It's a matter of context.

> In a generated set of classes with sets of methods, Ruby choked on
> method names "in", "begin", and "end" (could also have been "in=" etc.),
> so I simply avoid anything that could cause trouble, and use different
> names where collisions could occur.

> RiaN says: "These reserved word may not be used as constant or local
> variable names. They can, however, be used as method names if a receiver
> is specified."
> Can anyone provide examples for this?

Here's one little example. Works for me on 1.6.1 -- doesn't it work
for you?

  class MyClass
    def begin
      puts "Hello"
    end
  end

  obj = MyClass.new
  obj.begin

Hal Fulton



Sun, 04 Jul 2004 06:54:37 GMT  
 how to get all the reserved words?

Quote:

> Here's one little example. Works for me on 1.6.1 -- doesn't it work
> for you?

>   class MyClass
>     def begin
>       puts "Hello"
>     end
>   end

>   obj = MyClass.new
>   obj.begin

It does; but this doesn't:

def begin= val
end

; it gives
parse error
def begin= val
           ^

(which is OK with me ;) )

Tobi

--
http://www.pinkjuice.com/



Sun, 04 Jul 2004 07:10:37 GMT  
 how to get all the reserved words?

...

Quote:
> It does; but this doesn't:

> def begin= val
> end

> ; it gives
> parse error
> def begin= val
>            ^

This would be
----
class Object


end
self.begin= "end"
p (self.begin) # => end
----

/Christoph



Sun, 04 Jul 2004 16:34:29 GMT  
 how to get all the reserved words?
Hi,

At Wed, 16 Jan 2002 00:49:13 +0900,

Quote:

> how can I get all the reserved words, like
>    begin
>    in
>    end
> etc.?

See the `keywords' file.

--
Nobu Nakada



Sun, 04 Jul 2004 12:06:41 GMT  
 how to get all the reserved words?

Quote:

> This would be
> ----
> class Object


> end
> self.begin= "end"
> p (self.begin) # => end
> ----

Could you explain what you mean here?

In
ruby 1.6.5 (2001-09-19) [i386-cygwin]
this gives parse errors as well:
---
delete.rb:7: parse error

             ^
delete.rb:8: nested method definition

            ^
delete.rb:9: parse error

---

Tobi

--
http://www.pinkjuice.com/



Sun, 04 Jul 2004 15:39:25 GMT  
 how to get all the reserved words?

Quote:

> See the `keywords' file.

I can't find it in my PragProg tree.

Perhaps you could post it, if it's not too long?



?

TIA,

Tobi
--
http://www.pinkjuice.com/



Sun, 04 Jul 2004 15:55:23 GMT  
 how to get all the reserved words?
Hi,

In message "Re: how to get all the reserved words?"

|> See the `keywords' file.
|
|
|I can't find it in my PragProg tree.
|Perhaps you could post it, if it's not too long?

If you have ruby source distribution, it's in it.

                                                        matz.



Sun, 04 Jul 2004 16:11:24 GMT  
 how to get all the reserved words?
[keywords file]

Quote:

> If you have ruby source distribution, it's in it.

Got it; thanks :)

Tobi

--
http://www.pinkjuice.com/



Sun, 04 Jul 2004 16:16:45 GMT  
 how to get all the reserved words?
It would be great if this array would be available from some predef
global var or constant.
Here's what I extracted from
ruby-1.6.6/keywords:

keywords = [
'__LINE__', '__FILE__', 'BEGIN',  'END',   'alias',
'and',      'begin',    'break',  'case',  'class',
'def',      'defined?', 'do',     'else',  'elsif',
'end',      'ensure',   'false',  'for',   'if',
'in',       'module',   'next',   'nil',   'not',
'or',       'redo',     'rescue', 'retry', 'return',
'self',     'super',    'then',   'true',  'undef',
'unless',   'until',    'when',   'while', 'yield'
]

Tobi

--
http://www.pinkjuice.com/



Sun, 04 Jul 2004 16:27:21 GMT  
 how to get all the reserved words?

...

Quote:
> delete.rb:7: parse error

>              ^
> delete.rb:8: nested method definition

>             ^
> delete.rb:9: parse error

yes I get the same (sorry I should have checked this), but
it works with a newer 1.7.2 version - which sort seems
``more correct'' to me

/Christoph



Mon, 05 Jul 2004 09:26:56 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Problem with reserved words in column names.

2. Reserved words in JCL

3. PB 3.5 Reserved Words List?

4. Obtaining a list of Clarion Reserved Words

5. Reserved word ?

6. CW4 - Reserved Words

7. xbase to clarion with reserved word as xbase variable

8. Reserved Words (2)

9. Reserved words

10. 359 Reserved Words and No Syntax

11. Reserved Words and Functions

12. VO2 - BEWARE Reserved words!

 

 
Powered by phpBB® Forum Software