Hi guys, how can I simplify this example implement...
# codereview
c
Hi guys, how can I simplify this example implementation of a linter
Copy code
fun linter(line: String): Boolean {
    val myStack = Stack<String>()
    line.split("").forEach { char ->
      when (char) {
        "{", "(", "[" -> myStack.push(char)
        "}", ")", "]" -> {
          if (!myStack.isStackEmpty()) {
            val topStackItem = myStack.peek()
            if (topStackItem != null) {
              when (char) {
                "}" -> {
                  if (topStackItem == "{")myStack.pop()
                  else throw SyntaxErrorThreeException(topStackItem, char)
                }
                "]" -> {
                  if (topStackItem == "[") myStack.pop()
                  else throw SyntaxErrorThreeException(topStackItem, char)
                }
                ")" -> {
                  if (topStackItem == "(") myStack.pop()
                  else throw SyntaxErrorThreeException(topStackItem, char)
                }
              }
            }
          } else {
            throw SyntaxErrorTwoException(char)
          }
        }
      }
    }
    if (!myStack.isStackEmpty()) throw SyntaxErrorOneException(myStack.peek()!!)
    else return true
  }