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

univac

v0.0.8

Published

Generate AST of lots of common programming languages using antlr4. JavaScript API and CLI tool.

Downloads

5

Readme

Univac

API and CLI to generate Abstract Syntax Trees (AST) of several well-known programming languages using antlr4 grammars

Playground - Demo

Playground (WIP)

Features

  • JavaScript API for node.js and browser.
  • Command line tool
  • TypeScript
  • ASTs for C, golang, ruby, java, python, scala, erlang, lua, dart2, rust, antlr4, kotlin, smalltalk, fortran77, VisualBasic6, less wat, and more...

A word of caution

A word of caution regarding generated ASTs:

  • Not guaranteed to support 100% of Language's features
  • Not guaranteed to render 100% of given source code semantics
  • AST structure is not official
    • Was built using antlr4 which is not a tool oriented to generate AST
      • So some grammars needed to be post-processed to remove redundant nodes.

Install

npm i univac

JavaScript API

import { parseAst } from 'univac'

const ast = await parseAst({
  input: 'int main() {}',
  language: 'c'
})
console.log(JSON.stringify(ast, null, 2))

Command line

univac --input src/file.py --language python3 --output file-ast.json
univac --listLanguages
univac --input "int main() {}" --language c > ast.json

Supported Languages

The idea is to support all languages in antlr4 grammars

Status

THis is a very new project, WIP, this is the current status:

  • tests for Node.js API
  • tests to make sure it runs in the browser
  • C language
  • Golang
  • C++
  • scala
  • ruby
  • java
  • lua
  • python3
  • erlang
  • dart2
  • kotlin
  • Fortran77
  • Smalltalk
  • VisualBasic6
  • wat
  • less
  • java9 (very slow)
  • CLI
  • Basic Playground
  • playground improved with many examples, syntax hihgiling,different kind of ast viewers.
  • antlr4 grammar
  • c++ grammar (cppAntlr) - slow
  • introduced second kind of parser : tree-sitting. These return a "real" ast - not visitor.
    • declared adaptor interfaces
    • visitor is now a normalizer Normalizer
    • tree-sitter tests for node
    • async call parseAst()
  • rust (tree-sitter)
  • sexpressions (antlr4)
  • abnf (antlr4)
  • julia (tree-sitter)

Language grammars notes

Smalltalk

Grammar taken from official readline-smalltalk project: https://github.com/redline-smalltalk/redline-smalltalk

Ruby

Is not Ruby, is Ruby-like. Doesn't support Object Oriented features.

TODO: rename it or remove it. Notes from the author:

Ruby-like language (Corundum) grammar written in ANTLR v4. Was developed just for fun to use with Parrot VM (basically it compiles into PIR - parrot intermediate representation)

It has some specific stuff like inline pir and for loop :) And won't ever have OOP features, sorry.

Java9

It's very very slow, just use the java one. notes form the author:

A Java 8 grammar for ANTLR 4 derived from the Java Language Specification chapter 19.

NOTE: This grammar results in a generated parser that is much slower than the Java 7 grammar in the grammars-v4/java directory. This one is, however, extremely close to the spec.