0.1.5 • Published 4 months ago
@apexlang/core v0.1.5
Apex Language Parser
This library will parse .apex
files into an AST. Refer to the docs
docs for more information.
Installation
$ npm install @apexlang/core
Usage (node v12+)
import { parse, validate } from "@apexlang/core/mod.js";
import { CommonRules } from "@apexlang/core/rules/mod.js";
import { AbstractVisitor, Context, Writer } from "@apexlang/core/ast/mod.js";
const source = `
namespace "mandelbrot"
interface {
update(width: u32, height: u32, limit: u32): [u16]
}`;
const doc = parse(source, undefined, { noLocation: true });
const errors = validate(doc, ...CommonRules);
if (errors.length > 0) {
errors.map((e) => console.log(e.message));
} else {
const context = new Context({});
const writer = new Writer();
const visitor = new AbstractVisitor();
visitor.setCallback("Operation", "", function (context) {
const oper = context.operation;
if (oper == undefined || oper.name.value != "update") {
return;
}
console.log(oper);
});
doc.accept(context, visitor);
}
Usage (browser)
<script type="module">
import { parse, validate } from 'https://cdn.jsdelivr.net/npm/@apexlang/core/esm/mod.js';
import { CommonRules } from 'https://cdn.jsdelivr.net/npm/@apexlang/core/esm/rules/mod.js';
import { Context, Writer, AbstractVisitor } from 'https://cdn.jsdelivr.net/npm/@apexlang/core/esm/ast/mod.js';
const source = `
namespace "mandelbrot"
interface {
update(width: u32, height: u32, limit: u32): [u16]
}`;
const doc = parse(source, undefined, { noLocation: true });
const errors = validate(doc, ...CommonRules);
if (errors.length > 0) {
errors.map(e => console.log(e.message));
} else {
const context = new Context({});
const writer = new Writer();
const visitor = new AbstractVisitor();
visitor.setCallback("Operation", "", function(context) {
const oper = context.operation;
if (oper == undefined || oper.name.value != "update") {
return;
}
console.log(oper);
});
doc.accept(context, visitor);
}
</script>
License
0.1.4
4 months ago
0.1.5
4 months ago
0.1.3
1 year ago
0.1.0
2 years ago
0.1.1
2 years ago
0.0.26
2 years ago
0.0.27
2 years ago
0.0.20
2 years ago
0.0.21
2 years ago
0.0.22
2 years ago
0.0.23
2 years ago
0.0.24
2 years ago
0.0.25
2 years ago
0.0.17
2 years ago
0.0.18
2 years ago
0.0.19
2 years ago
0.0.16
2 years ago
0.0.15
2 years ago
0.0.14
2 years ago
0.0.13
2 years ago