public Token Scan (bool recognizeDash = false)
{
int start = pos;
if (s == null)
return new Token (Token.Type.Error, 0, 0);
Token.Type ttype;
if (pos >= s.Length) {
ttype = Token.Type.End;
} else {
ttype = Token.Type.Error;
start:
char ch = s[pos++];
switch (ch) {
case ' ':
case '\t':
if (pos == s.Length) {
ttype = Token.Type.End;
break;
}
goto start;
case '=':
ttype = Token.Type.SeparatorEqual;
break;
case ';':
ttype = Token.Type.SeparatorSemicolon;
break;
case '/':
ttype = Token.Type.SeparatorSlash;
break;
case '-':
if (recognizeDash) {
ttype = Token.Type.SeparatorDash;
break;
}
goto default;
case ',':
ttype = Token.Type.SeparatorComma;
break;
case '"':
// Quoted string
start = pos - 1;
while (pos < s.Length) {
ch = s [pos++];
if (ch == '"') {
ttype = Token.Type.QuotedString;
break;
}
}
break;
case '(':
start = pos - 1;
ttype = Token.Type.OpenParens;
break;
default:
if (ch < last_token_char && token_chars[ch]) {
start = pos - 1;
ttype = Token.Type.Token;
while (pos < s.Length) {
ch = s[pos];
if (ch >= last_token_char || !token_chars[ch]) {
break;
}
++pos;
}
}
break;
}
}
return new Token (ttype, start, pos);
}
}