|
@@ -2,6 +2,7 @@ using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
+using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Text.RegularExpressions;
|
|
using Jint.Parser.Ast;
|
|
using Jint.Parser.Ast;
|
|
|
|
|
|
@@ -388,7 +389,7 @@ namespace Jint.Parser
|
|
private string GetEscapedIdentifier()
|
|
private string GetEscapedIdentifier()
|
|
{
|
|
{
|
|
char ch = _source.CharCodeAt(_index++);
|
|
char ch = _source.CharCodeAt(_index++);
|
|
- string id = ch.ToString();
|
|
|
|
|
|
+ var id = new StringBuilder(ch.ToString());
|
|
|
|
|
|
// '\u' (char #92, char #117) denotes an escaped character.
|
|
// '\u' (char #92, char #117) denotes an escaped character.
|
|
if (ch == 92)
|
|
if (ch == 92)
|
|
@@ -403,7 +404,7 @@ namespace Jint.Parser
|
|
{
|
|
{
|
|
ThrowError(null, Messages.UnexpectedToken, "ILLEGAL");
|
|
ThrowError(null, Messages.UnexpectedToken, "ILLEGAL");
|
|
}
|
|
}
|
|
- id = ch.ToString();
|
|
|
|
|
|
+ id = new StringBuilder(ch.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
while (_index < _length)
|
|
while (_index < _length)
|
|
@@ -414,12 +415,11 @@ namespace Jint.Parser
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
++_index;
|
|
++_index;
|
|
- id += ch.ToString();
|
|
|
|
|
|
+
|
|
|
|
|
|
// '\u' (char #92, char #117) denotes an escaped character.
|
|
// '\u' (char #92, char #117) denotes an escaped character.
|
|
if (ch == 92)
|
|
if (ch == 92)
|
|
{
|
|
{
|
|
- id = id.Substring(0, id.Length - 1);
|
|
|
|
if (_source.CharCodeAt(_index) != 117)
|
|
if (_source.CharCodeAt(_index) != 117)
|
|
{
|
|
{
|
|
ThrowError(null, Messages.UnexpectedToken, "ILLEGAL");
|
|
ThrowError(null, Messages.UnexpectedToken, "ILLEGAL");
|
|
@@ -430,11 +430,15 @@ namespace Jint.Parser
|
|
{
|
|
{
|
|
ThrowError(null, Messages.UnexpectedToken, "ILLEGAL");
|
|
ThrowError(null, Messages.UnexpectedToken, "ILLEGAL");
|
|
}
|
|
}
|
|
- id += ch.ToString();
|
|
|
|
|
|
+ id.Append(ch);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ id.Append(ch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return id;
|
|
|
|
|
|
+ return id.ToString();
|
|
}
|
|
}
|
|
|
|
|
|
private string GetIdentifier()
|
|
private string GetIdentifier()
|
|
@@ -864,7 +868,7 @@ namespace Jint.Parser
|
|
|
|
|
|
private Token ScanStringLiteral()
|
|
private Token ScanStringLiteral()
|
|
{
|
|
{
|
|
- string str = "";
|
|
|
|
|
|
+ var str = new StringBuilder();
|
|
bool octal = false;
|
|
bool octal = false;
|
|
|
|
|
|
char quote = _source.CharCodeAt(_index);
|
|
char quote = _source.CharCodeAt(_index);
|
|
@@ -890,13 +894,13 @@ namespace Jint.Parser
|
|
switch (ch)
|
|
switch (ch)
|
|
{
|
|
{
|
|
case 'n':
|
|
case 'n':
|
|
- str += '\n';
|
|
|
|
|
|
+ str.Append('\n');
|
|
break;
|
|
break;
|
|
case 'r':
|
|
case 'r':
|
|
- str += '\r';
|
|
|
|
|
|
+ str.Append('\r');
|
|
break;
|
|
break;
|
|
case 't':
|
|
case 't':
|
|
- str += '\t';
|
|
|
|
|
|
+ str.Append('\t');
|
|
break;
|
|
break;
|
|
case 'u':
|
|
case 'u':
|
|
case 'x':
|
|
case 'x':
|
|
@@ -904,22 +908,22 @@ namespace Jint.Parser
|
|
char unescaped;
|
|
char unescaped;
|
|
if(ScanHexEscape(ch, out unescaped))
|
|
if(ScanHexEscape(ch, out unescaped))
|
|
{
|
|
{
|
|
- str += unescaped.ToString();
|
|
|
|
|
|
+ str.Append(unescaped);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
_index = restore;
|
|
_index = restore;
|
|
- str += ch.ToString();
|
|
|
|
|
|
+ str.Append(ch);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case 'b':
|
|
case 'b':
|
|
- str += "\b";
|
|
|
|
|
|
+ str.Append("\b");
|
|
break;
|
|
break;
|
|
case 'f':
|
|
case 'f':
|
|
- str += "\f";
|
|
|
|
|
|
+ str.Append("\f");
|
|
break;
|
|
break;
|
|
case 'v':
|
|
case 'v':
|
|
- str += "\x0B";
|
|
|
|
|
|
+ str.Append("\x0B");
|
|
break;
|
|
break;
|
|
|
|
|
|
default:
|
|
default:
|
|
@@ -947,11 +951,11 @@ namespace Jint.Parser
|
|
code = code * 8 + "01234567".IndexOf(_source.CharCodeAt(_index++));
|
|
code = code * 8 + "01234567".IndexOf(_source.CharCodeAt(_index++));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- str += ((char)code).ToString();
|
|
|
|
|
|
+ str.Append((char)code);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- str += ch.ToString();
|
|
|
|
|
|
+ str.Append(ch);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -971,7 +975,7 @@ namespace Jint.Parser
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- str += ch.ToString();
|
|
|
|
|
|
+ str.Append(ch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -983,7 +987,7 @@ namespace Jint.Parser
|
|
return new Token
|
|
return new Token
|
|
{
|
|
{
|
|
Type = Tokens.StringLiteral,
|
|
Type = Tokens.StringLiteral,
|
|
- Value = str,
|
|
|
|
|
|
+ Value = str.ToString(),
|
|
Octal = octal,
|
|
Octal = octal,
|
|
LineNumber = _lineNumber,
|
|
LineNumber = _lineNumber,
|
|
LineStart = _lineStart,
|
|
LineStart = _lineStart,
|
|
@@ -1001,13 +1005,13 @@ namespace Jint.Parser
|
|
int start = _index;
|
|
int start = _index;
|
|
char ch;
|
|
char ch;
|
|
|
|
|
|
- string str = _source.CharCodeAt(_index++).ToString();
|
|
|
|
|
|
+ var str = new StringBuilder(_source.CharCodeAt(_index++).ToString());
|
|
|
|
|
|
while (_index < _length)
|
|
while (_index < _length)
|
|
{
|
|
{
|
|
ch = _source.CharCodeAt(_index++);
|
|
ch = _source.CharCodeAt(_index++);
|
|
|
|
|
|
- str += ch.ToString();
|
|
|
|
|
|
+ str.Append(ch);
|
|
if (ch == '\\')
|
|
if (ch == '\\')
|
|
{
|
|
{
|
|
ch = _source.CharCodeAt(_index++);
|
|
ch = _source.CharCodeAt(_index++);
|
|
@@ -1016,7 +1020,7 @@ namespace Jint.Parser
|
|
{
|
|
{
|
|
ThrowError(null, Messages.UnterminatedRegExp);
|
|
ThrowError(null, Messages.UnterminatedRegExp);
|
|
}
|
|
}
|
|
- str += ch.ToString();
|
|
|
|
|
|
+ str.Append(ch);
|
|
}
|
|
}
|
|
else if (IsLineTerminator(ch))
|
|
else if (IsLineTerminator(ch))
|
|
{
|
|
{
|
|
@@ -1050,7 +1054,7 @@ namespace Jint.Parser
|
|
}
|
|
}
|
|
|
|
|
|
// Exclude leading and trailing slash.
|
|
// Exclude leading and trailing slash.
|
|
- string pattern = str.Substring(1, str.Length - 2);
|
|
|
|
|
|
+ string pattern = str.ToString().Substring(1, str.Length - 2);
|
|
|
|
|
|
string flags = "";
|
|
string flags = "";
|
|
while (_index < _length)
|
|
while (_index < _length)
|
|
@@ -1072,27 +1076,27 @@ namespace Jint.Parser
|
|
if(ScanHexEscape('u', out ch))
|
|
if(ScanHexEscape('u', out ch))
|
|
{
|
|
{
|
|
flags += ch.ToString();
|
|
flags += ch.ToString();
|
|
- for (str += "\\u"; restore < _index; ++restore)
|
|
|
|
|
|
+ for (str.Append("\\u"); restore < _index; ++restore)
|
|
{
|
|
{
|
|
- str += _source.CharCodeAt(restore).ToString();
|
|
|
|
|
|
+ str.Append(_source.CharCodeAt(restore).ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
_index = restore;
|
|
_index = restore;
|
|
flags += "u";
|
|
flags += "u";
|
|
- str += "\\u";
|
|
|
|
|
|
+ str.Append("\\u");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- str += "\\";
|
|
|
|
|
|
+ str.Append("\\");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
flags += ch.ToString();
|
|
flags += ch.ToString();
|
|
- str += ch.ToString();
|
|
|
|
|
|
+ str.Append(ch.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1101,7 +1105,7 @@ namespace Jint.Parser
|
|
return new Token
|
|
return new Token
|
|
{
|
|
{
|
|
Type = Tokens.RegularExpression,
|
|
Type = Tokens.RegularExpression,
|
|
- Literal = str,
|
|
|
|
|
|
+ Literal = str.ToString(),
|
|
Value = pattern + flags,
|
|
Value = pattern + flags,
|
|
Range = new[] {start, _index}
|
|
Range = new[] {start, _index}
|
|
};
|
|
};
|