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-minilogo

v3.0.1

Published

An implementation of the MiniLogo Language in Langium

Downloads

23

Readme

MiniLogo in Langium

An example of implementing a simple DSL, MiniLogo, in Langium.

The core artifacts of this project are:

  • A Langium implementation of a variant of the MiniLogo language.
  • A demo web application for showing how Langium can run in the web.

MiniLogo is a example language for operating a 'pen' to draw on a surface. If you're familiar with python's Turtle graphics, it's similar to that.

This implementation is based on Eric Walkingshaw's grammar and semantics at OSU.

Which in turn, is based on the Logo language itself.

There is, at this time, a single example in examples/test.logo. Which demonstrates the aspects of MiniLogo:

  • Move commands to change position of the pen
  • Pen up/down commands to change the drawing state
  • Basic arithmetic expressions of literal ints, references, and binary expressions. Parenthesized and negated expressions are allowed as well
  • Common arithmetic binary functions are in infix notation: +, -, * and /
  • For loops allow a means to bind a single variable to an expr, with a second expression as an excluded upper bound, and a body of statements that are executed on each loop
  • Macros are definable, taking arguments upon calling that are bound to parameters which can be referenced in a macro's body
  • Color can be set for the lines that are drawn, affecting all subsequent 'move' comands.

Notably, there is no branching instruction present, as there are no booleans present in this language.

Building && Running Locally

The primary artifact of this project is producing a MiniLogo parser & associated generator. This is done by running the following.

# in case you changed the grammar
npm run langium:generate

# compile minilogo
npm run build

You can then reference the produced MiniLogo parser to directly process MiniLogo programs in your own projects.

If you just want to generate code from parsed MiniLogo programs, you can use the cli from the command line. You can test it like so.

# generate commands from a simple program
npm run generate:test

You can also use the cli more directly to generate either an AST or commands in JSON, whichever is of more interest. The AST will allow you to process the program as data, and the commands are pre-processed to support a simple stack-based drawing machine (a version of which is implemented in this project for demonstration).

# generate an AST
./bin/minilogo.js generate examples/simple.logo > examples/ast.json

# generate commands
./bin/minilogo.js generate-cmds examples/simple.logo > examples/ast.json

This will give you a a JSON array of drawing commands generated from the examples/simple.logo program. You can also run this on any other MiniLogo program that you'd like to test, such as examples/test.logo and examples/turtle.logo.

This output can be fed into another program to process the corresponding drawing commands, without needing to interact with a Minilogo program directly.

Building && Running the VSCode extension

In VSCode, open a terminal and run the following line.

npm run build:extension

Then, run the extension by hitting F5 (File menu -> Run -> Start debugging). Another VSCode instance will open, and you can open the examples folder to see the MiniLogo language in action.

Running in the Web

The secondary artifact of this project is a simple web application that demonstrates running Langium in the web, without a backend.

To run these examples standalone in the web, you need to first build the regular application, and then build & copy assets over for usage in browsers.

# in case you've adjusted the grammar
npm run langium:generate

# compile minilogo, copy, and construct the appropriate web assets
npm run build:web

This builds Minilogo, and sets up the libraries that you will need in public for all MiniLogo programs. You can startup an simple express app on localhost:3000 with a default program by running the following.

npm run serve

In the same interface you can also add in any MiniLogo program (that is recognized by this implementation of MiniLogo in Langium) that you would like to test, and see the results printed to the canvas on the right hand side. Once changes are made, you can click the update button at the bottom of the page to trigger redrawing the canvas using the current program.

If you're running after making a large quantity of changes, you can always run npm run clean before building to ensure you have a stable state.

There are some example MiniLogo programs in the examples folder that you can try out as well.

At a high-level, updating the canvas works by:

  • Monaco is started with a language client (LC), and is connected to an Minilogo language server (LS)
  • The document is updated, and the LC passes this new document (program) to the LS
  • the language server (Langium) receives the document
  • the document is parsed & an AST is produced, validations are performed, etc.
  • the generator is invoked to traverse and transform this AST into an array of drawing commands (includes evaluation of exprs)
  • these resulting commands, along with the AST, are returned as the result as a response to a successfully validated (processed) document
  • the front-end receives & processes these drawing instructions using a very simple stack-based machine
  • the machine drives visual updates to the canvas

This is a hyper generalization of each step, but should be sufficient to get a good idea of how this example implementation works.

Here are the results of a couple of example programs