hdl-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

hdl-parser

Parser for nand2tetris HDL (Hardware Description Language), built on top of Peggy.

Build Status NPM Version License: MIT Types: TypeScript

Usage example

const { parse } = require('hdl-parser');

console.log(parse(`
  CHIP Not {
    IN in;
    OUT out;

    PARTS:
    Nand(a=in, b=true, out=out);
  }
`));

And the result:

({
  name: 'Not',
  definitions: [
    { type: 'IN', pins: [{ name: 'in', bits: 1 }] },
    { type: 'OUT', pins: [{ name: 'out', bits: 1 }] },
  ],
  parts: [
    {
      name: 'Nand',
      connections: [
        { from: { pin: 'a', bits: null }, to: { pin: 'in', bits: null } },
        { from: { pin: 'b', bits: null }, to: { const: 'true' } },
        { from: { pin: 'out', bits: null }, to: { pin: 'out', bits: null } },
      ],
    },
  ],
})

For more examples, see the tests file.

License

Released under the terms of the MIT licence. Copyright (c) 2021, Uri Shaked.

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i hdl-parser

    Weekly Downloads

    3

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    52 kB

    Total Files

    6

    Last publish

    Collaborators

    • urish