Skip to content

Commit 2997062

Browse files
authored
Merge pull request #11 from leftibot/fix/issue-10-make-the-railroad-grammar-diagram-part-o
Fix #10: Make the railroad grammar diagram part of the hourly build process for the website
2 parents 05a1248 + afe0dce commit 2997062

4 files changed

Lines changed: 129 additions & 1 deletion

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Update Grammar Railroad Diagram
2+
3+
on:
4+
schedule:
5+
- cron: '47 * * * *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
update-grammar:
13+
name: Generate railroad diagram from EBNF grammar
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: '17'
22+
23+
- name: Download EBNF grammar
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: |
27+
mkdir -p grammar
28+
gh api repos/ChaiScript/ChaiScript/contents/grammar/chaiscript.ebnf \
29+
--jq '.content' | base64 -d > grammar/chaiscript.ebnf
30+
31+
- name: Download rr-webapp
32+
run: |
33+
curl -sL \
34+
"https://repo1.maven.org/maven2/de/bottlecaps/rr/rr-webapp/2.6/rr-webapp-2.6.war" \
35+
-o /tmp/rr.war
36+
37+
- name: Generate railroad diagram
38+
run: |
39+
java -jar /tmp/rr.war \
40+
-out:grammar/railroad.xhtml \
41+
grammar/chaiscript.ebnf
42+
43+
- name: Check for changes
44+
id: changes
45+
run: |
46+
git add grammar/
47+
if git diff --cached --quiet; then
48+
echo "changed=false" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "changed=true" >> "$GITHUB_OUTPUT"
51+
fi
52+
53+
- name: Commit and push
54+
if: steps.changes.outputs.changed == 'true'
55+
run: |
56+
git config user.name "github-actions[bot]"
57+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
58+
git commit -m "Update grammar railroad diagram from ChaiScript/ChaiScript"
59+
git push

_includes/header.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
<li>
3333
<a href="https://github.com/ChaiScript/ChaiScript/blob/develop/cheatsheet.md">Cheatsheet</a>
3434
</li>
35+
<li {% if page.url == '/grammar.html'%} class='active' {% endif %}>
36+
<a href="/grammar.html">Grammar</a>
37+
</li>
3538
<li {% if page.url == '/docs.html'%} class='active' {% endif %}>
3639
<a href="/docs.html">Docs</a>
3740
</li>

grammar.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Grammar
3+
---
4+
5+
<!DOCTYPE HTML>
6+
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
7+
8+
<head>
9+
<title>ChaiScript - Grammar Railroad Diagram</title>
10+
{% include common.html %}
11+
12+
<style>
13+
.grammar-iframe {
14+
width: 100%;
15+
min-height: 800px;
16+
border: 1px solid #ddd;
17+
border-radius: 4px;
18+
background: #fff;
19+
}
20+
.grammar-links {
21+
margin-top: 10px;
22+
font-size: 0.9rem;
23+
}
24+
</style>
25+
26+
</head>
27+
28+
<body>
29+
30+
{% include header.html %}
31+
32+
<div class="well well-sm">
33+
<h3>Grammar Railroad Diagram</h3>
34+
<p>Navigable railroad diagram of ChaiScript's syntax, generated from the
35+
<a href="https://github.com/ChaiScript/ChaiScript/blob/develop/grammar/chaiscript.ebnf">EBNF grammar</a>
36+
using <a href="https://github.com/GuntherRademacher/rr">RR</a>.</p>
37+
</div>
38+
39+
<div class="body-with-margin">
40+
<iframe class="grammar-iframe" src="/grammar/railroad.xhtml" title="ChaiScript grammar railroad diagram"></iframe>
41+
42+
<div class="grammar-links">
43+
<p>
44+
<a href="/grammar/railroad.xhtml">Open full-page diagram</a> &middot;
45+
<a href="/grammar/chaiscript.ebnf">Download EBNF source</a>
46+
</p>
47+
</div>
48+
</div>
49+
50+
</body>

test_playground.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Regression test for issue #6: WASM playground
2+
# Regression tests for the ChaiScript website build artifacts.
33
# Validates that all required files exist and contain expected content.
44
set -euo pipefail
55

@@ -40,6 +40,22 @@ assert_file_contains "playground.html" "header.html"
4040
# 3. Navigation includes playground link
4141
assert_file_contains "_includes/header.html" "playground"
4242

43+
# 4. Grammar railroad diagram workflow exists and runs hourly
44+
assert_file_exists ".github/workflows/update-grammar.yml"
45+
assert_file_contains ".github/workflows/update-grammar.yml" "schedule"
46+
assert_file_contains ".github/workflows/update-grammar.yml" "cron:"
47+
assert_file_contains ".github/workflows/update-grammar.yml" "chaiscript.ebnf"
48+
assert_file_contains ".github/workflows/update-grammar.yml" "ChaiScript/ChaiScript"
49+
assert_file_contains ".github/workflows/update-grammar.yml" "rr-webapp"
50+
51+
# 5. Grammar page exists with required elements
52+
assert_file_exists "grammar.html"
53+
assert_file_contains "grammar.html" "header.html"
54+
assert_file_contains "grammar.html" "railroad"
55+
56+
# 6. Navigation includes grammar link
57+
assert_file_contains "_includes/header.html" "grammar"
58+
4359
if [ "$FAIL" -ne 0 ]; then
4460
echo ""
4561
echo "RESULT: SOME TESTS FAILED"

0 commit comments

Comments
 (0)