start separating validation from parsing

This commit is contained in:
Dave Holoway
2020-06-16 12:59:08 +01:00
parent 1801a81c0f
commit b050f3a82d
4 changed files with 217 additions and 1039 deletions

View File

@@ -57,6 +57,19 @@ class TokenList {
return token;
}
/**
* Check if the current token matches the specified kind, returns and consumes it
* @param {string} kind
*/
getIfKind(kind) {
const token = this.current;
if (token && token.kind === kind) {
this.inc();
return token;
}
return null;
}
/**
* Check if the current token matches the specified value, returns and consumes it
* @param {string} value
@@ -83,11 +96,7 @@ class TokenList {
* @param {string} kind
*/
isKind(kind) {
if (this.current && this.current.kind === kind) {
this.inc();
return true;
}
return false;
return this.getIfKind(kind) !== null;
}
/**