parse method
Implementation
List<Todo> parse() {
List<Todo> todos = [];
TokenIterator iterator = TokenIterator(tokens);
while (iterator.hasNext()) {
try {
throwErrorIfDoesntMatch(iterator, TokenKind.openingSquareBracket);
iterator.moveNext();
bool wasPosted = false;
if (match(iterator, TokenKind.tilde)) {
wasPosted = true;
iterator.moveNext();
}
throwErrorIfDoesntMatch(iterator, TokenKind.closingSquareBracket);
iterator.moveNext();
throwErrorIfDoesntMatch(iterator, TokenKind.colon);
iterator.moveNext();
throwErrorIfDoesntMatch(iterator, TokenKind.issueText);
String issueTitle = iterator.current.lexeme;
iterator.moveNext();
String issueBodyText = "";
if (match(iterator, TokenKind.issueText)) {
issueBodyText = iterator.current.lexeme;
iterator.moveNext();
}
List<String> labels = [];
if (match(iterator, TokenKind.openingCurlyBrace)) {
labels = parseLabels(iterator);
}
throwErrorIfDoesntMatch(iterator, TokenKind.semicolon);
if (iterator.hasNext()) iterator.moveNext();
final todo = Todo(
wasPosted: wasPosted,
title: issueTitle,
body: issueBodyText,
labels: labels,
);
todos.add(todo);
} catch (error) {
rethrow;
}
}
return todos;
}