Skip to content

Commit

Permalink
fix: parse tree, not AST
Browse files Browse the repository at this point in the history
  • Loading branch information
ouuan committed Jul 22, 2023
1 parent d1a17cc commit 59e5996
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Codle

Guess code like Wordle with AST nodes as letters. [Play it!](https://codle.ouuan.moe)
Guess code like Wordle with parse tree nodes as letters. [Play it!](https://codle.ouuan.moe)

[![preview image](public/images/og-image.png)](https://codle.ouuan.moe)

Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="author" content="ouuan">
<meta name="description" content="A game to guess a target code's AST like Wordle with AST nodes as letters">
<meta name="description" content="A game to guess a target code's parse tree like Wordle with tree nodes as letters">
<link rel="canonical" href="https://<%- host %>">
<title>Codle | Wordle with AST nodes as letters</title>
<title>Codle | Wordle with parse tree nodes as letters</title>

<link href="/index.xml" rel="feed" type="application/rss+xml" title="Codle Puzzles">
<link href="/atom.xml" rel="feed" type="application/atom+xml" title="Codle Puzzles">
Expand Down Expand Up @@ -37,7 +37,7 @@
<link rel="manifest" href="/manifest.json">

<meta property="og:title" content="Codle" />
<meta property="og:description" content="A game to guess a target code's AST like Wordle with AST nodes as letters">
<meta property="og:description" content="A game to guess a target code's parse tree like Wordle with tree nodes as letters">
<meta property="og:type" content="website" />
<meta property="og:url" content="https://<%- host %>" />
<meta property="og:image" content="https://<%- host %>/images/og-image.png" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "codle-game",
"version": "1.0.0",
"description": "Guess code like Wordle with AST nodes as letters",
"description": "Guess code like Wordle with parse tree nodes as letters",
"scripts": {
"lint": "pnpm lint:nofix --fix",
"lint:nofix": "eslint . --ignore-path .gitignore --ext .ts,.vue,.js",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Codle | Wordle with AST nodes as letters",
"name": "Codle | Wordle with parse tree nodes as letters",
"short_name": "Codle",
"start_url": "/",
"display": "standalone",
Expand Down
6 changes: 3 additions & 3 deletions src/components/AboutDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
href="https://github.com/ouuan"
title="ouuan"
/>.
In this game, you need to guess the Abstract Syntax Tree (AST)
In this game, you need to guess the parse tree (concrete syntax tree)
of a piece of code called "target code".
It's like
<external-link
href="https://www.nytimes.com/games/wordle/index.html"
title="Wordle"
/>
with AST nodes as "letters".
with tree nodes as "letters".
</n-p>
<n-p>
It's open-sourced at
Expand Down Expand Up @@ -133,7 +133,7 @@
<p>
That's how Codle works :)
<br>
AST is the only thing that matters, and your code doesn't even need to compile.
Parse tree is the only thing that matters, and your code doesn't even need to compile.
</p>
</n-li>
</n-ul>
Expand Down
25 changes: 13 additions & 12 deletions src/components/GameRuleDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@
so the rule will be easier to understand if you are already familiar with Wordle.
This game would also require some basic knowledge about the C++ programming language and its
<external-link
href="https://en.wikipedia.org/wiki/Abstract_syntax_tree"
title="Abstract Syntax Tree (AST)"
href="https://en.wikipedia.org/wiki/Parse_tree"
title="parse tree"
/>,
but you don't need to master them very well.
</n-p>
<n-p>
In this game,
you need to guess the AST of a piece of C++ code called the <i>target code</i>.
You only need to find out the <i>type</i> of each node in the AST,
you need to guess the parse tree of a piece of C++ code called the <i>target code</i>.
You only need to find out the <i>type</i> of each node in the parse tree,
so the actual content of the code does <strong>not</strong> matter.
In each guess, you need to provide a piece of code,
and you'll get the difference between your code's AST and the target code's AST as a hint.
and you'll get the difference between your code's parse tree
and the target code's parse tree as a hint.
</n-p>
<n-p>
The hint will be in a format similar to Wordle's hint:
Expand All @@ -56,7 +57,7 @@
guess="int x = 0, y = 0, z, w;"
/>
<n-p>
Since AST is a tree, the "correct position" needs more explanation.
Since parse tree is a tree, the "correct position" needs more explanation.
In short, a necessary condition for a node to be
<n-text
v-for="(c, index) of 'colored'"
Expand Down Expand Up @@ -119,7 +120,7 @@
However, only one type will be revealed after every single guess, by design.
</n-p>
<n-p>
So what is the <i>type</i> of an AST node?
So what is the <i>type</i> of a tree node?
The answer is complicated, but you don't have to know every single node type.
Just try a few guesses and you'll roughly know what they look like.
You can hover on (in the real game, not in the demo above)
Expand All @@ -132,17 +133,17 @@
>
node
</grammar-rule-dialog>
, either in the node type list or in the AST,
, either in the node type list or in the tree,
to see the grammar structure of the corresponding node type.
In the grammar structure,
<n-text type="success">
green nodes
</n-text>
are node types displayed in the AST,
are node types displayed in the tree,
<n-text type="warning">
yellow nodes
</n-text>
are "node types" that are not displayed in the AST.
are "node types" that are not displayed in the tree.
Strings are shown as
<n-text code>
"string"
Expand All @@ -160,7 +161,7 @@
href="https://tree-sitter.github.io/tree-sitter/playground"
title="Tree-sitter Playground"
/>
which can show you the AST of a piece of code.
which can show you the parse tree of a piece of code.
</n-p>
<n-p>
It could be troublesome to focus on editing a subtree of your code in the main code editor.
Expand All @@ -175,7 +176,7 @@
there will be an associated algorithm or coding problem.
The target code is guaranteed to be a valid solution to the problem,
but your code doesn't need to solve the problem — it even doesn't need to compile,
as the only thing that matters is the AST.
as the only thing that matters is the parse tree.
The problem won't be hard, since the goal is not to solve it.
</n-p>
<n-p>
Expand Down
4 changes: 2 additions & 2 deletions src/components/MainPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<n-page-header
class="page-header"
title="Codle"
subtitle="Wordle with AST nodes as letters"
subtitle="Wordle with parse tree nodes as letters"
>
<template #extra>
<plausible-dialog />
Expand Down Expand Up @@ -260,7 +260,7 @@ onMounted(async () => {
}
loadPhase.value = 'Loading TreeSitter...';
await initParser;
loadPhase.value = 'Constructing AST...';
loadPhase.value = 'Constructing parse tree...';
const tree = await parse(targetCode.value);
correctRoot.value = tree.rootNode;
loadPhase.value = true;
Expand Down
2 changes: 1 addition & 1 deletion src/vite/transformPuzzles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function transformPuzzles(): Plugin {
async buildStart() {
const feed = new Feed({
title: 'Codle Puzzles',
description: "A game to guess a target code's AST like Wordle with AST nodes as letters",
description: "A game to guess a target code's parse tree like Wordle with tree nodes as letters",
id: `https://${host}`,
link: `https://${host}`,
image: `https://${host}/images/og-image.png`,
Expand Down

0 comments on commit 59e5996

Please sign in to comment.