Compare commits
8 Commits
2b98f56240
...
fbc8124646
Author | SHA1 | Date | |
---|---|---|---|
fbc8124646 | |||
a1c076305d | |||
8abd963c8e | |||
83c382d361 | |||
67ff5203a6 | |||
86ef6f8c09 | |||
eded324a43 | |||
45cee168e6 |
21
public/img/zig_logo.svg
Normal file
21
public/img/zig_logo.svg
Normal file
@ -0,0 +1,21 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 153 140">
|
||||
<g fill="#f7a41d">
|
||||
<g>
|
||||
<polygon points="46,22 28,44 19,30"/>
|
||||
<polygon points="46,22 33,33 28,44 22,44 22,95 31,95 20,100 12,117 0,117 0,22" shape-rendering="crispEdges"/>
|
||||
<polygon points="31,95 12,117 4,106"/>
|
||||
</g>
|
||||
<g>
|
||||
<polygon points="56,22 62,36 37,44"/>
|
||||
<polygon points="56,22 111,22 111,44 37,44 56,32" shape-rendering="crispEdges"/>
|
||||
<polygon points="116,95 97,117 90,104"/>
|
||||
<polygon points="116,95 100,104 97,117 42,117 42,95" shape-rendering="crispEdges"/>
|
||||
<polygon points="150,0 52,117 3,140 101,22"/>
|
||||
</g>
|
||||
<g>
|
||||
<polygon points="141,22 140,40 122,45"/>
|
||||
<polygon points="153,22 153,117 106,117 120,105 125,95 131,95 131,45 122,45 132,36 141,22" shape-rendering="crispEdges"/>
|
||||
<polygon points="125,95 130,110 106,117"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 832 B |
@ -16,7 +16,7 @@ const { showSidebarButton = true } = Astro.props;
|
||||
|
||||
<a
|
||||
href="/"
|
||||
class="inline-block px-4 font-display font-black text-2xl hover:underline"
|
||||
class="px-4 flex gap-2 items-center"
|
||||
>
|
||||
<img
|
||||
class="inline-block h-10"
|
||||
@ -25,7 +25,7 @@ const { showSidebarButton = true } = Astro.props;
|
||||
/>
|
||||
</a>
|
||||
<a
|
||||
href="/learn/"
|
||||
href="/en/latest/learn/"
|
||||
class="hidden sm:inline-block px-4 font-display font-bold-text-xl hover:underline"
|
||||
>
|
||||
Learn
|
||||
@ -36,12 +36,6 @@ const { showSidebarButton = true } = Astro.props;
|
||||
>
|
||||
Standard Library
|
||||
</a>
|
||||
<a
|
||||
href="/api/help/"
|
||||
class="hidden sm:inline-block px-4 font-display font-bold-text-xl hover:underline"
|
||||
>
|
||||
Help
|
||||
</a>
|
||||
<a
|
||||
href="/spec/"
|
||||
class="hidden sm:inline-block px-4 font-display font-bold-text-xl hover:underline"
|
||||
|
@ -4,10 +4,15 @@ import type { PageEntry } from "../layouts/PagesLayout.astro";
|
||||
const entry: PageEntry = Astro.props.entry;
|
||||
const basePath: string = Astro.props.basePath;
|
||||
|
||||
const entryPath = entry.path === "index"? "": entry.path;
|
||||
const entryPath = is_index_file(entry.path)? "": entry.path;
|
||||
|
||||
const entryUrl = basePath + entryPath + (entryPath.endsWith("/")? "" : "/");
|
||||
|
||||
function is_index_file(p) {
|
||||
return p.endsWith("index")
|
||||
|| p.endsWith("index.md")
|
||||
|| p.endsWith("index.mdx")
|
||||
}
|
||||
---
|
||||
|
||||
{
|
||||
@ -26,14 +31,14 @@ const entryUrl = basePath + entryPath + (entryPath.endsWith("/")? "" : "/");
|
||||
entry.children && (
|
||||
<>
|
||||
<div class="mt-6 px-3 py-1 uppercase font-display text-c-text-2 font-medium">
|
||||
{entry.title}
|
||||
{entry.title.replaceAll("-", " ")}
|
||||
</div>
|
||||
|
||||
<ul class="my-1">
|
||||
{entry.children!.map((nextEntry) => (
|
||||
<Astro.self
|
||||
entry={nextEntry}
|
||||
basePath={`${basePath}${entry.path}/`}
|
||||
basePath={`${basePath}${entry.path}`}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
|
@ -3,7 +3,7 @@ import PagesLayout from "./PagesLayout.astro";
|
||||
|
||||
const { frontmatter, headings } = Astro.props;
|
||||
|
||||
const posts = await Astro.glob("../pages/learn/**/*.{md,mdx}");
|
||||
const posts = await Astro.glob("@/pages/learn/**/*.{md,mdx}");
|
||||
const indexSubpath = `/learn/index.mdx`;
|
||||
---
|
||||
|
||||
|
150
src/layouts/NewDocsLayout.astro
Normal file
150
src/layouts/NewDocsLayout.astro
Normal file
@ -0,0 +1,150 @@
|
||||
---
|
||||
import Navbar from "../components/Navbar.astro";
|
||||
import BaseLayout from "./BaseLayout.astro";
|
||||
import TOC from "../components/TOC.astro";
|
||||
import Sidebar from "../components/Sidebar.astro";
|
||||
|
||||
export type PageEntry = {
|
||||
path: string;
|
||||
title?: string;
|
||||
children?: Array<PageEntry>;
|
||||
};
|
||||
|
||||
export interface AstroFile {
|
||||
frontmatter: Frontmatter
|
||||
__usesAstroImage: boolean
|
||||
url: string
|
||||
file: string
|
||||
relative_file: string
|
||||
}
|
||||
|
||||
export interface Frontmatter {
|
||||
layout: string
|
||||
title: string
|
||||
order: number
|
||||
}
|
||||
|
||||
type Props = {
|
||||
/** The directory where all the md/mdx files start from */
|
||||
base_dir: string
|
||||
frontmatter: Frontmatter;
|
||||
headings: any;
|
||||
posts: Array<AstroFile>;
|
||||
};
|
||||
|
||||
const {
|
||||
base_dir,
|
||||
frontmatter,
|
||||
headings,
|
||||
posts
|
||||
}: Props = Astro.props;
|
||||
|
||||
const base_dir_end = base_dir.length;
|
||||
|
||||
const posts_2 = posts
|
||||
.map(post => ({
|
||||
...post,
|
||||
relative_file: post.file.substring(base_dir_end),
|
||||
path: post.file.substring(base_dir_end).replace(/\.mdx?$/, ""),
|
||||
title: post.frontmatter.title,
|
||||
}))
|
||||
.sort((p1, p2) => p1.frontmatter.order > p2.frontmatter.order? 1 : -1);
|
||||
|
||||
// build a hierarchy of the files
|
||||
const second_level: Record<string, Array<AstroFile>> = {
|
||||
"_": [],
|
||||
};
|
||||
for (const post of posts_2) {
|
||||
const fragments = post.path.split("/");
|
||||
if (fragments.length === 3) {
|
||||
const folder_name = fragments[1]!;
|
||||
|
||||
// create if not exists
|
||||
if (second_level[folder_name] === undefined) {
|
||||
second_level[folder_name] = [];
|
||||
}
|
||||
second_level[folder_name].push(post);
|
||||
}
|
||||
else if (fragments.length === 2) {
|
||||
// add to root folder
|
||||
second_level["_"]!.push(post);
|
||||
}
|
||||
}
|
||||
|
||||
// transform to the layout that the sidebar expects
|
||||
|
||||
const entries: Array<any> = [];
|
||||
for (const levels_key in second_level) {
|
||||
if (levels_key === "_") {
|
||||
// top level
|
||||
const posts = second_level[levels_key]!;
|
||||
entries.push(...posts)
|
||||
}
|
||||
else {
|
||||
const posts = second_level[levels_key]!;
|
||||
const parentEntry = {
|
||||
path: "",
|
||||
title: levels_key,
|
||||
children: posts,
|
||||
};
|
||||
entries.push(parentEntry);
|
||||
}
|
||||
}
|
||||
|
||||
const index_page = entries.find(post => post.relative_file === "/index.md" || post.relative_file === "/index.mdx");
|
||||
if (index_page === undefined && process.env.NODE_ENV !== "production") {
|
||||
console.error("\n\nBuilding without an index page");
|
||||
console.error("Props base_dir:", base_dir);
|
||||
}
|
||||
const basePath = index_page?.url ?? "/";
|
||||
---
|
||||
|
||||
<BaseLayout title={frontmatter.title}>
|
||||
<Navbar />
|
||||
|
||||
<div
|
||||
class="lg:grid lg:grid-cols-[14rem_auto_12rem] lg:container mx-auto font-display"
|
||||
>
|
||||
<div
|
||||
id="sidebar"
|
||||
class="pt-12 h-screen lg:sticky top-0 fixed z-10 bg-c-bg w-60 lg:w-auto border-r-2 lg:border-0
|
||||
border-c-border-1 -translate-x-64 lg:translate-x-0 transition-transform"
|
||||
>
|
||||
<nav class="py-4 pr-2 overflow-x-scroll h-[calc(100vh-3rem)]">
|
||||
{
|
||||
entries.map((entry) => (
|
||||
<Sidebar entry={entry} basePath={basePath} />
|
||||
))
|
||||
}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<main
|
||||
class="pt-[3.5rem] pb-[10rem] lg:pl-12 lg:pr-4 markdown min-w-0 small-container mx-auto"
|
||||
>
|
||||
<slot />
|
||||
</main>
|
||||
|
||||
<div
|
||||
class="lg:pt-12 hidden lg:block pt-4 max-h-screen overflow-x-scroll sticky top-0"
|
||||
>
|
||||
<nav class="rounded-md lg:mt-10">
|
||||
<h2 class="font-display font-medium pb-2 text-c-text-2">
|
||||
On this page
|
||||
</h2>
|
||||
|
||||
<TOC headings={headings} />
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
import { highlightOnDom } from "./thpHighlighter";
|
||||
document.addEventListener("DOMContentLoaded", highlightOnDom);
|
||||
</script>
|
||||
<script>
|
||||
import { sidebarHighlight } from "./utils";
|
||||
// Highlight the current url of the sidebar
|
||||
document.addEventListener("DOMContentLoaded", sidebarHighlight);
|
||||
</script>
|
||||
</BaseLayout>
|
20
src/pages/en/latest/learn/_wrapper.astro
Normal file
20
src/pages/en/latest/learn/_wrapper.astro
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
import NewDocsLayout, { type AstroFile } from "@/layouts/NewDocsLayout.astro";
|
||||
|
||||
const { frontmatter, headings } = Astro.props;
|
||||
// Get all the posts from this dir
|
||||
|
||||
const posts = await Astro.glob("./**/*.{md,mdx}") as unknown as Array<AstroFile>;
|
||||
|
||||
// Current dir
|
||||
const current_dir = import.meta.dirname;
|
||||
---
|
||||
|
||||
<NewDocsLayout
|
||||
base_dir={current_dir}
|
||||
frontmatter={frontmatter}
|
||||
headings={headings}
|
||||
posts={posts}
|
||||
>
|
||||
<slot />
|
||||
</NewPagesLayout>
|
@ -1,8 +1,9 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Comments
|
||||
order: 2
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Comments
|
||||
|
@ -1,8 +1,9 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Datatypes
|
||||
order: 4
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Datatypes
|
||||
|
@ -1,9 +1,10 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Hello world
|
||||
order: 1
|
||||
---
|
||||
import InteractiveCode from "../../../components/InteractiveCode.astro";
|
||||
import Code from "../../../components/Code.astro"
|
||||
import InteractiveCode from "@/components/InteractiveCode.astro";
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Hello, world!
|
||||
|
@ -1,8 +1,9 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Operators
|
||||
order: 5
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Operators
|
||||
|
@ -1,9 +1,9 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Variables
|
||||
|
||||
order: 3
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Variables
|
||||
|
9
src/pages/en/latest/learn/classes/abstract.mdx
Normal file
9
src/pages/en/latest/learn/classes/abstract.mdx
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
layout: "../_wrapper.astro"
|
||||
title: Abstract
|
||||
---
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Abstract
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Anonymous classes
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Anonymous classes
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Constructor/Destructor
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Constructor/Destructor
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Basics
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Classes
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Inheritance
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Inheritance
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Interfaces
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Interfaces
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Magic methods
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Magic methods
|
||||
|
15
src/pages/en/latest/learn/classes/readonly.mdx
Normal file
15
src/pages/en/latest/learn/classes/readonly.mdx
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
layout: "../_wrapper.astro"
|
||||
title: Readonly
|
||||
---
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Readonly
|
||||
|
||||
<Code thpcode={`
|
||||
class Caño
|
||||
{
|
||||
}
|
||||
`} />
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Static
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Static in classes
|
||||
|
7
src/pages/en/latest/learn/classes/visibility.mdx
Normal file
7
src/pages/en/latest/learn/classes/visibility.mdx
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
layout: "../_wrapper.astro"
|
||||
title: Visibility
|
||||
---
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Visibility
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Arrays
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Arrays
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Enums
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Enums
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Maps
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Maps
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Tuples
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Tuples
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Tagged unions
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Tagged unions
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Nullable types
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Nullable types
|
||||
|
@ -1,9 +1,9 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Try/Exceptions
|
||||
---
|
||||
import InteractiveCode from "../../../components/InteractiveCode.astro";
|
||||
import Code from "../../../components/Code.astro"
|
||||
import InteractiveCode from "@/components/InteractiveCode.astro";
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Try/exceptions
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Blocks
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Blocks
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Conditionals
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Conditionals
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Loops
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Loops
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Match
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Match
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Declaration
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Declaration
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Higher Order Functions
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Higher Order functions
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Lambdas
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Lambdas / Anonymous functions
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Function parameters
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Function parameters
|
||||
|
@ -1,68 +1,10 @@
|
||||
---
|
||||
layout: ../../layouts/DocsLayout.astro
|
||||
layout: "./_wrapper.astro"
|
||||
title: Welcome
|
||||
pagesLayout:
|
||||
- path: index
|
||||
- path: install
|
||||
- path: cheatsheet
|
||||
- path: basics
|
||||
title: Basics
|
||||
children:
|
||||
- path: hello-world
|
||||
- path: comments
|
||||
- path: variables
|
||||
- path: datatypes
|
||||
- path: operators
|
||||
- path: flow-control
|
||||
title: Flow control
|
||||
children:
|
||||
- path: conditionals
|
||||
- path: loops
|
||||
- path: match
|
||||
- path: blocks
|
||||
- path: data-structures
|
||||
title: Data structures
|
||||
children:
|
||||
- path: tuples
|
||||
- path: arrays
|
||||
- path: maps
|
||||
- path: enums
|
||||
- path: unions
|
||||
- path: functions
|
||||
title: Functions
|
||||
children:
|
||||
- path: declaration
|
||||
- path: parameters
|
||||
- path: higher-order
|
||||
- path: lambdas
|
||||
- path: error-handling
|
||||
title: Error handling
|
||||
children:
|
||||
- path: "null"
|
||||
- path: try
|
||||
- path: classes
|
||||
title: Classes
|
||||
children:
|
||||
- path: definition
|
||||
- path: constructor
|
||||
- path: inheritance
|
||||
- path: static
|
||||
- path: visibility
|
||||
- path: readonly
|
||||
- path: abstract
|
||||
- path: interfaces
|
||||
- path: anonymous
|
||||
- path: magic
|
||||
- path: templating
|
||||
title: Templating
|
||||
children:
|
||||
- path: intro
|
||||
- path: components
|
||||
- path: props
|
||||
- path: control-flow
|
||||
order: 1
|
||||
---
|
||||
import InteractiveCode from "../../components/InteractiveCode.astro";
|
||||
import Code from "../../components/Code.astro"
|
||||
import InteractiveCode from "@/components/InteractiveCode.astro";
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
|
||||
# Welcome
|
@ -1,9 +1,9 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Components
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Info from "../../../components/docs/Info.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
import Info from "@/components/docs/Info.astro"
|
||||
|
||||
# Components
|
||||
|
@ -1,9 +1,9 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Control flow
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Info from "../../../components/docs/Info.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
import Info from "@/components/docs/Info.astro"
|
||||
|
||||
# Control flow
|
||||
|
@ -1,9 +1,9 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Introduction
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Info from "../../../components/docs/Info.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
import Info from "@/components/docs/Info.astro"
|
||||
|
||||
# THP templating
|
||||
|
@ -1,9 +1,9 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Props
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Info from "../../../components/docs/Info.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
import Info from "@/components/docs/Info.astro"
|
||||
|
||||
# Props
|
||||
|
@ -54,7 +54,7 @@ const [thp_html] = await native_highlighter(
|
||||
<a
|
||||
class="inline-block font-display text-lg rounded-full border-2 border-pink-400 py-2 px-8
|
||||
transition-colors hover:text-black hover:bg-pink-400 mt-2"
|
||||
href="/learn/"
|
||||
href="/en/latest/learn/"
|
||||
>
|
||||
Learn
|
||||
</a>
|
||||
|
@ -1,230 +0,0 @@
|
||||
---
|
||||
layout: ../../layouts/DocsLayout.astro
|
||||
title: Cheatsheet
|
||||
disable_container: true
|
||||
---
|
||||
import TwoColumn from "../../components/TwoColumn.astro"
|
||||
import Code from "../../components/Code.astro"
|
||||
|
||||
# Language cheatsheet
|
||||
|
||||
Comparisons to PHP are noted.
|
||||
|
||||
<TwoColumn cols="grid-cols-[1fr_1fr] gap-2">
|
||||
|
||||
<Code thpcode={`
|
||||
// THP code is written directly, it's not enclosed in any ?php tag
|
||||
// Single line comments are written with two slashes
|
||||
|
||||
/*
|
||||
Multiline comments use slash-asterisk
|
||||
and can be /* nested */
|
||||
*/
|
||||
|
||||
// there is no echo, only print
|
||||
// Unlike PHP, parenthesis are required
|
||||
print("Hello world")
|
||||
`} />
|
||||
|
||||
```php
|
||||
<?php
|
||||
// PHP requires a <?php opening tag
|
||||
|
||||
/*
|
||||
PHP cannot nest multiline comments
|
||||
/* this would be an error * /
|
||||
*/
|
||||
|
||||
# PHP also has hash comments. THP doesn't
|
||||
|
||||
print "Hello world";
|
||||
```
|
||||
</TwoColumn>
|
||||
|
||||
|
||||
|
||||
|
||||
## Variables
|
||||
|
||||
|
||||
<TwoColumn cols="grid-cols-[1fr_1fr] gap-2">
|
||||
|
||||
<Code no_warnings={true} thpcode={`
|
||||
// THP has explicit variable declaration
|
||||
// Variables don't start with a dollar sign ($)
|
||||
// Variables are declared with \`var\`
|
||||
var age = 32
|
||||
|
||||
// Immutable variables are declared with \`val\`,
|
||||
// and can't be reassigned
|
||||
val name = "John"
|
||||
|
||||
// Variables may have a datatype declaration
|
||||
// This is an immutable variable with a type
|
||||
String road = "Abbey road"
|
||||
// This is a mutable variable with a type
|
||||
var String name = "The Beatles"
|
||||
`} />
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
|
||||
$age = 32;
|
||||
|
||||
|
||||
// There is no PHP equivalent
|
||||
$name = "John";
|
||||
|
||||
// You can't annotate the type of a variable in PHP
|
||||
|
||||
$road = "Abbey road";
|
||||
|
||||
$name = "The Beatles";
|
||||
```
|
||||
|
||||
</TwoColumn>
|
||||
|
||||
## Datatypes
|
||||
|
||||
<TwoColumn cols="grid-cols-[1fr_1fr] gap-2">
|
||||
<Code no_warnings={true} thpcode={`
|
||||
// Only double quotes, never single quotes
|
||||
String name = "Jane"
|
||||
// Interpolation
|
||||
String full_name = "{name} Doe"
|
||||
|
||||
Int age = 25
|
||||
Float interest = 3.22
|
||||
|
||||
// An integer with a leading zero is an error,
|
||||
// you must use \`0o\` for octal
|
||||
// Int invalid = 0755
|
||||
Int valid = 0o755
|
||||
|
||||
// Case sensitive, only \`true\` or \`false\`
|
||||
Bool has_a_cute_dress = true
|
||||
`} />
|
||||
```php
|
||||
|
||||
$name = 'Jane';
|
||||
|
||||
$full_name = "$name Doe";
|
||||
|
||||
$age = 25;
|
||||
$interest = 3.22;
|
||||
|
||||
|
||||
|
||||
$invalid = 0755;
|
||||
$valid = 0o755;
|
||||
|
||||
// PHP allows true/false in any case, for some reason
|
||||
$has_a_cute_dress = TrUe;
|
||||
```
|
||||
</TwoColumn>
|
||||
|
||||
|
||||
<TwoColumn cols="grid-cols-[1fr_1fr] gap-2">
|
||||
<Code no_warnings={true} thpcode={`
|
||||
// String concatenation uses \`++\`
|
||||
print("Hello " ++ "world")
|
||||
|
||||
// Basic operators
|
||||
var res = 1 + 2 - 3 * 4 % 5
|
||||
|
||||
res += 2
|
||||
res -= 2
|
||||
res *= 2
|
||||
res /= 2
|
||||
res %= 2
|
||||
|
||||
// There are no prefix/postfix increment/decrement
|
||||
//
|
||||
//
|
||||
`} />
|
||||
```php
|
||||
|
||||
print("Hello " . "world");
|
||||
|
||||
|
||||
$res = 1 + 2 - 3 * 4 % 5;
|
||||
|
||||
res += 2;
|
||||
res -= 2;
|
||||
res *= 2;
|
||||
res /= 2;
|
||||
res %= 2;
|
||||
|
||||
|
||||
++res;
|
||||
res--;
|
||||
```
|
||||
</TwoColumn>
|
||||
|
||||
## Flow control
|
||||
|
||||
<TwoColumn cols="grid-cols-[1fr_1fr] gap-2">
|
||||
<Code no_warnings={true} thpcode={`
|
||||
// Parenthesis not required, braces required
|
||||
if age < 18
|
||||
{
|
||||
print("Not allowed")
|
||||
}
|
||||
else if age == 18
|
||||
{
|
||||
print("Allowed, barely")
|
||||
}
|
||||
else
|
||||
{
|
||||
print("Allowed")
|
||||
}
|
||||
|
||||
// Conditionals are expressions
|
||||
val gift = if prefers_silver
|
||||
{
|
||||
"silver necklace"
|
||||
}
|
||||
else
|
||||
{
|
||||
"gold necklace"
|
||||
}
|
||||
`} />
|
||||
|
||||
```php
|
||||
|
||||
if (age < 18) {
|
||||
print("Not allowed");
|
||||
} else if (age === 18) {
|
||||
print("Allowed, barely");
|
||||
} else {
|
||||
print("Allowed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$gift = "";
|
||||
if (prefers_silver) {
|
||||
$gift = "silver necklace";
|
||||
} else {
|
||||
$gift = "gold necklace";
|
||||
}
|
||||
```
|
||||
</TwoColumn>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<TwoColumn cols="grid-cols-[1fr_1fr] gap-2">
|
||||
<Code no_warnings={true} thpcode={`
|
||||
`} />
|
||||
```php
|
||||
```
|
||||
</TwoColumn>
|
@ -1,9 +0,0 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
title: Abstract
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
|
||||
# Abstract
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
title: Readonly
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
|
||||
# Readonly
|
||||
|
||||
<Code thpcode={`
|
||||
class Caño
|
||||
{
|
||||
}
|
||||
`} />
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
---
|
||||
layout: ../../../layouts/DocsLayout.astro
|
||||
title: Visibility
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
|
||||
# Visibility
|
@ -1,251 +0,0 @@
|
||||
# Idea 1
|
||||
|
||||
|
||||
let mut x = 20
|
||||
let y = 30
|
||||
|
||||
type Something = ...
|
||||
|
||||
Something s1 = ...
|
||||
Something s2 = s1
|
||||
|
||||
|
||||
// Passes `some` by reference, but it's immutable. Cannot call mutable methods
|
||||
// or use it in mutable operations
|
||||
fun do_something(Something some) -> Bool {}
|
||||
do_something(s1)
|
||||
|
||||
// Passes `some` by reference, and it's mutable. Can call mutable methods
|
||||
// or use it in mutable operations
|
||||
fun do_something(&Something some) -> Bool {}
|
||||
do_something(&s1)
|
||||
|
||||
|
||||
let mut arr1 = Array(10, 20, 30)
|
||||
let mut arr2 = &arr1
|
||||
|
||||
|
||||
Owned/Reference Mutable
|
||||
Type Owned n
|
||||
&Type Reference n
|
||||
mut Type Owned y
|
||||
&mut Type Reference y
|
||||
|
||||
|
||||
Copy/Reference Mutable Equivalent
|
||||
Some Copy n 1 (technically) references the other data
|
||||
&Some Reference n 1 References the other data
|
||||
mut Some Copy y 2 Creates a __mutable__ copy
|
||||
&mut Some Reference y 3 References the other data, __mutable__
|
||||
|
||||
|
||||
## `Array[A]::map`
|
||||
|
||||
```thp
|
||||
fun map[B](this, (A) -> B callback) -> Array[B]
|
||||
```
|
||||
|
||||
Applies `callback` to all the elements of this array, and
|
||||
returns those new values in a new array.
|
||||
|
||||
### Example
|
||||
|
||||
```thp
|
||||
let numbers = Array(1, 2, 3, 4, 5)
|
||||
|
||||
let numbers_squared = numbers.map {it ** 2}
|
||||
|
||||
print(numbers_squared) // Array(1, 4, 9, 16, 25)
|
||||
|
||||
numbers.map(fun(v) {
|
||||
v - 2
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
|
||||
## `Array[A]::reduce`
|
||||
|
||||
```thp
|
||||
fun reduce[B](
|
||||
this,
|
||||
B initial,
|
||||
(A previous, B current) -> B callback,
|
||||
) -> B
|
||||
```
|
||||
|
||||
Iteratively reduce the array to a single value using `callback`.
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```thp
|
||||
let numbers = Array(1, 2, 3, 4, 5)
|
||||
|
||||
let sum = numbers.reduce(0, \+)
|
||||
let sum = numbers.reduce(0) {$1 + $2}
|
||||
let sum = numbers.reduce(0, fun(prev, curr) {prev + curr})
|
||||
|
||||
print(sum) // 15
|
||||
```
|
||||
|
||||
|
||||
```thp
|
||||
let numbers = Array(1, 2, 3, 4, 5)
|
||||
|
||||
let sum = numbers.reduce("", fun(prev, curr) {prev + curr})
|
||||
|
||||
let sum = numbers.reduce("") {prev, curr -> prev + curr}
|
||||
|
||||
print(sum) // "12345"
|
||||
```
|
||||
|
||||
|
||||
```thp
|
||||
// Functor
|
||||
|
||||
fun fmap(
|
||||
(A) -> B,
|
||||
f[A],
|
||||
) -> f[B]
|
||||
|
||||
fun (<$)(
|
||||
A,
|
||||
f[B],
|
||||
) -> f[A]
|
||||
|
||||
|
||||
// Applicative
|
||||
|
||||
fun pure(A) -> f[A]
|
||||
|
||||
fun (<*>)(
|
||||
f[A -> B],
|
||||
f[A],
|
||||
) -> f[B]
|
||||
|
||||
fun (*>)(
|
||||
f[_],
|
||||
f[B],
|
||||
) -> f[B]
|
||||
|
||||
fun (<*)(
|
||||
f[A],
|
||||
f[_],
|
||||
) -> f[A]
|
||||
|
||||
|
||||
// Monad
|
||||
|
||||
fun (>>=)[m, A, B](
|
||||
m[A],
|
||||
(A) -> m[B],
|
||||
) -> m[B]
|
||||
|
||||
|
||||
(Array[Int], Int -> Array[String]) -> Array[String]
|
||||
|
||||
let result = Array(1, 2, 3, 4, 5) >>= {Array($.into[String]())}
|
||||
|
||||
print(result) // Array("1", "2", "3", "4", "5")
|
||||
```
|
||||
|
||||
|
||||
```thp
|
||||
Option[Int] result = "322".try_into()
|
||||
Option[Int] result_halved = result >>= {Some($ / 2)}
|
||||
|
||||
print(result_halved) // Some(161)
|
||||
|
||||
|
||||
Option[Int] result = "abc".try_into()
|
||||
Option[Int] result_halved = result >>= {Some($ / 2)}
|
||||
|
||||
print(result_halved) // None
|
||||
```
|
||||
|
||||
```thp
|
||||
fun (<$>)[m, A, B](
|
||||
(A) -> B,
|
||||
m[A],
|
||||
) -> m[B]
|
||||
|
||||
|
||||
fun half(Int x) -> Int {
|
||||
x / 2
|
||||
}
|
||||
|
||||
|
||||
Option[Int] result = "322".try_into()
|
||||
Option[Int] result_halved = result <$> half
|
||||
|
||||
print(result_halved) // Some(161)
|
||||
|
||||
|
||||
Option[Int] result = "abc".try_into()
|
||||
Option[Int] result_halved = result <$> half
|
||||
|
||||
print(result_halved) // None
|
||||
```
|
||||
|
||||
```thp
|
||||
fun (>>)[A, B, C](
|
||||
(A) -> B,
|
||||
(B) -> C,
|
||||
) -> (A) -> C
|
||||
|
||||
let f1 = add1 >> times2
|
||||
|
||||
f1(5) // 12
|
||||
```
|
||||
|
||||
|
||||
|
||||
```thp
|
||||
function_call[Datatype](param1, param2) {
|
||||
// lambda
|
||||
}
|
||||
|
||||
function_call([arr1, arr2])
|
||||
function_call[Datatype]([arr1, arr2])
|
||||
|
||||
|
||||
fun test[A, B](A a, B b) -> B {}
|
||||
|
||||
|
||||
Array[String] v = 20
|
||||
|
||||
val x = Obj {
|
||||
Array[Int] x: [1, 2, 3]
|
||||
}
|
||||
|
||||
value + [1, 2, 3]
|
||||
|
||||
value + [Int]
|
||||
|
||||
|
||||
value[0]
|
||||
|
||||
|
||||
let functions = [
|
||||
{0},
|
||||
{1},
|
||||
{2},
|
||||
]
|
||||
|
||||
let index = 0
|
||||
|
||||
functions[index]()
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
```thp
|
||||
fun main()
|
||||
{
|
||||
// Using the turbofish operator
|
||||
let result = "42".parse[Int]()
|
||||
}
|
||||
```
|
||||
|
@ -1,28 +0,0 @@
|
||||
---
|
||||
layout: ../../layouts/DocsLayout.astro
|
||||
title: Install
|
||||
---
|
||||
|
||||
# Install
|
||||
|
||||
**THP is technically usable.**
|
||||
|
||||
## From source (*nix)
|
||||
|
||||
Requires Rust installed.
|
||||
|
||||
Clone [the repo](https://git.araozu.dev/fernando/thp) and run
|
||||
`cargo build --release`. You'll have a `thp` binary on
|
||||
`target/release/thp`, run it and see for yourself.
|
||||
|
||||
|
||||
## Binary
|
||||
|
||||
Goal: Install THP with a single binary. Assumes that php and composer is
|
||||
available.
|
||||
|
||||
|
||||
## With composer
|
||||
|
||||
TBD: Install THP with `composer require thp`
|
||||
|
21
src/pages/spec/_wrapper.astro
Normal file
21
src/pages/spec/_wrapper.astro
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
import NewDocsLayout, { type AstroFile } from "@/layouts/NewDocsLayout.astro";
|
||||
|
||||
const { frontmatter, headings } = Astro.props;
|
||||
// Get all the posts from this dir
|
||||
|
||||
const posts = await Astro.glob("./**/*.{md,mdx}") as unknown as Array<AstroFile>;
|
||||
|
||||
// Current dir
|
||||
const current_dir = import.meta.dirname;
|
||||
---
|
||||
|
||||
<NewDocsLayout
|
||||
base_dir={current_dir}
|
||||
frontmatter={frontmatter}
|
||||
headings={headings}
|
||||
posts={posts}
|
||||
>
|
||||
<slot />
|
||||
</NewPagesLayout>
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: AST
|
||||
---
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Expression
|
||||
---
|
||||
|
||||
|
@ -1,26 +1,8 @@
|
||||
---
|
||||
layout: ../../layouts/SpecLayout.astro
|
||||
layout: "./_wrapper.astro"
|
||||
title: Welcome
|
||||
pagesLayout:
|
||||
- path: index
|
||||
- path: tokens
|
||||
title: Tokens
|
||||
children:
|
||||
- path: tokens
|
||||
- path: numbers
|
||||
- path: identifier
|
||||
- path: string
|
||||
- path: comments
|
||||
- path: operator
|
||||
- path: grouping
|
||||
- path: newline
|
||||
- path: ast
|
||||
title: THP AST
|
||||
children:
|
||||
- path: ast
|
||||
- path: expression
|
||||
---
|
||||
import Code from "../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
|
||||
# The THP Language Specification
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Comment
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Comment
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Grouping signs
|
||||
---
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Identifiers & Datatypes
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Identifiers & Datatypes
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: New line
|
||||
---
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Numbers
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Numbers
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Operator
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# Operator
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: String
|
||||
---
|
||||
import Code from "../../../components/Code.astro"
|
||||
import Code from "@/components/Code.astro"
|
||||
|
||||
# String
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
layout: ../../../layouts/SpecLayout.astro
|
||||
layout: "../_wrapper.astro"
|
||||
title: Index
|
||||
---
|
||||
|
||||
|
@ -1,3 +1,9 @@
|
||||
{
|
||||
"extends": "astro/tsconfigs/strictest"
|
||||
"extends": "astro/tsconfigs/strictest",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["src/*"],
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user