Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
18 lines (17 sloc) 457 Bytes
export default function liner(tokens) {
let line = [];
let result = [line];
let brackets = 0;
for ( let token of tokens ) {
line.push(token);
if ( token[0] === '(' ) {
brackets += 1;
} else if ( token[0] === ')' ) {
brackets -= 1;
} else if ( token[0] === 'newline' && brackets === 0 ) {
line = [];
result.push(line);
}
}
return result;
}