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

evm2term

v1.2.4

Published

Translates from Egg Virtual Machine (JSON) to a summarized AST term

Downloads

8

Readme

Installation

npm i -g evm2term

Usage

Usage: evm2term [options] <json file containing the ast>

Converts an Egg AST to a term representation

Options:
  -V, --version  output the version number
  -i, --indent
  -h, --help     display help for command

Description

Provides an executable evm2term that summarizes an AST stored in a json file. Currently only there is a description file egg-ast-description.js giving support to the ASTs provided by the egg compiler used in the classes of the subject Language Processors:

For instance, for this Egg program:

➜ cat cat examples/summult.egg
+(a,*(4,5))

The AST generated by the any parser is usually a long JSON:

➜  eggc examples/summult.egg       
➜  evm2term git:(generic) ✗ cat examples/summult.json
{
  "type": "apply",
  "operator": {
    "type": "word",
    "offset": 0,
    "lineBreaks": 0,
    "line": 1,
    "col": 1,
    "name": "+"
  },
  "args": [
    {
      "type": "word",
      "offset": 2,
      "lineBreaks": 0,
      "line": 1,
      "col": 3,
      "name": "a"
    },
    {
      "type": "apply",
      "operator": {
        "type": "word",
        "offset": 4,
        "lineBreaks": 0,
        "line": 1,
        "col": 5,
        "name": "*"
      },
      "args": [
        {
          "type": "value",
          "value": 4,
          "raw": "4"
        },
        {
          "type": "value",
          "value": 5,
          "raw": "5"
        }
      ]
    }
  ]
}

You can get the shape of the AST using evm2term:

✗ evm2term examples/summult.json
apply(op:word{"+"},args:[word{"a"},apply(op:word{"*"},args:[value{4},value{5}])])

The Term Language to Summarize ASTs

Term is a DSL to summarize ASTs. Here is an attempt to describe the language:

term -> ('NAME' ':')? 'TYPE' '(' term (',' term)* ')'
  | leaf
leaf -> ('NAME' ':')? 'TYPE' ('{' 'ATTRIBUTE' '}')?
  • Token 'NAME' is the name of the child in the node,
  • Token 'TYPE' represents the type of the node,
  • The token 'ATTRIBUTE' is the JSON stringify of a single attribute of the leaf node.

To summarize the AST the following rules are followed:

  • Only the type of the node is shown
  • Only one selected attribute of a leaf is shown (Between curly brackets)
  • Array n-ary nodes are allowed (and they go between brackets)

Trick

The syntax of the output seems to be legal ruby. You get syntax highlighting by saving the output with the .rb extension

Future Work

By adding a configuration JS file following the pattern in egg-ast-description.js, the program can be used to work with different ASTs.

  • Write more AST descriptions for different JS transpilers (esprima, babel, etc.)