website online/try: serve different example
This commit is contained in:
parent
fd3dbb77ac
commit
9dc4d4a5ef
|
@ -4,6 +4,7 @@ const bodyParser = require( "body-parser" );
|
|||
const express = require( "express" );
|
||||
const layout = require( "express-layout" );
|
||||
const logger = require( "morgan" );
|
||||
const { readFileSync } = require( "fs" );
|
||||
const { join } = require( "path" );
|
||||
const ms = require( "pretty-ms" );
|
||||
const rollup = require( "rollup" );
|
||||
|
@ -58,6 +59,7 @@ app.get( "/", ( req, res ) => {
|
|||
|
||||
} );
|
||||
|
||||
const LEGACY_EXAMPLE = readFileSync( path( "website", "vendor", "pegjs", "arithmetics.pegjs" ), "utf8" );
|
||||
app.get( "/online", ( req, res ) => {
|
||||
|
||||
res.render( "online", {
|
||||
|
@ -65,6 +67,7 @@ app.get( "/online", ( req, res ) => {
|
|||
title: "Online version",
|
||||
layout: "layout-online",
|
||||
pegjs: "/vendor/pegjs/peg.js",
|
||||
example: LEGACY_EXAMPLE,
|
||||
|
||||
} );
|
||||
|
||||
|
@ -90,6 +93,7 @@ app.get( "/development", ( req, res ) => {
|
|||
|
||||
} );
|
||||
|
||||
const DEV_EXAMPLE = readFileSync( path( "examples", "arithmetics.pegjs" ) );
|
||||
app.get( "/development/try", ( req, res ) => {
|
||||
|
||||
res.render( "online", {
|
||||
|
@ -97,6 +101,7 @@ app.get( "/development/try", ( req, res ) => {
|
|||
title: "Online Development version",
|
||||
layout: "layout-online",
|
||||
pegjs: "/js/peg-bundle.js",
|
||||
example: DEV_EXAMPLE,
|
||||
|
||||
} );
|
||||
|
||||
|
|
30
website/vendor/pegjs/arithmetics.pegjs
vendored
Normal file
30
website/vendor/pegjs/arithmetics.pegjs
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Simple Arithmetics Grammar
|
||||
// ==========================
|
||||
//
|
||||
// Accepts expressions like "2 * (3 + 4)" and computes their value.
|
||||
|
||||
Expression
|
||||
= head:Term tail:(_ ("+" / "-") _ Term)* {
|
||||
return tail.reduce(function(result, element) {
|
||||
if (element[1] === "+") { return result + element[3]; }
|
||||
if (element[1] === "-") { return result - element[3]; }
|
||||
}, head);
|
||||
}
|
||||
|
||||
Term
|
||||
= head:Factor tail:(_ ("*" / "/") _ Factor)* {
|
||||
return tail.reduce(function(result, element) {
|
||||
if (element[1] === "*") { return result * element[3]; }
|
||||
if (element[1] === "/") { return result / element[3]; }
|
||||
}, head);
|
||||
}
|
||||
|
||||
Factor
|
||||
= "(" _ expr:Expression _ ")" { return expr; }
|
||||
/ Integer
|
||||
|
||||
Integer "integer"
|
||||
= _ [0-9]+ { return parseInt(text(), 10); }
|
||||
|
||||
_ "whitespace"
|
||||
= [ \t\n\r]*
|
|
@ -14,36 +14,7 @@
|
|||
<td>
|
||||
<div class="textarea-wrapper">
|
||||
<textarea class="code" id="grammar" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" disabled>
|
||||
// Simple Arithmetics Grammar
|
||||
// ==========================
|
||||
//
|
||||
// Accepts expressions like "2 * (3 + 4)" and computes their value.
|
||||
|
||||
Expression
|
||||
= head:Term tail:(_ ("+" / "-") _ Term)* {
|
||||
return tail.reduce(function(result, element) {
|
||||
if (element[1] === "+") { return result + element[3]; }
|
||||
if (element[1] === "-") { return result - element[3]; }
|
||||
}, head);
|
||||
}
|
||||
|
||||
Term
|
||||
= head:Factor tail:(_ ("*" / "/") _ Factor)* {
|
||||
return tail.reduce(function(result, element) {
|
||||
if (element[1] === "*") { return result * element[3]; }
|
||||
if (element[1] === "/") { return result / element[3]; }
|
||||
}, head);
|
||||
}
|
||||
|
||||
Factor
|
||||
= "(" _ expr:Expression _ ")" { return expr; }
|
||||
/ Integer
|
||||
|
||||
Integer "integer"
|
||||
= _ [0-9]+ { return parseInt(text(), 10); }
|
||||
|
||||
_ "whitespace"
|
||||
= [ \t\n\r]*
|
||||
<%- example %>
|
||||
</textarea>
|
||||
</div>
|
||||
</td>
|
||||
|
|
Loading…
Reference in a new issue