Mirror: The magical sticky regex-based parser generator 🧙
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Simplify opts construction

+13 -14
+13 -14
src/codegen.js
··· 9 9 return body.trim(); 10 10 } 11 11 12 - const newOpts = (prev, next) => ({ 13 - index: next.index != null ? next.index : prev.index, 14 - length: next.length != null ? next.length : prev.length, 15 - onAbort: next.onAbort != null ? next.onAbort : prev.onAbort, 16 - abort: next.abort != null ? next.abort : prev.abort, 17 - capture: next.capture != null ? next.capture : prev.capture, 18 - }); 12 + const makeOpts = (prev, next) => { 13 + const output = {}; 14 + for (const key in prev) output[key] = prev[key]; 15 + for (const key in next) output[key] = next[key]; 16 + return output; 17 + }; 19 18 20 19 const assignIndex = (depth) => 21 20 depth ? js`var index_${depth} = ${_state}.index;` : ''; ··· 74 73 ${astSequence( 75 74 ast.sequence, 76 75 depth + 1, 77 - newOpts(opts, { 76 + makeOpts(opts, { 78 77 length: depth, 79 78 capture, 80 79 }) ··· 85 84 return astSequence( 86 85 ast.sequence, 87 86 depth + 1, 88 - newOpts(opts, { 87 + makeOpts(opts, { 89 88 capture, 90 89 }) 91 90 ); ··· 103 102 ${astChild( 104 103 ast, 105 104 depth, 106 - newOpts(opts, { 105 + makeOpts(opts, { 107 106 onAbort: js` 108 107 if (${count}) { 109 108 ${restoreIndex(depth)} ··· 126 125 ${astChild( 127 126 ast, 128 127 depth, 129 - newOpts(opts, { 128 + makeOpts(opts, { 130 129 length: 0, 131 130 index: depth, 132 131 abort: js`break ${label};`, ··· 142 141 ${astChild( 143 142 ast, 144 143 depth, 145 - newOpts(opts, { 144 + makeOpts(opts, { 146 145 index: depth, 147 146 abort: '', 148 147 onAbort: '', ··· 155 154 const label = `invert_${depth}`; 156 155 157 156 if (ast.capture === '!') { 158 - opts = newOpts(opts, { 157 + opts = makeOpts(opts, { 159 158 index: depth, 160 159 abort: js`break ${label};`, 161 160 }); ··· 197 196 198 197 let childOpts = opts; 199 198 if (ast.alternation) { 200 - childOpts = newOpts(opts, { 199 + childOpts = makeOpts(opts, { 201 200 index: depth, 202 201 abort: js`break ${block};`, 203 202 onAbort: '',