diff --git a/lib/parser.js b/lib/parser.js index 33cf7b2..79db0dc 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -84,14 +84,29 @@ function summary (scanner) { node.children.push(t) } - // ... "(" ")" ... - let s = scope(scanner) - if (s instanceof Error) { + // ... ... + let ss = scopeStart(scanner) + if (ss instanceof Error) { s = null } else { - node.children.push(s) + node.children.push(ss) + + let s = scope(scanner) + if (s instanceof Error) { + s = null + } else { + node.children.push(s) + + let se = scopeEnd(scanner) + if (se instanceof Error) { + s = null + } else { + node.children.push(se) + } + } } + // ... ["!"] ... let b = breakingChange(scanner) if (b instanceof Error) { @@ -154,15 +169,23 @@ function text (scanner) { } /* - * "(" ")" ::= 1* + * ::= "(" */ -function scope (scanner) { - if (scanner.peek() !== '(') { - return scanner.abort(scanner.enter('scope', '')) - } else { - scanner.next() +function scopeStart (scanner) { + const node = scanner.enter('scopeStart', '') + // '(' + if (scanner.peek() === '(') { + node.value = scanner.next() + return scanner.exit(node) } + return scanner.abort(node) +} + +/* + * "(" ")" ::= 1* + */ +function scope (scanner) { const node = scanner.enter('scope', '') while (!scanner.eof()) { @@ -177,7 +200,6 @@ function scope (scanner) { throw scanner.abort(node, [')']) } else { scanner.exit(node) - scanner.next() } if (node.value === '') { @@ -187,6 +209,20 @@ function scope (scanner) { } } +/* + * ::= ")" + */ +function scopeEnd (scanner) { + const node = scanner.enter('scopeEnd', '') + // ')' + if (scanner.peek() === ')') { + node.value = scanner.next() + return scanner.exit(node) + } + + return scanner.abort(node) +} + /* * ::= [], , * * | []