* Parse string to nodes tree
(str)
| 7 | * Parse string to nodes tree |
| 8 | */ |
| 9 | parse(str) { |
| 10 | let current = [''] |
| 11 | let stack = [current] |
| 12 | |
| 13 | for (let sym of str) { |
| 14 | if (sym === '(') { |
| 15 | current = [''] |
| 16 | last(stack).push(current) |
| 17 | stack.push(current) |
| 18 | continue |
| 19 | } |
| 20 | |
| 21 | if (sym === ')') { |
| 22 | stack.pop() |
| 23 | current = last(stack) |
| 24 | current.push('') |
| 25 | continue |
| 26 | } |
| 27 | |
| 28 | current[current.length - 1] += sym |
| 29 | } |
| 30 | |
| 31 | return stack[0] |
| 32 | }, |
| 33 | |
| 34 | /** |
| 35 | * Generate output string by nodes tree |
no test coverage detected
searching dependent graphs…