Skip to content

Commit

Permalink
take out type checker tests for now
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Jul 3, 2024
1 parent d44f13c commit 7f3806f
Show file tree
Hide file tree
Showing 5 changed files with 344 additions and 291 deletions.
15 changes: 13 additions & 2 deletions src/components/LanguageShowcase.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { printValue } from '../lib/print-value';
import { printValue, printType } from '../lib/print-value';
import { features } from '../language/features';
import Toast from "react-bootstrap/Toast";
import { tokenizer as plainTokenizer } from '../language/tokenizer';
Expand All @@ -21,6 +21,7 @@ function LanguageShowCase({ tokenizer, parser, evaluator }: {
const [text, setText] = useState("");
const [error, setError] = useState<string>("");
const [result, setResult] = useState<Value[]>([]);
const [typeResult, setTypeResult] = useState<Type[]>([]);
const [checkTypes, setCheckTypes] = useStickyState<boolean>(false, "check-types");
const [tcError, setTcError] = useState<string>("");
const [tree, setTree] = useState<SExpr[]>([]);
Expand All @@ -46,13 +47,14 @@ function LanguageShowCase({ tokenizer, parser, evaluator }: {
setTree([]);
setError("");
setResult([]);
setTypeResult([]);
setTcError("");
return;
}
if (checkTypes) {
try {
const e = parser(plainTokenizer(text, false));
tcTop(e);
setTypeResult(tcTop(e));
setTcError("");
} catch(e) {
// @ts-ignore
Expand All @@ -71,6 +73,7 @@ function LanguageShowCase({ tokenizer, parser, evaluator }: {
const msg = e.message as string;
setError(`syntax error: ${msg}`);
setResult([]);
setTypeResult([]);
setTree([]);
}
}
Expand All @@ -81,6 +84,7 @@ function LanguageShowCase({ tokenizer, parser, evaluator }: {
setResult([]);
setTcError("");
setTree([]);
setTypeResult([]);
setText(t);
try {
parser(tokenizer(t));
Expand All @@ -93,6 +97,7 @@ function LanguageShowCase({ tokenizer, parser, evaluator }: {
setText("");
setResult([]);
setTree([]);
setTypeResult([]);
}
return (
<div className="mb-4 mt-4" style={{ maxWidth: "40rem" }}>
Expand Down Expand Up @@ -180,6 +185,12 @@ function LanguageShowCase({ tokenizer, parser, evaluator }: {
<pre>{result.map(v => printValue(v)).join(" ")}</pre>
</samp>
</div>}
{checkTypes && typeResult.length > 0 && <div>
<div className="py-1">Type Value:</div>
<samp>
<pre>{typeResult.map(v => printType(v)).join(" ")}</pre>
</samp>
</div>}
{tree && Array.isArray(tree) && tree.length > 0 && <div className="py-2">
<details>
<summary>Syntax Tree</summary>
Expand Down
Loading

0 comments on commit 7f3806f

Please sign in to comment.