getTokenByString method
this functions initiates the starting properties of a token , rest of the properties are calculated on basis of previous and next token
Implementation
Token getTokenByString(String value) {
if (RegexCollection.isString(value)) {
// String found
return Token(value, TokenTypes.string, false);
} else if (RegexCollection.isComment(value)) {
//comment found
if (RegexCollection.isSingleLineComment(value)) {
return Token(value, TokenTypes.comment, false);
} else {
return Token(value, TokenTypes.multilineComment, false);
}
} else if (RegexCollection.isNumber(value)) {
//number found
return Token(value, TokenTypes.number, false);
} else if (RegexCollection.isIdentifier(value)) {
if (ReservedWords.isReservedWord(reservedWordSets, value)) {
// keyword found
return Token(value, TokenTypes.keyword, false);
} else if (RegexCollection.isTitle(value)) {
// class/constructor found
return Token(value, TokenTypes.classType, true);
} else {
// identifier found
return Token(value, TokenTypes.identifier, false);
}
} else if (RegexCollection.isOperator(value)) {
//operator found
return Token(value, TokenTypes.operator, false);
} else {
// separator found
return Token(value, TokenTypes.separator, false);
}
}