|
|
@ -33,7 +33,7 @@ var Stream = (function() { |
|
|
|
lookChar: function() { |
|
|
|
lookChar: function() { |
|
|
|
var bytes = this.bytes; |
|
|
|
var bytes = this.bytes; |
|
|
|
if (this.pos >= bytes.length) |
|
|
|
if (this.pos >= bytes.length) |
|
|
|
return EOF; |
|
|
|
return; |
|
|
|
return String.fromCharCode(bytes[this.pos]); |
|
|
|
return String.fromCharCode(bytes[this.pos]); |
|
|
|
}, |
|
|
|
}, |
|
|
|
getChar: function() { |
|
|
|
getChar: function() { |
|
|
@ -53,8 +53,6 @@ var Stream = (function() { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
constructor.EOF = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return constructor; |
|
|
|
return constructor; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -189,7 +187,7 @@ var Lexer = (function() { |
|
|
|
var stream = this.stream; |
|
|
|
var stream = this.stream; |
|
|
|
do { |
|
|
|
do { |
|
|
|
switch (ch = stream.getChar()) { |
|
|
|
switch (ch = stream.getChar()) { |
|
|
|
case EOF: |
|
|
|
case undefined: |
|
|
|
this.error("Unterminated string"); |
|
|
|
this.error("Unterminated string"); |
|
|
|
done = true; |
|
|
|
done = true; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -206,6 +204,10 @@ var Lexer = (function() { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case '\\': |
|
|
|
case '\\': |
|
|
|
switch (ch = stream.getChar()) { |
|
|
|
switch (ch = stream.getChar()) { |
|
|
|
|
|
|
|
case undefined: |
|
|
|
|
|
|
|
this.error("Unterminated string"); |
|
|
|
|
|
|
|
done = true; |
|
|
|
|
|
|
|
break; |
|
|
|
case 'n': |
|
|
|
case 'n': |
|
|
|
str += '\n'; |
|
|
|
str += '\n'; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -248,10 +250,6 @@ var Lexer = (function() { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case '\n': |
|
|
|
case '\n': |
|
|
|
break; |
|
|
|
break; |
|
|
|
case EOF: |
|
|
|
|
|
|
|
this.error("Unterminated string"); |
|
|
|
|
|
|
|
done = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
str += ch; |
|
|
|
str += ch; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -269,7 +267,7 @@ var Lexer = (function() { |
|
|
|
getName: function(ch) { |
|
|
|
getName: function(ch) { |
|
|
|
var str = ""; |
|
|
|
var str = ""; |
|
|
|
var stream = this.stream; |
|
|
|
var stream = this.stream; |
|
|
|
while ((ch = stream.lookChar()) != EOF && !specialChars[ch.toCharCode()]) { |
|
|
|
while (!!(ch = stream.lookChar()) && !specialChars[ch.toCharCode()]) { |
|
|
|
stream.getChar(); |
|
|
|
stream.getChar(); |
|
|
|
if (ch == "#") { |
|
|
|
if (ch == "#") { |
|
|
|
ch = stream.lookChar(); |
|
|
|
ch = stream.lookChar(); |
|
|
@ -299,7 +297,7 @@ var Lexer = (function() { |
|
|
|
ch = stream.getChar(); |
|
|
|
ch = stream.getChar(); |
|
|
|
if (ch == '>') { |
|
|
|
if (ch == '>') { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} else if (ch == EOF) { |
|
|
|
} else if (!ch) { |
|
|
|
this.error("Unterminated hex string"); |
|
|
|
this.error("Unterminated hex string"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} else if (specialChars[ch.toCharCode()] != 1) { |
|
|
|
} else if (specialChars[ch.toCharCode()] != 1) { |
|
|
@ -320,7 +318,7 @@ var Lexer = (function() { |
|
|
|
var stream = this.stream; |
|
|
|
var stream = this.stream; |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
var ch; |
|
|
|
var ch; |
|
|
|
if ((ch = stream.getChar()) == EOF) |
|
|
|
if (!(ch = stream.getChar())) |
|
|
|
return new Obj(Object.EOF); |
|
|
|
return new Obj(Object.EOF); |
|
|
|
if (comment) { |
|
|
|
if (comment) { |
|
|
|
if (ch == '\r' || ch == '\n') |
|
|
|
if (ch == '\r' || ch == '\n') |
|
|
@ -372,7 +370,7 @@ var Lexer = (function() { |
|
|
|
|
|
|
|
|
|
|
|
// command
|
|
|
|
// command
|
|
|
|
var str = ch; |
|
|
|
var str = ch; |
|
|
|
while ((ch = stream.lookChar()) != EOF && !specialChars[ch.toCharCode()]) { |
|
|
|
while (!!(ch = stream.lookChar()) && !specialChars[ch.toCharCode()]) { |
|
|
|
stream.getChar(); |
|
|
|
stream.getChar(); |
|
|
|
if (str.length == 128) { |
|
|
|
if (str.length == 128) { |
|
|
|
error("Command token too long"); |
|
|
|
error("Command token too long"); |
|
|
|