| 1 | Railroad-diagram Generator |
| 2 | ========================== |
| 3 | |
| 4 | <a href="https://github.com/tabatkins/railroad-diagrams/blob/gh-pages/images/rr-title.svg"><img src="https://github.com/tabatkins/railroad-diagrams/raw/gh-pages/images/rr-title.svg?sanitize=true" alt="Diagram(Stack('Generate', 'some'), OneOrMore(NonTerminal('railroad diagrams'), Comment('and more')))" title="Diagram(Stack('Generate', 'some'), OneOrMore(NonTerminal('railroad diagrams'), Comment('and more')))" width=10000></a> |
| 5 | |
| 6 | ``` |
| 7 | ╭──────────╮ |
| 8 | ├┼──────│ Generate │──┐ |
| 9 | ╰──────────╯ │ |
| 10 | ┌────────────────┘ |
| 11 | │ ╭──────╮ ┌───────────────────┐ |
| 12 | └────│ some │────────╭──│ railroad diagrams │──╮───┼┤ |
| 13 | ╰──────╯ │ └───────────────────┘ │ |
| 14 | ╰─and more────────────────╯ |
| 15 | (If this one looks messed up, you're probably on ChromeOS or Android, |
| 16 | whose default monospace fonts don't include box-drawing characters, |
| 17 | meaning it's falling back to a variable-width font for those chars. |
| 18 | I can't adjust font on GitHub READMEs, but you can make sure *your* |
| 19 | text editor or website uses a monospace font with proper support, |
| 20 | so it'll look great when you generate text-based diagrams yourself. |
| 21 | ``` |
| 22 | |
| 23 | This is a small library for generating railroad diagrams |
| 24 | (like what [JSON.org](http://json.org) uses) |
| 25 | using SVG or Unicode Text, with both JS and Python ports. |
| 26 | |
| 27 | Railroad diagrams are a way of visually representing a grammar |
| 28 | in a form that is more readable than using regular expressions or BNF. |
| 29 | They can easily represent any context-free grammar, and some more powerful grammars. |
| 30 | There are several railroad-diagram generators out there, but none of them had the visual appeal I wanted, so I wrote my own. |
| 31 | |
| 32 | [Here's an online dingus for you to play with and get SVG code from!](https://tabatkins.github.io/railroad-diagrams/generator.html) |
| 33 | |
| 34 | Versions |
| 35 | -------- |
| 36 | |
| 37 | This library is supported both as a JS module and a Python module, |
| 38 | and the install and use instructions for each |
| 39 | are in their lang-specific READMEs. |
| 40 | |
| 41 | * [JS-specific README](README-js.md) |
| 42 | * [Python-specific README](README-py.md) |
| 43 | |
| 44 | |
| 45 | Caveats |
| 46 | ------- |
| 47 | |
| 48 | SVG can't actually respond to the sizes of content; in particular, there's no way to make SVG adjust sizing/positioning based on the length of some text. Instead, I guess at some font metrics, which mostly work as long as you're using a fairly standard monospace font. This works pretty well, but long text inside of a construct might eventually overflow the construct. |
| 49 | |
| 50 | |
| 51 | License |
| 52 | ------- |
| 53 | |
| 54 | Standard MIT license; see [LICENSE](LICENSE). |
| 55 | |
| 56 | Don't ask me for permission to use any part of this project, **just use it**. |
| 57 | I would appreciate attribution, but that is not required by the license. |
| 58 | If you're doing something cool with it, again I'd appreciate it if you let me know, but that's not required either. |