Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc tokenizeString(expression: string): seq[Token] =
- if len(expression) == 0:
- raise newException(ValueError, "Expression cannot be empty.")
- var
- tokens: seq[Token] = @[]
- startIndex: int = 0
- while startIndex < len(expression):
- endIndex = len(expression) - 1
- var foundToken: bool = false
- while endIndex >= startIndex && !foundToken:
- var token: Token = parseToken(expression[startIndex..endIndex])
- if token.tokenType != TokenType.Invalid:
- startIndex = endIndex + 1
- tokens.add(token)
- foundToken = true
- endIndex++
- if !foundToken: <-- Invalid Indentation Here
- raise newException(ValueError, "Expression has an invalid token at " & startIndex)
- return tokens
Add Comment
Please, Sign In to add comment