Permalink
Browse files

Eve's Grammar displayed as Syntax Diagrams.

* Using Chevrotain's Syntax Diagrams template.
  - https://github.com/SAP/chevrotain/tree/master/diagrams

* The syntax is serialized to "build/syntax-diagrams/" folder.
* Serialization is invoked via the build-syntax-diagrams.ts/js script.
  - An npm script ("diagrams") was added for convenience.
* The syntax diagrams can be viewed by opening the syntax_diagrams.html file at the root of the project.
  • Loading branch information...
1 parent c0b6eaf commit 302c9c163c730034bb0b6359b30ac8182901bb82 @bd82 bd82 committed Dec 1, 2016
Showing with 38 additions and 2 deletions.
  1. +2 −1 package.json
  2. +10 −0 scripts/build-syntax-diagrams.ts
  3. +1 −1 src/runtime/parser.ts
  4. +25 −0 syntax_diagrams.html
View
@@ -25,7 +25,8 @@
"prepublish": "./node_modules/.bin/tsc && node ./build/scripts/build.js",
"build-dist": "node ./build/scripts/build-dist.js",
- "test": "node ./build/test/all.js | faucet"
+ "test": "node ./build/test/all.js | faucet",
+ "diagrams": "node ./build/scripts/build-syntax-diagrams.js"
},
"dependencies": {
@@ -0,0 +1,10 @@
+let path = require("path");
+let mkdirp = require("mkdirp");
+let serializer = require("../../node_modules/chevrotain/diagrams/src/diagrams_serializer");
+let eveParser = require("../src/runtime/parser").Parser;
+
+
+let parserInstance = new eveParser([]);
+let outPath = path.join(__dirname, '../syntax_diagrams/serialized_syntax.js');
+mkdirp.sync("../syntax_diagrams");
+serializer.serializeGrammarToFile(outPath, "serializedGrammar", parserInstance);
@@ -344,7 +344,7 @@ export class ParseBlock {
// Parser
//-----------------------------------------------------------
-class Parser extends chev.Parser {
+export class Parser extends chev.Parser {
block: ParseBlock;
activeScopes: string[];
currentAction: string;
View
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<style>
+ body {
+ background-color: hsl(30, 20%, 95%)
+ }
+</style>
+
+<!--References when using npm and chevrotain is installed node_modules/chevrotain.-->
+<link rel='stylesheet' href='node_modules/chevrotain/diagrams/diagrams.css'>
+<script src='node_modules/chevrotain/diagrams/vendor/railroad-diagrams.js'></script>
+<script src='node_modules/chevrotain/diagrams/src/diagrams_builder.js'></script>
+<script src='node_modules/chevrotain/diagrams/src/diagrams_behavior.js'></script>
+<script src='node_modules/chevrotain/diagrams/src/main.js'></script>
+
+<body>
+<div id="diagrams" align="center"></div>
+
+<script src='build/syntax_diagrams/serialized_syntax.js'></script>
+
+<script>
+ var diagramsDiv = document.getElementById("diagrams");
+ main.drawDiagramsFromSerializedGrammar(serializedGrammar, diagramsDiv)
+</script>
+</body>

0 comments on commit 302c9c1

Please sign in to comment.