npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

langium-ast-helper

v0.1.2

Published

A helpful package for performing AST transformations for Langium-based languages.

Downloads

124

Readme

Langium AST Helper (for AST Transformations)

A helpful package for performing AST transformations for Langium-based languages.

The goal of this package is to keep it as simple as possible to turn Langium-based language ASTs into workable data, independent of Langium itself. This is done by providing a simple API for traversing ASTs and extracting data from them, along with some helpers to transform to common data formats (TreeMaps, Graphs, etc.). The intention is that the helper can be used in any environment, including the web, so long as you have a way to feed it a serialized AST.

Provided you have a working Langium-based language, you can add the langium-ast-helper to your project and start using it immediately to consume AST data.

Possible applications for the Langium AST Helper include:

  • data analysis on ASTs
  • graphing of AST structures
  • visualizations tied directly to AST output
  • any other applications that need to consume AST-derived data

It should be noted that this helper is designed to work with the JSONSerializer output provided by most Langium-based languages. You can see an example of how the JSON serializer is invoked for the CLI in the MiniLogo example language, and also as part of a language-server worker for the Domainmodel example language.

Usage

import { deserializeAST, convertASTtoGraph, convertGraphtoDOT } from 'langium-ast-helper';

// get a serialized AST from the cli, a build-phase listen from a worker, etc.
const jsonAst = ...;

// deserialize the AST, producing an object with cross references re-constructed
const ast = deserializeAST(jsonAst);

// convert the AST to nodes & edges graph representation
const graph = convertASTtoGraph(ast);

// convert this Graph representation into a DOT program
const dot = convertGraphtoDOT(graph);

// do something with your program!

You can see the examples for more details.

Here's an example of taking a MiniLogo program that draws a series of squares, applying the steps above, and then rendering the resulting DOT program into a graph.

MiniLogo program graph generated from a DOT specification, which in turn was derived from the StateMachine grammar.

Because Langium is written in its own language, we can also parse Langium grammars and generate DOT programs from them.

As an example, here's a DOT program that corresponds to transforming the grammar for the StateMachine example language into a DOT graph. StateMachine graph generated from a DOT specification, which in turn was derived from the StateMachine grammar.

Contributing

Additions are welcome! If you see a helpful transformation that is missing from this package, and would be useful for a large enough audience, feel free to make a PR to add it in.