MCPcopy Index your code
hub / github.com/dundalek/GrammKit

github.com/dundalek/GrammKit @v0.7.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.7.2 ↗ · + Follow
37 symbols 53 edges 21 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

GrammKit

Build status on CircleCI npm version

GrammKit is a tool for generating syntax diagrams (also known as railroad diagrams) for parser grammars. Check out the online version.

Currently these grammar formats are supported: - PEG.js - it is parsed into internal AST of PEG.js which is then translated using peg-rd.js. - EBNF defined in W3C standards - it parsed into AST using parse-ebnf.pegjs - Ohm - translation is done using semantic actions in ohm-rd.js

Is uses the railroad-diagrams library to generate SVG images.

Use the command line utility

npm install -g grammkit

To generate static html page run grammkit yourgrammar.peg.

To generate markdown file run grammkit -t md yourgrammar.peg. This will generate separate SVG files and a markdown file that includes them.

Use the library

npm install grammkit

var grammkit = require('grammkit');
var parse = require('pegjs/lib/parser').parse;

var grammar = parse('start = left ("+" / "-") right');
grammkit.diagram(grammar.rules[0]);
// => '<svg>...</svg>'

The SVG renders as:

Diagram Example

Development

Clone repo and install dependencies with npm install.

Run npm run dev and open browser at http://localhost:1234 .

Here is an overview how the format conversion works:

Overview

Changelog

v0.7.1

  • Bumped up dependencies to make npm audit happy (#20)
  • Removed references to rawgit.com since it shut down (#21)

v0.7.0

  • Fixed compatibility with latest version of pegjs (v0.10.0)

v0.6.3

  • Fix onclick events for SVG elements (#13)

v0.6.2

  • Bump dependencies to satisfy npm audit

v0.6.1

  • Update ohm dependency

v0.6.0

  • Add support for ohm grammars
  • Choose different formats in web app and cli

Related projects

List of other project worth checking out.

Core symbols most depended-on inside this repo

wrap
called by 4
lib/peg-string.js
mergeObjects
called by 3
lib/ohm-references.js
checkSubnodes
called by 3
lib/peg-references.js
renderTemplate
called by 2
cli.js
processPeg
called by 2
lib/util.js
handleRule
called by 2
lib/ohm-references.js
escape
called by 2
lib/peg-string.js
generateRepeating
called by 2
lib/peg-generate.js

Shape

Function 37

Languages

TypeScript100%

Modules by API surface

lib/ohm-references.js17 symbols
lib/peg-generate.js7 symbols
app/app.js4 symbols
lib/peg-references.js3 symbols
lib/peg-string.js2 symbols
lib/util.js1 symbols
lib/rd-string.js1 symbols
lib/diagram.js1 symbols
cli.js1 symbols

For agents

$ claude mcp add GrammKit \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact