Coder Social home page Coder Social logo

syntax-diagrams's Introduction

Sequence Diagrams

This library is used to generate syntax diagrams (https://en.wikipedia.org/wiki/Syntax_diagram) from Scala code. Features:

  • Grammar is defined directly in Scala
  • Diagrams are generated as SVG files:
    • Can be styled via CSS
    • Non-terminals can be rendered as links to separate diagrams

Usage

Diagrams are represented by type Expr. You can use its subclasses to construct primitives and combine them into larger expressions:

  • Symbols
    • Terminal(value: String)
    • NonTerminal(value: String)
    • Special(value: String) - special kind of terminal. For example: textual description, regexp etc.
  • Combinators
    • Repeat(e: Expr) - at least one e
    • Optional(e: Expr) - e or nothing
    • Choice(es: Seq[Expr]) - selects one of the alternatives
    • Sequence(es: Seq[Expr]) - joins es in a sequence (concatenation)

Diagrams are generated by the method SVG.createDiagram:

def createDiagram(rhs: Expr, options: Options = Options()): Tag

You can specify the following options:

  • maxWidth - maximal width of the diagram. This is not a hard constraint - the generator does its best to fit the diagram but it may fail to do so.
  • cssClass - css class name used in generated SVG diagram
  • embeddedStyle - CSS to embed directly in SVG
  • linker: String => String - method used to convert NonTerminals to HTML links. For example "#" + _. By default does nothing (_ => "").
  • showNonTerm: String => String - method used to convert NonTerminals to HTML links. For example "#" + _. By default does nothing (_ => "").

Example

See JsonExampleRunner.scala for example that generates a single html page with syntax diagrams for JSON. You can see the generated page here: JSON Syntax

syntax-diagrams's People

Contributors

sheliaklyr avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.