ast-check
v1.0.10
Published
Check ast to match criterions
Downloads
9
Readme
ast-check
Check ast for specified pattern.
Usage
var matcher = require('ast-check').matcher;
var m = matcher();
m.
// We define goals to match some code
goal('init.var').
code('var i = "#var.value"'). // "#fragment.name" will be replaced
// with fragment's code on matching
assign('var.value', 'value.answer').
// Several goals may be defined to inherit code
goal('init.var.parrots').
// Just take another goal
takes('init.var').
// And reassign some of fragments
assign('var.value', 'value.parrots').
goal('init.var.variants').
takes('init.var').
// When several variants are possible..
assign('var.value', 'value.variants').
goal('init.var.anything').
// When we need wildcard in init part
assign('var.value', 'builtin.anything').
fragment('value.answer').
code('42').
fragment('value.parrots').
code('38').
fragment('value.variants').
code('38', '42'); // fragment's code may have several variants
m.match('init.var')('var i = 42'); // => true
m.match('init.var')('var i = 38'); // => false
m.match('init.var.parrots')('var i = 42'); // => false
m.match('init.var.parrots')('var i = 38'); // => true
m.match('init.var.variants')('var i = 38'); // => true
m.match('init.var.variants')('var i = 42'); // => true
m.match('init.var.anything')('var i = 404'); // => true
Limitations
You should avoid situations when two builtin.anything
are placed sequentally.
In this case matching will not work as expected.