Skip to content

Commit

Permalink
Merge pull request #42 from LyonSyonII/dev
Browse files Browse the repository at this point in the history
bugfixes
  • Loading branch information
LyonSyonII authored Jul 12, 2024
2 parents 1af6f04 + 2748f36 commit 9742f83
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 23 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/CodeBlock/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function godbolt(code: string, error: string): Promise<EvalResponse> {

const execution = response.indexOf("# Exec");
const stdout_idx = response.indexOf("# Standard out:", execution);

if (stdout_idx !== -1) {
return response.substring(stdout_idx + " Standard out:\n".length + 1);
}
Expand All @@ -84,8 +84,8 @@ async function godbolt(code: string, error: string): Promise<EvalResponse> {
error || response.substring(stderr_idx + "Standard error:\n".length + 1),
);
}

return err("UNKNOWN ERROR");
return "";
}

async function playground(code: string, error: string): Promise<EvalResponse> {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/RobotGame/RobotGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export class RobotGame extends HTMLElement {
}),
);

const simulationError = async () => {
const simulationError = async (err?: { error: string }) => {
this.codeblock.setOutput(
"There was an error during the simulation, please try again.",
err?.error || "There was an error during the simulation, please try again.",
);
await new Promise((r) => setTimeout(r, 1000));
this.codeblock.setRunning(false);
Expand All @@ -102,7 +102,7 @@ export class RobotGame extends HTMLElement {
for (const [r, board] of responses) {
const response = await r;
if (typeof response !== "string") {
return simulationError();
return simulationError(response);
}

const steps = await this.handleResponse(response, board);
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/content/docs/en/first-steps/4-enrolling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ This page should be finished, but there might be some bugs or things that are ha
Proceed with caution!
:::

:::caution[Data collection?]
**DATA WILL NOT BE COLLECTED** in any way, it's just for the exercise.
If you're worried about it, use dummy values that don't match your real data.
:::

You wake up, eat a nutritious breakfast, and head to the guild to get your next mission.

<Guild>
Expand All @@ -42,11 +47,6 @@ I'm sorry, but now that you've completed your first quest, you need to officiall
Please fill in the remaining information in the blanks provided:
</Guild>

:::caution[Data collection?]
**DATA WILL NOT BE COLLECTED** in any way, it's just for the exercise.
If you're worried about it, use dummy values that don't match your real data.
:::

<CodeQuestion
id="4-1"
question="Fill in your name and age:"
Expand Down Expand Up @@ -115,7 +115,7 @@ Double quotes `"` declare a `string`, while single quotes `'` declare a `char`.
I know, that's a lot of concepts, but don't worry, that's all you need to know for now.
:::
<Guild>
Huh? Asking for a favorite cardinal direction is wierd?
Huh? Asking for a favorite cardinal direction is weird?
Well... I can't really argue with that.

Unfortunately, there's only one form left, let's get to it!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ No slimes in sight, at last, your job is done.

Or so you thought, because to your horror three slimes fall from the sky, prepared for the final fight.

> threeslimesfight.png
{ /* TODO: threeslimesfight.png */ }

You're almost there. Hang on!

Expand Down
8 changes: 8 additions & 0 deletions frontend/src/validation/0-robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { anyOf, createRegExp, exactly } from "magic-regexp";
import type { CodeQuestion } from "./CodeQuestion";
import { _ } from "./regex";

export const up = exactly("up");
export const down = exactly("down");
export const left = exactly("left");
export const right = exactly("right");
export const is_slime_right = anyOf("is_slime_right", "isr");
export const is_slime_left = anyOf("is_slime_left", "isl");
export const robotFunction = anyOf(up, down, left, right, is_slime_left, is_slime_right);

export function parenthesisCheck(value: string): string | undefined {
const up = exactly("up").notBefore(_, "(", _, ")", _);
const down = exactly("down").notBefore(_, "(", _, ")", _);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/validation/3-4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
setup: `
__VALUE__
if apples == 16 {
println!("Once you say the magical words 'let mut' the barrier sorrounding the box disappears, and you're able to take the apples.\\nGood job!");
println!("Once you say the magical words 'let mut' the barrier surrounding the box disappears, and you're able to take the apples.\\nGood job!");
println!("SUCCESS");
} else {
println!("There should be 16 apples in the box, but you have {apples}, did you replace some values?");
Expand Down
13 changes: 7 additions & 6 deletions frontend/src/validation/5-6-robot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Functions, type RobotGameProps } from "@components/RobotGame/RobotGameTypes";
import { codeMess, replace } from "./CodeQuestion";
import { createRegExp, exactly, maybe, not, oneOrMore, word } from "magic-regexp";
import { _, end, line, start } from "./regex";
import { char, createRegExp, exactly, maybe, oneOrMore } from "magic-regexp";
import { _, __, end, fn, line, start } from "./regex";

export default {
solveWithMinimumSteps: true,
Expand All @@ -24,20 +24,21 @@ export default {
} as RobotGameProps;

function validator(value: string): string | undefined {
const instructions = exactly(_, oneOrMore(not.whitespace)).times.any();
const instructions = exactly(oneOrMore(char), __).times.any();
const regex = createRegExp(
start, _,
line, _,
"if", _, exactly("?").or(word, "()", maybe(";")).as("first"), _, "{", instructions.as("inst1"), _, "}", _,
"if", _, exactly("?").or(word, "()", maybe(";")).as("second"), _, "{", instructions.as("inst2"), _, "}", _,
"if", _, exactly("?").or(fn, maybe(";")).as("first"), _, "{", _, instructions.as("inst1"), "}", _,
"if", _, exactly("?").or(fn, maybe(";")).as("second"), _, "{", _, instructions.as("inst2"), "}", _,
end
);
console.log(regex.source)
const matches = value.match(regex);
if (!matches) return codeMess;

const { first, second, inst1 = "", inst2 = "" } = matches.groups;
if (!first || !second) return codeMess;

const wrong = "Look closely at the instructions, you don't need a semicolon!";

// slice to remove last semicolon
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/validation/regex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exactly, maybe, whitespace, word, char as _any, digit, oneOrMore } from "magic-regexp";
import { exactly, maybe, whitespace, word, char as _any, digit, oneOrMore, wordChar, anyOf } from "magic-regexp";

/** Matches start of string. */
export const start = exactly().at.lineStart();
Expand Down Expand Up @@ -57,5 +57,9 @@ export const _ = whitespace.times.any();
/** Accepts 1 or more whitespace. */
export const __ = oneOrMore(whitespace);

/** Accepts a semicolon sorrounded by whitespace. */
export const semicolon = exactly(_, ";", _);
/** Accepts a semicolon surrounded by whitespace. */
export const semicolon = exactly(_, ";", _);

export const ident = oneOrMore(anyOf(wordChar, "_"));

export const fn = ident.and("()")

0 comments on commit 9742f83

Please sign in to comment.