diff --git a/civet.dev/.vitepress/components/Hero.vue b/civet.dev/.vitepress/components/Hero.vue index ef2f1f2b..51134bee 100644 --- a/civet.dev/.vitepress/components/Hero.vue +++ b/civet.dev/.vitepress/components/Hero.vue @@ -4,6 +4,11 @@ import VPHero from 'vitepress/dist/client/theme-default/components/VPHero.vue'; const actions = [ { theme: 'brand', + text: 'Reference', + link: '/reference', + }, + { + theme: 'alt', text: 'Cheatsheet', link: '/cheatsheet', }, diff --git a/civet.dev/.vitepress/config.js b/civet.dev/.vitepress/config.mjs similarity index 93% rename from civet.dev/.vitepress/config.js rename to civet.dev/.vitepress/config.mjs index 5271c0ca..3771e741 100644 --- a/civet.dev/.vitepress/config.js +++ b/civet.dev/.vitepress/config.mjs @@ -1,6 +1,6 @@ import pkg from '../../package.json'; -import { head } from './head.js'; -import { getContributors } from './utils/getContributors.js'; +import { head } from './head.mjs'; +import { getContributors } from './utils/getContributors.mjs'; import { defineConfig } from 'vitepress'; import { compileCivet } from './utils/compileCivet'; import { getHighlighter } from './utils/getHighlighter'; @@ -26,7 +26,8 @@ export default async function vitePressConfig() { siteTitle: 'Civet', nav: [ { text: 'Getting started', link: '/getting-started' }, - { text: 'Cheatsheet', link: '/cheatsheet' }, + { text: 'Reference', link: '/reference' }, + { text: 'Cheatsheet', link: '/cheatsheet'}, { text: 'Comparison', link: '/comparison' }, { text: 'Integrations', link: '/integrations' }, { text: 'Config', link: '/config' }, diff --git a/civet.dev/.vitepress/head.js b/civet.dev/.vitepress/head.mjs similarity index 100% rename from civet.dev/.vitepress/head.js rename to civet.dev/.vitepress/head.mjs diff --git a/civet.dev/.vitepress/utils/getContributors.js b/civet.dev/.vitepress/utils/getContributors.mjs similarity index 100% rename from civet.dev/.vitepress/utils/getContributors.js rename to civet.dev/.vitepress/utils/getContributors.mjs diff --git a/civet.dev/cheatsheet.md b/civet.dev/cheatsheet.md index a3a387aa..dea4cc9b 100644 --- a/civet.dev/cheatsheet.md +++ b/civet.dev/cheatsheet.md @@ -5,124 +5,218 @@ aside: false # {{ $frontmatter.title }} -Civet code on the lefttop, -compiled TypeScript output on -the rightbottom. +Here's a quick overview of the language. For more detailed information take a look at the [Reference](/reference). + + + +
+ +```ts +// Declarations +const x = 1 +let y: number = 2 +var z: string = "3" +x := 1 // const x = 1 +y .= 2 // let y = 2 + +// Destructuring +[ a, b ] := x +[ ..., last ] := x +[ first, ...rest ] := x +[ first, ..., last ] := x +[ first, ...middle, last] := x + +{ a, b } := c -In most cases, the Civet code on -the lefttop -is optional shorthand. -The TypeScript code on -the rightbottom -(and most TypeScript code) is almost always also valid Civet input. +``` -[[toc]] +```ts +// Function application +f(x) +f(a, g(x)) +f(...args, cb) -## Variable Declaration +// Implicit application +f x // f(x) +f a, b, c // f(a, b, c) +f g x // f(g(x)) +f a, b c // f(a, b(c)) -By default, you are responsible for declaring your variables -via `var`, `let`, `const`, or their shorthands: +``` - -a := 10 -b .= 10 -c: number | string .= 0 -let d: boolean -var v: any - +```ts +// Conditionals +x && y +x and y // x && y +x || y +x or y // x || y + +// relationals +x === y +x is y // x === y +x < y +x > y +// Chained relationals +x < y < z // x < y && y < z +``` -Alternatively, you can use a `"civet"` directive at the beginning of your file -to specify one of two automatic variable declaration modes: +```ts +// this +this +// shorthand +@ // this +@x // this.x + +// instance of and typeof shorthand +x instanceof y +x -"civet autoVar" -sos = 0 -for item of iterable - square = item * item - sos += square - +// Block Strings +""" + Block strings + will dedent +""" -### `autoLet` +''' + They work with all kinds of + strings +''' - -"civet autoLet" -sos = 0 -for item of iterable - square = item * item - sos += square - +``` + I will dedent by removing + common indentation +``` -### Declarations in Conditions and Loops +````` - -if match := regex.exec string - console.log match[1], match[2] - +```ts +// if conditions +if x < 3 + "it's small" - -if [, dir, base] := /^(.*\/)?([^/]*)$/.exec file - console.log dir, base - +if x > 11 + "it's big" - -if {x, y} := getLocation() - console.log `At ${x}, ${y}` -else - console.log "Not anywhere" - +unless paused + run() - -node .= linkedList.head -while {data, next} := node - console.log data - node = next - +// loops +while x < 10 + f(x) + x++ -## Objects +for item of items + update item -### Unbraced Literals +for key in object + log key -When every property has a value, braces can be omitted. +for own key in object + log `my ${key}` +``` + +```ts +// Postfix loops/conditionals +f(x) if x +log name for name of names + +``` - -person := name: 'Henry', age: 4 -obj := - a: 1 - b: 2 - c: - x: 'pretty' - y: 'cool' - +```ts +// Arrow Functions +inc := (x) => x + 1 +add := (a, b): T => a + b + +// Thin arrow -> is equivalent to `function` +f := (this: ctx, a, b) -> + ctx.log a, b if ctx.debug + +``` -`$:` behaves specially for Svelte compatibility. If you want a key of `$`, -wrap it in quotes or use explicit braces. +```ts +// Block shorthand +people.map .name // people.map($ => $.name) +numbers.filter & % 2 is 0 +// numbers.filter($ => $ % 2 === 0) - -$: document.title = title -"$": "dollar" -{$: "dollar"} - +// Conditional declarations +throw error if { error } := result + +if [, dir, base] := /^(.*\/)?([^/]*)$/.exec file + console.log dir, base +``` + +```ts +// Switch +switch dir + when '>' then civet.x++ + when '<' + civet.x-- + civet.x = 0 if civet.x < 0 + else + civet.waiting += 5 +``` -### Braced Literals +```ts +// Pattern Matching +switch s + "" + console.log "nothing" + /\s+/ + console.log "whitespace" + "hi" + console.log "greeting" +``` -With braces, the `{x}` shorthand generalizes to any -sequence of member accesses and/or calls: +```ts +// Pattern destructuring +switch x + [{type: "text", content: /\s+/}, ...rest] + console.log "leading whitespace" + [{type: "text", content}, ...rest] + console.log "leading text:", content + [{type}, ...rest] + console.log "leading type:", type +``` - -another := {person.name, obj?.c?.x} -computed := {foo(), bar()} -named := {lookup[x+y]} -templated := {`${prefix}${suffix}`: result} - +```ts +// JSX +// Better binding + + -### Object Globs +// Closing is optional +
+