const matcher = require('ast-check').matcher; const m = matcher(); m. goal('for.loop'). code('for("#for.init"; "#for.condition"; "#for.iter") "#for.actions"'). assign('for.init', 'anything'). assign('for.condition', 'anything'). assign('for.iter', 'anything'). assign('for.actions', 'anything'). goal('for.initialized'). takes('for.loop'). assign('for.init', 'init.i'). goal('for.with.condition'). takes('for.initialized'). assign('for.condition', 'i.lt.10'). goal('for.with.update'). takes('for.with.condition'). assign('for.iter', 'i.increment'). goal('for.with.action'). takes('for.with.update'). assign('for.actions', 'console.i'). fragment('init.i').code('var i = 1'). fragment('i.lt.10').code('i < 10', '10 > i'). fragment('i.increment').code('i++', '++i', 'i = i + 1', 'i = 1 + i', 'i += 1'). fragment('console.i').code('console.log(i)'); // Примеры var fullSample = 'for(var i = 1; i < 10; i += 1) { console.log(i); }'; var samples = { 'for.loop': 'for(var i = 1;;) {}', 'for.initialized': 'for(var i = 1;;) {}', 'for.with.condition': 'for(var i = 1; i < 10;) {}', 'for.with.update': 'for(var i = 1; i < 10; i++) {}', 'for.with.action': 'for(var i = 1; 10 > i; i = i + 1) { console.log(i); }' }; Object.keys(samples).forEach((key) => { console.log(`${key}: ${m.matches(key)(samples[key])}`); console.log(`full.${key}: ${m.matches(key)(fullSample)}`); });

no comments

    sign in to comment

    running