Added != support to scanner. #11

This commit is contained in:
Gideon le Grange 2014-10-07 11:18:27 +02:00
parent 91b95e8466
commit 196131dac1
1 changed files with 12 additions and 1 deletions

View File

@ -24,7 +24,7 @@ class Scanner {
enum Token {
SLASH("/"), COMMA(","), EOL(), WS, TEXT,
LESS("<"), MORE(">"), EQUALS("="),
LESS("<"), MORE(">"), EQUALS("="), NOT_EQUALS("!="),
WHERE, NOT, AND, OR, RETURN;
@Override
@ -73,6 +73,8 @@ class Scanner {
case '=' :
nextChar();
return Token.EQUALS;
case '!' :
return notEquals();
case '"' :
return quotedText('"');
case '\'' :
@ -133,6 +135,15 @@ class Scanner {
return Token.WS;
}
/** process the not equals token */
private Token notEquals() throws ScanException {
nextChar(); // eat the !
if (c != '=') {
throw new ScanException(String.format("Expected = after !, found '%c'", c));
}
return Token.NOT_EQUALS;
}
/** return the next character from the line of text */
private void nextChar() {
if (pos < line.length()) {