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 { enum Token {
SLASH("/"), COMMA(","), EOL(), WS, TEXT, SLASH("/"), COMMA(","), EOL(), WS, TEXT,
LESS("<"), MORE(">"), EQUALS("="), LESS("<"), MORE(">"), EQUALS("="), NOT_EQUALS("!="),
WHERE, NOT, AND, OR, RETURN; WHERE, NOT, AND, OR, RETURN;
@Override @Override
@ -73,6 +73,8 @@ class Scanner {
case '=' : case '=' :
nextChar(); nextChar();
return Token.EQUALS; return Token.EQUALS;
case '!' :
return notEquals();
case '"' : case '"' :
return quotedText('"'); return quotedText('"');
case '\'' : case '\'' :
@ -133,6 +135,15 @@ class Scanner {
return Token.WS; 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 */ /** return the next character from the line of text */
private void nextChar() { private void nextChar() {
if (pos < line.length()) { if (pos < line.length()) {