Skip to content

Commit

Permalink
converted to ESM only, removed unused configuration files (#1)
Browse files Browse the repository at this point in the history
Converted to ESM only, removed unused configuration files
  • Loading branch information
jsoverson committed May 1, 2022
1 parent c4f661d commit 1606a8e
Show file tree
Hide file tree
Showing 42 changed files with 2,252 additions and 16,755 deletions.
62 changes: 47 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ This library will parse `.apex` files into an AST. Refer to the docs [docs](http
$ npm install @apexlang/core
```

## Usage (node)
## Usage (node v12+)

```js
const Apex = require("@apexlang/core");
import { parse, validate } from '@apexlang/core/index.js';
import { CommonRules } from '@apexlang/core/rules/index.js';
import { Context, Writer, AbstractVisitor } from '@apexlang/core/ast/index.js';

const source = `
namespace "mandelbrot"
Expand All @@ -20,32 +22,62 @@ interface {
update(width: u32, height: u32, limit: u32): [u16]
}`;

const doc = Apex.parse(source, { noLocation: true });

console.log(JSON.stringify(doc));
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)

```html
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/@apexlang/apex-js/dist/standalone.min.js"
></script>
<script type="text/javascript">
const source = `
<script type="module">
import { parse, validate } from 'https://cdn.jsdelivr.net/npm/@apexlang/apex-js/dist/index.js';
import { CommonRules } from 'https://cdn.jsdelivr.net/npm/@apexlang/apex-js/dist/rules/index.js';
import { Context, Writer, AbstractVisitor } from 'https://cdn.jsdelivr.net/npm/@apexlang/apex-js/dist/ast/index.js';
const source = `
namespace "mandelbrot"
interface {
update(width: u32, height: u32, limit: u32): [u16]
}`;
const doc = Apex.parse(source, { noLocation: true });
console.log(JSON.stringify(doc));
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

[Apache License 2.0](https://choosealicense.com/licenses/apache-2.0/)
[Apache License 2.0](https://choosealicense.com/licenses/apache-2.0/)
27 changes: 0 additions & 27 deletions config/jest.config.js

This file was deleted.

17 changes: 0 additions & 17 deletions config/rollup.config.js

This file was deleted.

4 changes: 0 additions & 4 deletions config/setup-tests.js

This file was deleted.

16 changes: 0 additions & 16 deletions config/tsconfig.json

This file was deleted.

Loading

0 comments on commit 1606a8e

Please sign in to comment.