Guest User

Untitled

a guest
May 4th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.86 KB | None | 0 0
  1. proc tokenizeString(expression: string): seq[Token] =
  2.     if len(expression) == 0:
  3.         raise newException(ValueError, "Expression cannot be empty.")
  4.  
  5.     var
  6.         tokens: seq[Token] = @[]
  7.         startIndex: int = 0
  8.    
  9.     while startIndex < len(expression):
  10.         endIndex = len(expression) - 1
  11.  
  12.         var foundToken: bool = false
  13.         while endIndex >= startIndex && !foundToken:
  14.             var token: Token = parseToken(expression[startIndex..endIndex])
  15.  
  16.             if token.tokenType != TokenType.Invalid:
  17.                 startIndex = endIndex + 1
  18.                 tokens.add(token)
  19.                 foundToken = true
  20.            
  21.             endIndex++
  22.        
  23.         if !foundToken: <-- Invalid Indentation Here
  24.             raise newException(ValueError, "Expression has an invalid token at " & startIndex)
  25.    
  26.     return tokens
Add Comment
Please, Sign In to add comment