init
initalize repo Co-authored-by: Patrick Massot PatrickMassot@users.noreply.github.compull/43/head
commit
7563730292
@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
client/dist
|
||||
server/build
|
||||
@ -0,0 +1,73 @@
|
||||
|
||||
# Install docker
|
||||
```
|
||||
sudo apt-get update
|
||||
sudo apt-get install ca-certificates curl gnupg lsb-release -y
|
||||
sudo mkdir -p /etc/apt/keyrings
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
echo \
|
||||
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
|
||||
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
sudo apt-get update
|
||||
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
|
||||
|
||||
sudo groupadd docker
|
||||
sudo usermod -aG docker ${USER}
|
||||
newgrp docker
|
||||
```
|
||||
|
||||
# Install gVisor
|
||||
```
|
||||
sudo apt-get update && \
|
||||
sudo apt-get install -y \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
curl \
|
||||
gnupg
|
||||
curl -fsSL https://gvisor.dev/archive.key | sudo gpg --dearmor -o /usr/share/keyrings/gvisor-archive-keyring.gpg
|
||||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/gvisor-archive-keyring.gpg] https://storage.googleapis.com/gvisor/releases release main" | sudo tee /etc/apt/sources.list.d/gvisor.list > /dev/null
|
||||
sudo apt-get update && sudo apt-get install -y runsc
|
||||
|
||||
sudo runsc install
|
||||
sudo systemctl reload docker
|
||||
```
|
||||
|
||||
# Install NPM
|
||||
```
|
||||
sudo apt-get install npm
|
||||
sudo npm install -g http-server
|
||||
```
|
||||
|
||||
# Clone NNG interface
|
||||
```
|
||||
(
|
||||
git clone https://github.com/hhu-adam/nng4-interface.git
|
||||
cd nng4-interface
|
||||
rm package-lock.json
|
||||
npm install
|
||||
npm run build
|
||||
)
|
||||
```
|
||||
|
||||
```
|
||||
git clone https://github.com/hhu-adam/NNG4.git
|
||||
cd NNG4
|
||||
docker rmi nng4:latest
|
||||
docker build --pull --rm -f "Dockerfile" -t nng4:latest "."
|
||||
```
|
||||
|
||||
|
||||
# Start HTTP server
|
||||
```
|
||||
http-server ./nng4-interface/build
|
||||
```
|
||||
|
||||
# Start WebSocket server
|
||||
```
|
||||
cd NNG4 && python3 ./gameserver.py
|
||||
```
|
||||
|
||||
# Test docker
|
||||
```
|
||||
docker run --runtime=runsc --network=none --rm -it nng4:latest
|
||||
```
|
||||
@ -0,0 +1,9 @@
|
||||
# Lean 4 Game
|
||||
|
||||
This is a prototype for a Lean 4 game platform. It is based on ideas from the [Lean Game Maker](https://github.com/mpedramfar/Lean-game-maker) and the [Natural Number Game
|
||||
(NNG)](https://www.ma.imperial.ac.uk/~buzzard/xena/natural_number_game/)
|
||||
of Kevin Buzzard and Mohammad Pedramfar.
|
||||
The project is currently mostly copied from Patrick Massot's [NNG4](https://github.com/PatrickMassot/NNG4), but we plan to extend it significantly.
|
||||
|
||||
Building this requires a [npm](https://www.npmjs.com/) toolchain. After cloning the repository you should run
|
||||
`npm install` to pull in all dependencies. For development and experimentation, you can run `npm start` that will perform a non-optimized build and then run a local webserver on port 3000.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Lean 4 Game</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<noscript>
|
||||
You need to enable JavaScript to run this app.
|
||||
</noscript>
|
||||
<script src="../dist/bundle.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@ -0,0 +1,73 @@
|
||||
import React, { useState } from 'react';
|
||||
import { MathJaxContext } from "better-react-mathjax";
|
||||
|
||||
import useWebSocket from 'react-use-websocket';
|
||||
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
import { AppBar, CssBaseline, Toolbar, Typography } from '@mui/material';
|
||||
|
||||
import Welcome from './components/Welcome';
|
||||
import Level from './components/Level';
|
||||
import GoodBye from './components/GoodBye';
|
||||
|
||||
function App() {
|
||||
const [title, setTitle] = useState("")
|
||||
const [conclusion, setConclusion] = useState("")
|
||||
const [levelTitle, setLevelTitle] = useState("")
|
||||
const [nbLevels, setNbLevels] = useState(0)
|
||||
const [curLevel, setCurLevel] = useState(0)
|
||||
const [finished, setFinished] = useState(false)
|
||||
|
||||
const socketUrl = 'ws://' + window.location.hostname + ':8765'
|
||||
const { sendJsonMessage, lastMessage, lastJsonMessage } = useWebSocket(socketUrl)
|
||||
|
||||
const mathJaxConfig = {
|
||||
loader: {
|
||||
load: ['input/tex-base', 'output/svg']
|
||||
},
|
||||
tex: {
|
||||
inlineMath: [['$', '$'], ['\\(', '\\)']]
|
||||
},
|
||||
svg: {
|
||||
fontCache: 'global'
|
||||
}
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
setCurLevel(1)
|
||||
}
|
||||
|
||||
let mainComponent;
|
||||
if (finished) {
|
||||
mainComponent = <GoodBye message={conclusion} />
|
||||
} else if (curLevel > 0) {
|
||||
mainComponent = <Level sendJsonMessage={sendJsonMessage} lastMessage={lastMessage} lastJsonMessage={lastJsonMessage} nbLevels={nbLevels} level={curLevel} setCurLevel={setCurLevel} setLevelTitle={setLevelTitle} setFinished={setFinished}/>
|
||||
} else {
|
||||
mainComponent = <Welcome sendJsonMessage={sendJsonMessage} lastMessage={lastMessage} lastJsonMessage={lastJsonMessage} setNbLevels={setNbLevels} setTitle={setTitle} startGame={startGame} setConclusion={setConclusion}/>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<MathJaxContext config={mathJaxConfig}>
|
||||
<CssBaseline />
|
||||
<AppBar position="sticky" sx={{ zIndex: (theme) => theme.zIndex.drawer + 1 }}>
|
||||
<Toolbar sx={{ justifyContent: "space-between" }}>
|
||||
<Typography variant="h6" noWrap component="div">
|
||||
{title}
|
||||
</Typography>
|
||||
<Typography variant="h6" noWrap component="div">
|
||||
{levelTitle}
|
||||
</Typography>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
{mainComponent}
|
||||
</MathJaxContext>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
@ -0,0 +1,8 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
||||
@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
import { Box, Typography, Grid } from '@mui/material';
|
||||
|
||||
|
||||
function GoodBye({ message }) {
|
||||
return (<Grid container
|
||||
direction="row"
|
||||
justifyContent="center"
|
||||
alignItems="center">
|
||||
<Grid item xs={12} sm={6}>
|
||||
<Box sx={{ m: 3 }}>
|
||||
<Typography variant="body1" component="div">{message}</Typography>
|
||||
</Box>
|
||||
</Grid>
|
||||
</Grid>)
|
||||
}
|
||||
|
||||
export default GoodBye
|
||||
@ -0,0 +1,62 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
import { Typography, Button, Paper, TextField, List, ListItem } from '@mui/material';
|
||||
|
||||
|
||||
function InputZone({ index, history, messageOpen, setMessageOpen, completed, sendTactic, nbLevels, loadNextLevel, errors, lastTactic, undo, finishGame }) {
|
||||
const [curInput, setCurInput] = useState("")
|
||||
|
||||
const inputRef = React.createRef()
|
||||
const nextRef = React.createRef()
|
||||
|
||||
function handleCurInputChange(evt) { setCurInput(evt.target.value) }
|
||||
|
||||
function showPrevMessage() { setMessageOpen(true) }
|
||||
|
||||
useEffect(() => {
|
||||
if (!messageOpen && !completed) inputRef.current.focus()
|
||||
if (!messageOpen && completed && index < nbLevels) nextRef.current.focus()
|
||||
if (!messageOpen && completed && index === nbLevels) finishGame()
|
||||
}, [messageOpen, inputRef, nextRef, completed, finishGame, index, nbLevels])
|
||||
|
||||
async function submitForm(evt) {
|
||||
evt.preventDefault(); // prevent app reloading on form submission
|
||||
await sendTactic(curInput)
|
||||
setCurInput("");
|
||||
}
|
||||
|
||||
return (
|
||||
<Paper sx={{
|
||||
height: "100%", pt: 1, pl: 3, pr: 3, pb: 1,
|
||||
justifyContent: "space-between", alignItems: "center", textAlign: "center"
|
||||
}}
|
||||
elevation={5}>
|
||||
<Typography variant="h5">Invocation zone</Typography>
|
||||
<List dense={true}>
|
||||
{history.map((item, idx) => <ListItem key={idx}>{item}</ListItem>)}
|
||||
</List>
|
||||
<form onSubmit={submitForm}>
|
||||
<TextField
|
||||
id="outlined-input"
|
||||
label="Invocation"
|
||||
autoFocus={true}
|
||||
inputRef={inputRef}
|
||||
value={curInput}
|
||||
onChange={handleCurInputChange}
|
||||
/>
|
||||
<br />
|
||||
<Button type="submit" variant="contained" sx={{ mt: 2 }} disabled={errors.length > 0 || completed || curInput.trim() === ""} disableFocusRipple>Cast spell</Button>
|
||||
<br />
|
||||
<Button variant="text" onClick={undo} sx={{ ml: 3, mt: 2, mb: 2 }} disabled={lastTactic === "" ? true : false || completed}>Undo</Button>
|
||||
{!messageOpen && <Button variant="text" onClick={showPrevMessage} sx={{ ml: 3, mt: 2, mb: 2 }}>See previous message</Button>}
|
||||
<br />
|
||||
{completed && index < nbLevels && <Button variant="contained" ref={nextRef} onClick={loadNextLevel} sx={{ ml: 3, mt: 2, mb: 2 }} disableFocusRipple>Go to Next Level</Button>}
|
||||
</form>
|
||||
</Paper>)
|
||||
}
|
||||
|
||||
export default InputZone
|
||||
@ -0,0 +1,82 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import { MathJax } from "better-react-mathjax";
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
import { Paper, Box, Typography, Accordion, AccordionSummary, AccordionDetails, Tabs, Tab } from '@mui/material';
|
||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||
|
||||
|
||||
function TacticDoc(props) {
|
||||
return (
|
||||
<Accordion>
|
||||
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||
<Typography>{props.tactic.name}</Typography>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails>
|
||||
<MathJax>
|
||||
<ReactMarkdown>{props.tactic.content}</ReactMarkdown>
|
||||
</MathJax>
|
||||
</AccordionDetails>
|
||||
</Accordion>)
|
||||
}
|
||||
|
||||
function LemmaDoc({ lemma }) {
|
||||
return (
|
||||
<Accordion>
|
||||
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||
<Typography>{lemma.userName}</Typography>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails>
|
||||
<MathJax>
|
||||
<ReactMarkdown>{lemma.content}</ReactMarkdown>
|
||||
</MathJax>
|
||||
</AccordionDetails>
|
||||
</Accordion>)
|
||||
}
|
||||
|
||||
function LemmaDocs({ lemmas }) {
|
||||
const [categories, setCategories] = useState(new Map())
|
||||
const [curCategory, setCurCategory] = useState("")
|
||||
|
||||
useEffect(() => {
|
||||
const cats = new Map()
|
||||
lemmas.forEach(function (item) {
|
||||
const category = item.category
|
||||
cats.set(category, (cats.get(category) || []).concat([item]))
|
||||
});
|
||||
setCategories(cats)
|
||||
setCurCategory(cats.keys().next().value)
|
||||
}, [lemmas]);
|
||||
|
||||
return (
|
||||
<Paper sx={{ px: 2, py: 1, mt: 2 }}>
|
||||
<Typography variant="h5">Inventory</Typography>
|
||||
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
|
||||
<Tabs
|
||||
value={curCategory}
|
||||
aria-label="Categories" variant="scrollable" scrollButtons="auto">
|
||||
{(Array.from(categories)).map(([category, _]) => <Tab value={category} label={category} key={category} wrapped />)}
|
||||
</Tabs>
|
||||
</Box>
|
||||
{curCategory && categories.get(curCategory).map((lemma) => <LemmaDoc lemma={lemma} key={lemma.name} />)}
|
||||
</Paper>
|
||||
)
|
||||
}
|
||||
|
||||
function LeftPanel({ spells, inventory }) {
|
||||
return (
|
||||
<Box>
|
||||
{spells.length > 0 &&
|
||||
<Paper sx={{ px: 2, py: 1 }}>
|
||||
<Typography variant="h5" sx={{ mb: 2 }}>Spell book</Typography>
|
||||
{spells.map((spell) => <TacticDoc key={spell.name} tactic={spell} />)}
|
||||
</Paper>}
|
||||
{inventory.length > 0 && <LemmaDocs lemmas={inventory} />}
|
||||
</Box>)
|
||||
}
|
||||
|
||||
export default LeftPanel;
|
||||
@ -0,0 +1,114 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
import Grid from '@mui/material/Unstable_Grid2';
|
||||
|
||||
import LeftPanel from './LeftPanel';
|
||||
import InputZone from './InputZone';
|
||||
import Message from './Message';
|
||||
import TacticState from './TacticState';
|
||||
|
||||
|
||||
|
||||
function Level({ sendJsonMessage, lastMessage, lastJsonMessage, nbLevels, level, setCurLevel, setLevelTitle, setFinished }) {
|
||||
const [index, setIndex] = useState(level) // Level number
|
||||
const [tacticDocs, setTacticDocs] = useState([])
|
||||
const [lemmaDocs, setLemmaDocs] = useState([])
|
||||
|
||||
const [leanData, setLeanData] = useState({})
|
||||
const [history, setHistory] = useState([])
|
||||
const [lastTactic, setLastTactic] = useState("")
|
||||
const [errors, setErrors] = useState([])
|
||||
|
||||
const [message, setMessage] = useState("")
|
||||
const [messageOpen, setMessageOpen] = useState(false)
|
||||
|
||||
|
||||
const [completed, setCompleted] = useState(false)
|
||||
|
||||
// The next function will be called when the level changes
|
||||
useEffect(() => {
|
||||
sendJsonMessage({ "loadLevel": level });
|
||||
}, [level, sendJsonMessage])
|
||||
|
||||
// The next function will be called when a message arrives or the level title changes
|
||||
useEffect(() => {
|
||||
console.log(lastMessage)
|
||||
console.log(lastJsonMessage)
|
||||
if ("nb_levels" in lastJsonMessage) { return } // this is an old message from starting the game
|
||||
const data = lastJsonMessage;
|
||||
if ("title" in data) { // This is the level metadata coming in
|
||||
setLevelTitle("Level " + data["index"] + ": " + data["title"])
|
||||
setIndex(parseInt(data["index"]))
|
||||
setTacticDocs(data["tactics"])
|
||||
setLemmaDocs(data["lemmas"])
|
||||
}
|
||||
|
||||
if (data["message"] !== "" && data.errors.length === 0) {
|
||||
setMessage(data["message"])
|
||||
setMessageOpen(true)
|
||||
}
|
||||
setLeanData(data);
|
||||
setErrors(data.errors);
|
||||
if (data.goals.length === 0 && data.errors.length === 0) {
|
||||
setCompleted(true)
|
||||
}
|
||||
|
||||
}, [lastJsonMessage, lastMessage, setLevelTitle])
|
||||
|
||||
|
||||
function sendTactic(input) {
|
||||
sendJsonMessage({ "runTactic": input });
|
||||
setLastTactic(input);
|
||||
setHistory(history.concat([input]));
|
||||
}
|
||||
|
||||
function undo() {
|
||||
if (errors.length === 0) {
|
||||
sendJsonMessage('undo');
|
||||
}
|
||||
if (history.length > 1) {
|
||||
setLastTactic(history[history.length - 1]);
|
||||
} else {
|
||||
setLastTactic("");
|
||||
};
|
||||
setErrors([]);
|
||||
setHistory(history.slice(0, -1));
|
||||
}
|
||||
|
||||
function loadNextLevel() {
|
||||
setCompleted(false)
|
||||
setHistory([])
|
||||
setCurLevel(index + 1)
|
||||
}
|
||||
|
||||
function closeMessage() {
|
||||
setMessageOpen(false)
|
||||
}
|
||||
|
||||
function finishGame() {
|
||||
setLevelTitle("")
|
||||
setFinished(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<Grid container sx={{ mt: 3, ml: 1, mr: 1 }} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
|
||||
<Grid xs={4}>
|
||||
<LeftPanel spells={tacticDocs} inventory={lemmaDocs} />
|
||||
</Grid>
|
||||
<Grid xs={4}>
|
||||
<InputZone index={index} history={history} messageOpen={messageOpen} setMessageOpen={setMessageOpen} completed={completed} sendTactic={sendTactic} nbLevels={nbLevels} loadNextLevel={loadNextLevel}
|
||||
errors={errors} lastTactic={lastTactic} undo={undo} finishGame={finishGame} />
|
||||
<Message isOpen={messageOpen} content={message} close={closeMessage} />
|
||||
</Grid>
|
||||
<Grid xs={4}>
|
||||
<TacticState goals={leanData.goals} errors={errors} lastTactic={lastTactic} completed={completed} />
|
||||
</Grid>
|
||||
</Grid>
|
||||
)
|
||||
}
|
||||
|
||||
export default Level
|
||||
@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import { MathJax } from "better-react-mathjax";
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
import { Button, Dialog, DialogContent, DialogContentText, DialogActions } from '@mui/material';
|
||||
|
||||
function Message({ isOpen, content, close }) {
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onClose={close}>
|
||||
<DialogContent>
|
||||
<DialogContentText id="alert-dialog-description">
|
||||
<MathJax><ReactMarkdown>{content}</ReactMarkdown></MathJax>
|
||||
</DialogContentText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={close} autoFocus={true} disableFocusRipple>
|
||||
Ok
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default Message
|
||||
@ -0,0 +1,69 @@
|
||||
import React from 'react';
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
import List from '@mui/material/List';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import { Paper, Box, Typography } from '@mui/material';
|
||||
|
||||
const errorRegex = /<stdin>:1:(?<col>[^:]*): (?<msg>.*)/;
|
||||
|
||||
function Goal({ goal }) {
|
||||
const hasObject = typeof goal.objects === "object" && goal.objects.length > 0
|
||||
const hasAssumption = typeof goal.assumptions === "object" && goal.assumptions.length > 0
|
||||
return (
|
||||
<Box sx={{ pl: 2 }}>
|
||||
{hasObject && <Box><Typography variant="h7">Objects</Typography>
|
||||
<List>
|
||||
{goal.objects.map((item) =>
|
||||
<ListItem key={item[0]}>
|
||||
<Typography color="primary" sx={{ mr: 1 }}>{item[0]}</Typography> :
|
||||
<Typography color="secondary" sx={{ ml: 1 }}>{item[1]}</Typography>
|
||||
</ListItem>)}
|
||||
</List></Box>}
|
||||
{hasAssumption && <Box><Typography variant="h7">Assumptions</Typography>
|
||||
<List>
|
||||
{goal.assumptions.map((item) => <ListItem key={item}><Typography color="primary" sx={{ mr: 1 }}>{item[0]}</Typography> :
|
||||
<Typography color="secondary" sx={{ ml: 1 }}>{item[1]}</Typography></ListItem>)}
|
||||
</List></Box>}
|
||||
<Typography variant="h7">Prove:</Typography>
|
||||
<Typography color="primary" sx={{ ml: 2 }}>{goal.goal}</Typography>
|
||||
</Box>)
|
||||
}
|
||||
|
||||
function TacticState({ goals, errors, lastTactic, completed }) {
|
||||
const hasError = typeof errors === "object" && errors.length > 0
|
||||
const hasGoal = typeof goals === "object" && goals.length > 0
|
||||
const hasManyGoal = hasGoal && goals.length > 1
|
||||
var col = ""
|
||||
var msg = ""
|
||||
if (hasError) {
|
||||
const m = errors[0].match(errorRegex)
|
||||
if (m) {
|
||||
col = `Column ${m.groups.col}: `
|
||||
msg = m.groups.msg
|
||||
} else {
|
||||
msg = errors[0]
|
||||
if (msg === "Unrecognized tactic") { msg = "Unknown spell!" }
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Box sx={{ height: "100%" }}>
|
||||
{hasGoal && <Paper sx={{ pt: 1, pl: 2, pr: 3, pb: 1, height: "100%" }}><Typography variant="h5">Current goal</Typography> <Goal goal={goals[0]} /></Paper>}
|
||||
{completed && <Typography variant="h6">Level completed ! 🎉</Typography>}
|
||||
{hasError && <Paper sx={{ pt: 1, pl: 2, pr: 3, pb: 1, height: "100%" }}><Typography variant="h5" color="error">Spell invocation failed</Typography>
|
||||
<Typography sx={{ my: 1 }}>{lastTactic}</Typography>
|
||||
<Typography component="pre" sx={{ my: 1 }}>{col}{msg}</Typography>
|
||||
<Typography>Use the undo button to go back to a sane state.</Typography>
|
||||
</Paper>}
|
||||
{hasManyGoal && <Paper sx={{ pt: 1, pl: 2, pr: 3, pb: 1, mt: 1 }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>Other goals</Typography>
|
||||
{goals.slice(1).map((goal, index) => <Paper><Goal key={index} goal={goal} /></Paper>)}
|
||||
</Paper>}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
export default TacticState
|
||||
@ -0,0 +1,52 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import { MathJax } from "better-react-mathjax";
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
|
||||
import { Box, Typography, Button, CircularProgress, Grid } from '@mui/material';
|
||||
|
||||
|
||||
function Welcome({ sendJsonMessage, lastJsonMessage, setNbLevels, setTitle, startGame, setConclusion }) {
|
||||
|
||||
const [leanData, setLeanData] = useState({})
|
||||
|
||||
// Will run at the very beginning
|
||||
useEffect(() => {
|
||||
sendJsonMessage('info')
|
||||
}, [sendJsonMessage])
|
||||
|
||||
// Will run when a Json message arrives
|
||||
useEffect(() => {
|
||||
if (lastJsonMessage != null && lastJsonMessage.hasOwnProperty("nb_levels")) {
|
||||
setLeanData(lastJsonMessage)
|
||||
setNbLevels(lastJsonMessage.nb_levels)
|
||||
setTitle(lastJsonMessage.title)
|
||||
document.title = lastJsonMessage.title
|
||||
setConclusion(lastJsonMessage.conclusion)
|
||||
}
|
||||
}, [lastJsonMessage, setNbLevels, setTitle, setConclusion])
|
||||
|
||||
let content
|
||||
if ("introduction" in leanData) {
|
||||
content = (<Box sx={{ m: 3 }}>
|
||||
<Typography variant="body1" component="div">
|
||||
<MathJax>
|
||||
<ReactMarkdown>{leanData["introduction"]}</ReactMarkdown>
|
||||
</MathJax>
|
||||
</Typography>
|
||||
<Box textAlign='center' sx={{ m: 5 }}>
|
||||
<Button onClick={startGame} variant="contained">Start rescue mission</Button>
|
||||
</Box>
|
||||
</Box>)
|
||||
} else {
|
||||
content = <Box display="flex" alignItems="center" justifyContent="center" sx={{ height: "calc(100vh - 64px)" }}><CircularProgress /></Box>
|
||||
}
|
||||
return <Grid container direction="row" justifyContent="center" alignItems="center">
|
||||
<Grid item xs={12} sm={6}>{content}</Grid>
|
||||
</Grid>
|
||||
}
|
||||
|
||||
export default Welcome
|
||||
@ -0,0 +1,11 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: Roboto;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Roboto Mono;
|
||||
color: rgba(0, 32, 90, 0.87);
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
import React from 'react'
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
|
||||
self.$RefreshReg$ = () => {};
|
||||
self.$RefreshSig$ = () => () => {};
|
||||
|
||||
const container = document.getElementById('root');
|
||||
const root = createRoot(container); // createRoot(container!) if you use TypeScript
|
||||
root.render(<App />);
|
||||
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "lean4-game",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"homepage": ".",
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.10.4",
|
||||
"@emotion/styled": "^11.10.4",
|
||||
"@fontsource/roboto": "^4.5.8",
|
||||
"@fontsource/roboto-mono": "^4.5.8",
|
||||
"@mui/icons-material": "^5.10.6",
|
||||
"@mui/material": "^5.10.9",
|
||||
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.8",
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^14.4.3",
|
||||
"better-react-mathjax": "^2.0.2",
|
||||
"concurrently": "^7.4.0",
|
||||
"express": "^4.18.2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-markdown": "^8.0.3",
|
||||
"react-refresh": "^0.14.0",
|
||||
"react-use-websocket": "^4.2.0",
|
||||
"web-vitals": "^3.0.3",
|
||||
"ws": "^8.9.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "concurrently -n server,client -c blue,green \"npm run start_server\" \"npm run start_client\"",
|
||||
"start_server": "cd server && node ./index.js",
|
||||
"start_client": "webpack-dev-server --env.NODE_ENV=development --hot",
|
||||
"build": "npm run build_server && npm run build_client",
|
||||
"build_server": "cd server && lake build",
|
||||
"build_client": "webpack --env.NODE_ENV=production"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.1.0",
|
||||
"@babel/core": "^7.1.0",
|
||||
"@babel/preset-env": "^7.1.0",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"babel-loader": "^8.0.2",
|
||||
"css-loader": "^1.0.0",
|
||||
"file-loader": "^6.2.0",
|
||||
"style-loader": "^0.23.0",
|
||||
"webpack": "^4.19.1",
|
||||
"webpack-cli": "^3.1.1",
|
||||
"webpack-dev-server": "^3.1.8"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
build
|
||||
node_modules
|
||||
@ -0,0 +1,25 @@
|
||||
FROM ubuntu:18.04
|
||||
|
||||
WORKDIR /
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get upgrade -y
|
||||
RUN apt-get install -y git curl
|
||||
|
||||
# Install elan
|
||||
RUN curl -sSfL https://github.com/leanprover/elan/releases/download/v1.4.2/elan-x86_64-unknown-linux-gnu.tar.gz | tar xz
|
||||
RUN ./elan-init -y --default-toolchain leanprover/lean4:stable
|
||||
ENV PATH="${PATH}:/root/.elan/bin"
|
||||
|
||||
# clone repos
|
||||
RUN git clone https://github.com/hhu-adam/lean4-game-server.git game-server
|
||||
RUN cd game-server && git checkout gvisor
|
||||
RUN cd game-server && lake build
|
||||
|
||||
RUN git clone https://github.com/hhu-adam/NNG4.git
|
||||
|
||||
WORKDIR /NNG4
|
||||
|
||||
RUN git checkout gvisor
|
||||
RUN lake build
|
||||
CMD ["./build/bin/nng"]
|
||||
@ -0,0 +1,13 @@
|
||||
import NNG.GameServer.Server
|
||||
import NNG.NNG
|
||||
|
||||
def System.FilePath.parent! (fp : System.FilePath) : System.FilePath :=
|
||||
match fp.parent with
|
||||
| some path => path
|
||||
| none => panic! "Couldn't find parent folder"
|
||||
|
||||
unsafe def main : IO Unit := do
|
||||
let build_folder := (← IO.appPath).parent!.parent!
|
||||
let paths : List System.FilePath := [build_folder/"lib",
|
||||
(← Lean.findSysroot) / "lib" / "lean"]
|
||||
Server.runGame `NNG paths
|
||||
@ -0,0 +1,151 @@
|
||||
import NNG.GameServer.HashMapExtension
|
||||
import NNG.GameServer.SingleValPersistentEnvExtension
|
||||
|
||||
/-! # Environment extensions
|
||||
|
||||
The game framework stores almost all its game building data in environment extensions
|
||||
defined in this file. MAyn of them are `SimplePersistentEnvExtension` but we also
|
||||
use `HashMapExtension` and `SingleValPersistentEnvExtension`
|
||||
-/
|
||||
|
||||
|
||||
open Lean
|
||||
|
||||
/-! ## Messages -/
|
||||
|
||||
structure GoalMessageEntry where
|
||||
ctx_size : Nat
|
||||
normalized_goal : Expr
|
||||
intro_nb : Nat
|
||||
message : String
|
||||
deriving Repr
|
||||
|
||||
/-! ## Tactic documentation -/
|
||||
|
||||
structure TacticDocEntry where
|
||||
name : Name
|
||||
content : String
|
||||
deriving ToJson, Repr
|
||||
|
||||
/-- Environment extension for tactic documentation. -/
|
||||
initialize tacticDocExt : SimplePersistentEnvExtension TacticDocEntry (Array TacticDocEntry) ←
|
||||
registerSimplePersistentEnvExtension {
|
||||
name := `tactic_doc
|
||||
addEntryFn := Array.push
|
||||
addImportedFn := Array.concatMap id
|
||||
}
|
||||
|
||||
open Elab Command in
|
||||
/-- Print a registered tactic doc for debugging purposes. -/
|
||||
elab "#print_tactic_doc" : command => do
|
||||
for entry in tacticDocExt.getState (← getEnv) do
|
||||
dbg_trace "{entry.name} : {entry.content}"
|
||||
|
||||
structure TacticSetEntry where
|
||||
name : Name
|
||||
tactics : Array TacticDocEntry
|
||||
deriving ToJson, Repr
|
||||
|
||||
/-- Environment extension for tactic sets. -/
|
||||
initialize tacticSetExt : SimplePersistentEnvExtension TacticSetEntry (Array TacticSetEntry) ←
|
||||
registerSimplePersistentEnvExtension {
|
||||
name := `tactic_set
|
||||
addEntryFn := Array.push
|
||||
addImportedFn := Array.concatMap id
|
||||
}
|
||||
|
||||
open Elab Command in
|
||||
/-- Print all registered tactic sets for debugging purposes. -/
|
||||
elab "#print_tactic_set" : command => do
|
||||
for entry in tacticSetExt.getState (← getEnv) do
|
||||
dbg_trace "{entry.name} : {entry.tactics.map TacticDocEntry.name}"
|
||||
|
||||
/-! ## Lemma documentation -/
|
||||
|
||||
structure LemmaDocEntry where
|
||||
name : Name
|
||||
userName : Name
|
||||
category : String
|
||||
content : String
|
||||
deriving ToJson, Repr
|
||||
|
||||
/-- Environment extension for lemma documentation. -/
|
||||
initialize lemmaDocExt : SimplePersistentEnvExtension LemmaDocEntry (Array LemmaDocEntry) ←
|
||||
registerSimplePersistentEnvExtension {
|
||||
name := `lemma_doc
|
||||
addEntryFn := Array.push
|
||||
addImportedFn := Array.concatMap id
|
||||
}
|
||||
|
||||
open Elab Command in
|
||||
/-- Print a lemma doc for debugging purposes. -/
|
||||
elab "#print_lemma_doc" : command => do
|
||||
for entry in lemmaDocExt.getState (← getEnv) do
|
||||
dbg_trace "{entry.userName} ({entry.name}) in {entry.category}: {entry.content}"
|
||||
|
||||
structure LemmaSetEntry where
|
||||
name : Name
|
||||
title : String
|
||||
lemmas : Array LemmaDocEntry
|
||||
deriving ToJson, Repr
|
||||
|
||||
/-- Environment extension for lemma sets. -/
|
||||
initialize lemmaSetExt : SimplePersistentEnvExtension LemmaSetEntry (Array LemmaSetEntry) ←
|
||||
registerSimplePersistentEnvExtension {
|
||||
name := `lemma_set
|
||||
addEntryFn := Array.push
|
||||
addImportedFn := Array.concatMap id
|
||||
}
|
||||
|
||||
open Elab Command in
|
||||
/-- Print all registered lemma sets for debugging purposes. -/
|
||||
elab "#print_lemma_set" : command => do
|
||||
for entry in lemmaSetExt.getState (← getEnv) do
|
||||
dbg_trace "{entry.name} : {entry.lemmas.map LemmaDocEntry.name}"
|
||||
|
||||
/-! ## Game -/
|
||||
|
||||
structure Game where
|
||||
name : Name
|
||||
title : String := ""
|
||||
introduction : String := ""
|
||||
conclusion : String := ""
|
||||
authors : List String := []
|
||||
nb_levels : Nat := 0
|
||||
deriving Repr, Inhabited, ToJson
|
||||
|
||||
initialize gameExt : SingleValPersistentEnvExtension Game ← registerSingleValPersistentEnvExtension `gameExt Game
|
||||
|
||||
/-! ## Levels -/
|
||||
|
||||
/- Register a (non-persistent) environment extension to hold the current level number. -/
|
||||
initialize curLevelExt : EnvExtension Nat ← registerEnvExtension (pure 0)
|
||||
|
||||
variable {m: Type → Type} [Monad m] [MonadEnv m]
|
||||
|
||||
def setCurLevelIdx (lvl : Nat) : m Unit :=
|
||||
modifyEnv (curLevelExt.setState · lvl)
|
||||
|
||||
def getCurLevelIdx : m Nat := do
|
||||
return curLevelExt.getState (← getEnv)
|
||||
|
||||
structure GameLevel where
|
||||
index: Nat
|
||||
title: String := default
|
||||
introduction: String := default
|
||||
conclusion: String := default
|
||||
tactics: Array TacticDocEntry := default
|
||||
lemmas: Array LemmaDocEntry := default
|
||||
messages: Array GoalMessageEntry := default
|
||||
goal : Expr := default
|
||||
intro_nb : Nat := default
|
||||
deriving Inhabited, Repr
|
||||
|
||||
initialize levelsExt : HashMapExtension Nat GameLevel ← mkHashMapExtension `levels Nat GameLevel
|
||||
|
||||
def getCurLevel [MonadError m] : m GameLevel := do
|
||||
let idx ← getCurLevelIdx
|
||||
match (← levelsExt.find? idx) with
|
||||
| some level => return level
|
||||
| none => throwError "Couldn't find level {idx}"
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
import NNG.GameServer.Commands
|
||||
import NNG.MyNat
|
||||
import NNG.TacticDocs
|
||||
import NNG.LemmaDocs
|
||||
|
||||
Game "NNG"
|
||||
|
||||
Title "The Natural Number Game"
|
||||
|
||||
Introduction
|
||||
"This is a sad day for mathematics. While trying to find glorious new foundations for mathematics,
|
||||
someone removed the law of excluded middle and the axiom of choice. Unsurprisingly,
|
||||
everything collapsed. A brave rescue team managed to retrieve our precious axioms from the wreckage
|
||||
but now we need to rebuild all of mathematics from scratch.
|
||||
|
||||
As a beginning mathematics wizard, you've been tasked to rebuild the theory of natural numbers from
|
||||
the axioms that Giuseppe Peano found under the collapsed tower of number theory. You've been equipped
|
||||
with a level 1 spell book. Good luck."
|
||||
|
||||
Conclusion
|
||||
"There is nothing else so far. Thanks for rescuing natural numbers!"
|
||||
@ -0,0 +1,7 @@
|
||||
import NNG.Metadata
|
||||
import NNG.Levels.Level1
|
||||
import NNG.Levels.Level2
|
||||
import NNG.Levels.Level3
|
||||
import NNG.Levels.Level4
|
||||
import NNG.Levels.Level5
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
import Lean
|
||||
import NNG.MyNat
|
||||
|
||||
open Lean Elab Tactic
|
||||
|
||||
elab "swap" : tactic => do
|
||||
match ← getGoals with
|
||||
| g₁::g₂::t => setGoals (g₂::g₁::t)
|
||||
| _ => pure ()
|
||||
|
||||
macro "induction_on" n:ident : tactic =>
|
||||
`(tactic| refine myInduction $n ?base ?inductive_step; swap; clear $n; intro $n $(mkIdent `ind_hyp); swap)
|
||||
@ -0,0 +1,81 @@
|
||||
const WebSocket = require("ws");
|
||||
const express = require("express");
|
||||
const app = express()
|
||||
const path = require("path")
|
||||
const fs = require("fs");
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
|
||||
const PORT = 8765;
|
||||
|
||||
const server = app
|
||||
.use(express.static('./build'))
|
||||
.listen(PORT, () => console.log(`Listening on ${PORT}`));
|
||||
|
||||
const wss = new WebSocket.Server({ server })
|
||||
|
||||
let cmd = "./build/bin/nng";
|
||||
let cmdArgs = [];
|
||||
// let cmd = "docker";
|
||||
// let cmdArgs = ["run", "--runtime=runsc", "--network=none", "--rm", "-i", "nng4:latest"];
|
||||
|
||||
class ClientConnection {
|
||||
|
||||
content = Buffer.alloc(0)
|
||||
|
||||
constructor(ws){
|
||||
console.log("Socket opened.")
|
||||
this.ws = ws
|
||||
this.ws.send("ok");
|
||||
|
||||
this.ws.on("message", (msg) => {
|
||||
this.send(JSON.parse(msg.toString("utf8")));
|
||||
})
|
||||
|
||||
this.ws.on("close", () => {
|
||||
this.lean.kill();
|
||||
console.log("Socket closed.")
|
||||
})
|
||||
|
||||
this.lean = spawn(cmd, cmdArgs);
|
||||
|
||||
this.lean.stdout.on('readable', () => {
|
||||
this.read();
|
||||
});
|
||||
|
||||
this.lean.stderr.on('data', (data) => {
|
||||
console.error(`stderr: ${data}`);
|
||||
});
|
||||
}
|
||||
|
||||
read () {
|
||||
let chr;
|
||||
while (chr = this.lean.stdout.read(1)) {
|
||||
this.content = Buffer.concat([this.content,chr])
|
||||
if (chr.toString() == "\n") {
|
||||
console.log(this.content.toString())
|
||||
this.ws.send(this.content.toString());
|
||||
this.content = Buffer.alloc(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
send(data) {
|
||||
const str = JSON.stringify(data) + "\n";
|
||||
const byteLength = Buffer.byteLength(str, "utf-8");
|
||||
|
||||
this.lean.stdin.cork();
|
||||
this.lean.stdin.write(str);
|
||||
this.lean.stdin.uncork();
|
||||
}
|
||||
}
|
||||
|
||||
wss.on("connection", function(ws) { // what should a websocket do on connection
|
||||
new ClientConnection(ws)
|
||||
})
|
||||
|
||||
// server.on('upgrade', async function upgrade(request, socket, head) {
|
||||
// wss.handleUpgrade(request, socket, head, function done(ws) {
|
||||
// wss.emit('connection', ws, request);
|
||||
// });
|
||||
// });
|
||||
@ -0,0 +1,20 @@
|
||||
import Lake
|
||||
open Lake DSL
|
||||
|
||||
package nng {
|
||||
-- add package configuration options here
|
||||
}
|
||||
|
||||
lean_lib NNG {
|
||||
-- add library configuration options here
|
||||
}
|
||||
|
||||
lean_lib NNG.levels {
|
||||
-- add library configuration options here
|
||||
}
|
||||
|
||||
@[defaultTarget]
|
||||
lean_exe nng {
|
||||
root := `Main
|
||||
supportInterpreter := true
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
leanprover/lean4:nightly-2022-09-23
|
||||
@ -0,0 +1,63 @@
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
||||
|
||||
module.exports = env => {
|
||||
const isDevelopment = env.NODE_ENV !== 'production';
|
||||
|
||||
const babelOptions = {
|
||||
presets: ['@babel/preset-env', '@babel/preset-react'],
|
||||
plugins: [
|
||||
isDevelopment && require.resolve('react-refresh/babel'),
|
||||
].filter(Boolean),
|
||||
};
|
||||
|
||||
global.$RefreshReg$ = () => {};
|
||||
global.$RefreshSig$ = () => () => {};
|
||||
|
||||
return {
|
||||
entry: "./client/src/index.js",
|
||||
mode: isDevelopment ? 'development' : 'production',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(js|jsx)$/,
|
||||
exclude: [/server/, /node_modules/],
|
||||
use: [{
|
||||
loader: require.resolve('babel-loader'),
|
||||
options: babelOptions,
|
||||
}]
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ["style-loader", "css-loader"]
|
||||
},
|
||||
{
|
||||
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
|
||||
use: [
|
||||
{
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
name: '[name].[ext]',
|
||||
outputPath: 'fonts/'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
resolve: { extensions: ["*", ".js", ".jsx"] },
|
||||
output: {
|
||||
path: path.resolve(__dirname, "client/dist/"),
|
||||
publicPath: "/client/dist/",
|
||||
filename: "bundle.js"
|
||||
},
|
||||
devServer: {
|
||||
contentBase: path.join(__dirname, "client/public/"),
|
||||
port: 3000,
|
||||
publicPath: "http://localhost:3000/dist/",
|
||||
hotOnly: true
|
||||
},
|
||||
plugins: [isDevelopment && new ReactRefreshWebpackPlugin()].filter(Boolean),
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue