// symbol

function Symbol (name) {
    this.name = name;
}
exports.Symbol = Symbol;

Symbol.escaped = {
    '-': 'MINUS', '+': 'PLUS', '!': 'BANG', '?': 'WHAT', '%': 'PERCENT',
    '#': 'HASH', '@': 'AT', '*': 'STAR', '/': 'SLASH', '=': 'EQUALS',
    ':': 'COLON', '<': 'LESSTHAN', '>': 'GREATERTHAN'
}

Symbol.reserved = [
    "break", "case", "catch", "continue", "default", "delete", "do", "else",
    "finally", "for", "function", "if", "in", "instanceof", "new", "return",
    "switch", "this", "throw", "try", "typeof", "var", "void", "while",
    "with", "abstract", "boolean", "byte", "char", "class", "const",
    "debugger", "double", "enum", "export", "extends", "final", "float",
    "goto", "implements", "import", "int", "interface", "long", "native",
    "package", "private", "protected", "public", "short", "static", "super",
    "synchronized", "throws", "transient", "volatile", "null", "true", "false",
    'arguments'
];

Symbol.prototype.escape = function () {
    if (Symbol.reserved.indexOf(this.name) >= 0) {
	return '_' + this.name;
    } else {
	var result = '';
	var up = false;
	for (var i = 0; i < this.name.length; i++) {
	    var c = this.name[i];
	    if (c != '-') {
		if (up)
		    result += c.toUpperCase();
		else if (Symbol.escaped.hasOwnProperty(c))
		    result += Symbol.escaped[c];
		else
		    result += c;
	    } else if (i == (this.name.length - 1)) {
		result += Symbol.escaped[c];
	    }
	    up = (c == '-');
	}
	return result;
    }
}

Symbol.prototype.toString = function () {
    return this.escape();
}

// hash symbols

var HashSymbol = function (name) {
    this.name = name;
}
exports.HashSymbol = HashSymbol;

HashSymbol.names = ['key', 'rest', 'values'];

HashSymbol.names.forEach(function (hashSymbol) {
    HashSymbol[hashSymbol] = new HashSymbol(hashSymbol);
});

/* TODO: into own namespace?
HashSymbol.prototype.toString = function () {
    return 'HashSymbol.' + this.name;
}
*/
@@ -112,13 +112,11 @@
 ': '
-MINUS
+_M_
 ', '
@@ -124,12 +124,12 @@
 ': '
+_
 PL
-US
+_
 ', '
@@ -137,12 +137,11 @@
 ': '
-BANG
+_B_
 ', '
@@ -149,12 +149,11 @@
 ': '
-WHAT
+_W_
 ', '
@@ -161,15 +161,12 @@
 ': '
+_
 PE
-RCENT
+_
 ',%0A 
@@ -178,12 +178,11 @@
 ': '
-HASH
+_H_
 ', '
@@ -186,18 +186,19 @@
 , '@': '
-AT
+_A_
 ', '*': 
@@ -202,12 +202,12 @@
 ': '
+_
 ST
-AR
+_
 ', '
@@ -215,13 +215,12 @@
 ': '
+_
 SL
-ASH
+_
 ', '
@@ -228,14 +228,11 @@
 ': '
-EQUALS
+_E_
 ',%0A 
@@ -244,13 +244,11 @@
 ': '
-COLON
+_C_
 ', '
@@ -256,16 +256,12 @@
 ': '
-LESSTHAN
+_LT_
 ', '
@@ -269,19 +269,23 @@
 ': '
-GREATERTHAN
+_GT_', '_': '__
 '%0A%7D%0A

shorter escape sequences; escape '_'