Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apexlang/core

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apexlang/core

Apex language JavaScript support

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Apache License 2.0

Keywords

FAQs

Package last updated on 03 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc