astraia
v0.0.2
Published
A library traversing AST
Downloads
1
Readme
Astraia
Astraia is a library of traversing objects.
Astraia can be used by traversing abstract syntax tree (AST).
How to use
node.js
Install Astraia:
npm install astraia
Use module:
var R = require('astraia');
Browser
<script src="astraia.js"></script>
Examples
Traversing AST of addtion or subtraction of constant
var rules = [{
pattern: {
"type": A.eqv("add"),
"left": A.number,
"right": A.number
},
action: function(obj) {
return obj.left + obj.right;
}
}, {
pattern: {
"type": A.eqv("sub"),
"left": A.number,
"right": A.number
},
action: function(obj) {
return obj.left - obj.right;
}
}];
// outputs 2
A.scan(rules, {
"type": "add",
"left": {
"type": "add",
"left": 1,
"right": 2
},
"right": {
"type": "sub",
"left": 3,
"right": 4
}
});