0.0.2 • Published 5 years ago

astraia v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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
	}
});
0.0.2

5 years ago

0.0.1

6 years ago

0.0.0

6 years ago