1

There is a lot of great information on this SO thread

I can grab the keywords from websites provided there, BUT I am asking is it possible to grab reserved keywords in real time ? Maybe there is some structure where they are stored?

For global objects in window, I can grab them with this:

for(var i in window) doSomethingWith(i)

But I also need all the language specific keywords like: if, case, switch, etc.

SORRY I didn't want to write "then". I was coding in Pascal in the last hour(remembering old times) and god damn it stuck into my head!

What I want to do: It may sound strange, however I am building an app where you can create elements, they have names, values, formulas and formulas are pure JS formulas, except I run a regular expression to modify variables a bit and want to leave the javascript syntax.

For example if formula is: if (a < b) { c = d; } In this case I would like to modify only a, b, c and d.

If formula would be something like: switch(a) { case 0: a=b; break; case 1: b=c; ... } In this case I would like to filter out "switch, break, case".

Well maybe I should delete this question

Community
  • 1
  • 1
lukas.pukenis
  • 13,057
  • 12
  • 47
  • 81

2 Answers2

2

Well, if you google "javascript reserved words" you get this:

abstract (*)
as (2)
boolean
break
byte
case
catch
char
class (2)
continue
const (2)
debugger (*)
default
delete
do
double
else
enum (*)
export (2)
extends (2)
false
final
finally
float
for
function
goto (*)
if
implements (*)
import (2)
in
instanceof
int
interface (2)
is (2)
long
namespace (2)
native (*)
new
null
package (2)
private (2)
protected (*)
public (2)
return
short
static (2)
super (2)
switch
synchronized (*)
this
throw
throws (*)
transient (*)
true
try
typeof
use (2)
var
void
volatile (*)
while
with

Source: http://javascript.about.com/library/blreserved.htm

I'm not sure what you mean by "grab" them, but you could put all those words in an array and search for each element of the array in a block of text...

jahroy
  • 22,322
  • 9
  • 59
  • 108
  • That's perfect, however there's no keyword like "then" in here. I would like to have them all – lukas.pukenis May 22 '12 at 20:15
  • 1
    @lukas.pukenis - I didn't know "then" was a keyword. According to that reference (which is supposed to include keywords that haven't even been implemented yet), it is not a keyword. – jahroy May 22 '12 at 20:16
  • well, yes, not a keyword, however a reserved word – lukas.pukenis May 22 '12 at 20:17
  • @lukas.pukenis - Not sure why it is "reserved" in your opinion. If you have some words that you want to reserve for your own reasons, you could add them to the array. Here's an even better reference with more "special" words. It does NOT include "then" either. – jahroy May 22 '12 at 20:19
1

A quick search on the tubes (you should always google first) came up with this bit of code I would never expect to see, a reserved word checker. I didn't even try playing with it, so don't know if its right or not.

https://github.com/revolution42/Javascript-Reserved-Word-Checker/blob/master/checker.js
Limey
  • 2,642
  • 6
  • 37
  • 62