Skip to content

Commit 1d26dfa

Browse files
committed
Add stubs for engines that are not implemented yet
1 parent 803e1ae commit 1d26dfa

File tree

7 files changed

+65
-17
lines changed

7 files changed

+65
-17
lines changed

src/app/advanced/[engine]/not-found.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Link from 'next/link'
33
import { redirect, useParams } from 'next/navigation'
44
import { EngineButton } from '@/components/EngineButton';
55
import { RegexEngine } from '@/engines/RegexEngine';
6-
import { getEngines } from '@/engines';
6+
import { getWorkingEngines } from '@/engines';
77

88
const niceNames = new Map<string, string>([
99
["javascript", "JavaScript"],
@@ -68,7 +68,7 @@ export default function NotFound() {
6868
return redirect(`/advanced/${handle.toLowerCase()}/index.html`);
6969
}
7070

71-
const engines = getEngines().filter(engine => engine.notfound && engine.notfound.includes(handle));
71+
const engines = getWorkingEngines().filter(engine => engine.notfound && engine.notfound.includes(handle));
7272

7373
if (engines.length == 1) {
7474
return redirect(`/advanced/${engines[0].handle}/index.html`);

src/app/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/* eslint-disable @next/next/no-img-element */
22
import { EngineButton } from '@/components/EngineButton';
3-
import { getEngines } from '@/engines';
3+
import { getWorkingEngines } from '@/engines';
44
import { Metadata } from 'next';
55

66
export const metadata: Metadata = {
77
title: "RegexPlanet",
8-
description: `Regular expression (regex/regexp) testing and debugging for ${getEngines().map(x => x.short_name).join(', ')}.`,
8+
description: `Regular expression (regex/regexp) testing and debugging for ${getWorkingEngines().map(x => x.short_name).join(', ')}.`,
99
};
1010

1111
export default function Home() {
1212

13-
const buttons = getEngines().map((engine) => {
13+
const buttons = getWorkingEngines().map((engine) => {
1414
return (<EngineButton key={engine.handle} engine={engine} />);
1515
});
1616

src/app/sitemap.xml/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { getEngines } from "@/engines";
2+
import { getWorkingEngines } from "@/engines";
33

44
const ROOT = "https://www.regexplanet.com";
55

@@ -13,7 +13,7 @@ export async function GET() {
1313
`/support/index.html`,
1414
];
1515

16-
getEngines().forEach((engine) => {
16+
getWorkingEngines().forEach((engine) => {
1717
urls.push(`/advanced/${engine.handle}/index.html`);
1818
urls.push(`/advanced/${engine.handle}/options.html`);
1919
});

src/app/status.html/ResultsTable.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import fetchJsonp from 'fetch-jsonp';
88
import { EngineStatus } from '@/types/EngineStatus';
99

1010

11-
function getHost(test_url: string) {
11+
function getHost(test_url: string|undefined) {
12+
if (!test_url) {
13+
return <i>(not configured)</i>
14+
}
1215
const urlObj = new URL(test_url);
1316
if (urlObj.host.endsWith(".gcr.regexplanet.com")) {
1417
return <Link href="https://cloud.google.com/run/">Cloud Run</Link>;
@@ -113,8 +116,8 @@ export function ResultsTable() {
113116

114117
const fetchAllResults = useCallback(() => {
115118
console.log("Fetching all results");
116-
getEngines().map((engine, index) => {
117-
fetchOneResult(engine.status_url)
119+
getEngines().filter((engine) => engine.status_url).map((engine, index) => {
120+
fetchOneResult(engine?.status_url || "") // hack since TS doesn't understand the filter above
118121
.then((result) => {
119122
console.log(`Got result for ${engine.short_name}`, result, index);
120123
setState(prevResult => {
@@ -153,7 +156,7 @@ export function ResultsTable() {
153156
</tr>
154157
</thead>
155158
<tbody>
156-
{getEngines().map((engine, index) => (
159+
{getEngines().filter(engine => engine.status_url).map((engine, index) => (
157160
<tr key={engine.handle}>
158161
<td>
159162
<img className="pe-2" src={engine.logo_icon} alt={engine.short_name} style={{ "height": "1.25em" }} />

src/app/support/index.html/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default function Page() {
1515
<>
1616
<h1>Official Documentation Links</h1>
1717
<hr />
18+
<div className="alert alert-info">You can find patterns and other resources at the <a className="alert-link" href="https://www.regex.zone/">Regex Zone</a>!</div>
1819
{getEngines().map((engine, index) => (
1920
<div className="card m-3 d-inline-block" key={`key${index}`} style={{ "width": "18rem" }}>
2021
<div className="card-header bg-body-tertiary d-flex align-items-center">

src/engines/RegexEngine.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ type RegexEngine = {
2424
help_label: string; // text for the help button on the testing page
2525
help_url: string; // URL destination for the help button on the testing page
2626
handle: string; // unique identifier for the language or engine used as the slug in URLs
27-
level: "alpha" | "beta" | "golden";
27+
level: "alpha" | "beta" | "golden" | "notimplemented"; // The level of support for this engine
2828
links: Record<string, string>; // A map of (name: url) for other help links. These will be displayed on the support page under “Official Documentation”
2929
logo_icon: string; // SVG icon (just the logo, no text) in a square
3030
logo_ar21: string; // SVG logo (including language name) in a 2:1 aspect ratio
31-
nodeping_url: string; // URL of the nodeping status page
31+
nodeping_url?: string; // URL of the nodeping status page
3232
notfound?: string[]; // A list of handles that this is a substitute for (i.e. nodejs is a substitute for javascript)
3333
options: RegexOption[]; // A list of which options it supports.
3434
option_notes?: string; // Notes to display on the options page (html allowed)
3535
short_name: string; // Name of the language or engine
36-
source_url: string; // URL of source code
37-
status_url: string; // URL of the status endpoint
38-
test_url: string; // URL of the test endpoint
36+
source_url?: string; // URL of source code
37+
status_url?: string; // URL of the status endpoint
38+
test_url?: string; // URL of the test endpoint
3939
};
4040

4141
export { type RegexEngine };

src/engines/index.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { TestOutput } from "@/types/TestOutput";
22
import type { RegexEngine } from "./RegexEngine";
3+
4+
import { dotnet } from "./dotnet";
5+
import { erlang } from "./erlang";
36
import { go } from "./go";
7+
import { haskell } from "./haskell";
48
import { java } from "./java";
9+
import { mysql } from "./mysql";
510
import { nodejs } from "./nodejs";
611
import { perl } from "./perl";
712
import { php } from "./php";
@@ -13,8 +18,12 @@ import { tcl } from "./tcl";
1318
import { xregexp } from "./xregexp";
1419

1520
const engineMap = new Map<string, RegexEngine>([
21+
[erlang.handle, erlang],
1622
[go.handle, go],
23+
[haskell.handle, haskell],
1724
[java.handle, java],
25+
[mysql.handle, mysql],
26+
[dotnet.handle, dotnet],
1827
[nodejs.handle, nodejs],
1928
[perl.handle, perl],
2029
[php.handle, php],
@@ -38,6 +47,14 @@ class EngineNotFoundError extends Error {
3847
handle: string;
3948
}
4049

50+
class EngineNotImplementedError extends Error {
51+
constructor(handle: string) {
52+
super("Engine not implemented");
53+
this.handle = handle;
54+
}
55+
handle: string;
56+
}
57+
4158
function getEngineOrThrow(handle: string): RegexEngine {
4259
const theEngine = engineMap.get(handle);
4360
if (!theEngine) {
@@ -50,10 +67,30 @@ function getEngines(): Array<RegexEngine> {
5067
return Array.from(engineMap.values());
5168
}
5269

70+
function getWorkingEngineOrThrow(handle: string): RegexEngine {
71+
const theEngine = engineMap.get(handle);
72+
if (!theEngine) {
73+
throw new EngineNotFoundError(handle);
74+
}
75+
if (!theEngine.test_url) {
76+
throw new EngineNotImplementedError(handle);
77+
}
78+
return theEngine;
79+
}
80+
81+
function getWorkingEngines(): Array<RegexEngine> {
82+
return Array.from(engineMap.values()).filter((engine) => engine.test_url);
83+
}
84+
5385
async function runTest(
5486
engine: RegexEngine,
5587
testInput: FormData
5688
): Promise<TestOutput> {
89+
90+
if (!engine.test_url) {
91+
throw new EngineNotImplementedError(engine.handle);
92+
}
93+
5794
// this is a bogus 'as', but next build insists on it
5895
const postData = new URLSearchParams(
5996
testInput as unknown as Record<string, string>
@@ -72,4 +109,11 @@ async function runTest(
72109
}
73110

74111

75-
export { getEngines, getEngine, getEngineOrThrow, runTest };
112+
export {
113+
getEngines,
114+
getEngine,
115+
getEngineOrThrow,
116+
getWorkingEngines,
117+
getWorkingEngineOrThrow,
118+
runTest,
119+
};

0 commit comments

Comments
 (0)