mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 09:54:49 +00:00
Somehow the test case doesn't crash anymore and the regression in the doc generation is fixed. Fixes #9019
28 lines
563 B
Nim
28 lines
563 B
Nim
discard """
|
|
action: "run"
|
|
"""
|
|
|
|
import
|
|
tables, deques, sequtils
|
|
|
|
const
|
|
lookupTable = {'(': ')', '{': '}', '[': ']'}.toTable
|
|
|
|
proc isPaired*(value: string): bool =
|
|
var stack = initDeque[char]()
|
|
|
|
for item in value:
|
|
# echo "Looking at " & item
|
|
if item in lookupTable:
|
|
stack.addLast(item)
|
|
if item in toSeq(lookupTable.values):
|
|
if stack.len == 0:
|
|
return false
|
|
if lookupTable[stack.popLast()] != item:
|
|
return false
|
|
|
|
return stack.len == 0
|
|
|
|
doAssert isPaired("{[()]}") == true
|
|
doAssert isPaired("a)b(c") == false
|