Permalink
Browse files

Ignore newlines inside brackets

  • Loading branch information...
1 parent 78d3934 commit a10fe25f07daa6d38aa006fc573ed5c4256dab31 @ai ai committed Mar 1, 2016
Showing with 15 additions and 3 deletions.
  1. +8 −3 liner.es6
  2. +7 −0 test/liner.js
View
@@ -1,9 +1,14 @@
export default function liner(tokens) {
- let line = [];
- let result = [line];
+ let line = [];
+ let result = [line];
+ let brackets = 0;
for ( let token of tokens ) {
line.push(token);
- if ( token[0] === 'newline' ) {
+ if ( token[0] === '(' ) {
+ brackets += 1;
+ } else if ( token[0] === ')' ) {
+ brackets -= 1;
+ } else if ( token[0] === 'newline' && brackets === 0 ) {
line = [];
result.push(line);
}
View
@@ -9,3 +9,10 @@ test('packs tokens by lines', t => {
[['word', 'b']]
]);
});
+
+test('ignores newline inside brackets', t => {
+ let tokens = [['(', '('], ['newline', '\n'], [')', ')']];
+ t.same(liner(tokens), [
+ [['(', '('], ['newline', '\n'], [')', ')']]
+ ]);
+});

0 comments on commit a10fe25

Please sign in to comment.