From 71f4b9a52fc98390139330f15b632df3fdfed2ea Mon Sep 17 00:00:00 2001 From: Taylan Kammer Date: Tue, 6 Jan 2026 08:46:28 +0100 Subject: docs/parser.md: Update for new grammar. --- docs/parser.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'docs/parser.md') diff --git a/docs/parser.md b/docs/parser.md index eb41362..41ae7d6 100644 --- a/docs/parser.md +++ b/docs/parser.md @@ -7,7 +7,7 @@ expressions and data types: +--------+-----------------+--------+----------+------+ | TYPE | String | Rune | Pair | Nil | +--------+-----------------+--------+----------+------+ - | E.G. | foo, |foo bar| | #name | (X . Y) | () | + | E.G. | foo, |foo bar| | #name | (X & Y) | () | +--------+-----------------+--------+----------+------+ The parser can also output non-negative integers, but this is only used for @@ -16,23 +16,23 @@ datum labels; number literals are handled by the decoder (see next section). The parser recognizes various "syntax sugar" and transforms it into uses of the above data types. The most ubiquitous example is of course the list: - (datum1 datum2 ...) -> (datum1 . (datum2 . (... . ()))) + (datum1 datum2 ...) -> (datum1 & (datum2 & (... & ()))) The following table summarizes the other supported transformations: - "xyz" -> (#QUOTE . |xyz|) #datum -> (#HASH . datum) + "xyz" -> (#QUOTE & |xyz|) #datum -> (#HASH & datum) [...] -> (#SQUARE ...) #rune(...) -> (#rune ...) - {...} -> (#BRACE ...) dat1dat2 -> (#JOIN dat1 . dat2) + {...} -> (#BRACE ...) dat1dat2 -> (#JOIN dat1 & dat2) - 'datum -> (#QUOTE . datum) dat1.dat2 -> (#DOT dat1 . dat2) + 'datum -> (#QUOTE & datum) dat1.dat2 -> (#DOT dat1 & dat2) - `datum -> (#GRAVE . datum) dat1:dat2 -> (#COLON dat1 . dat2) + `datum -> (#GRAVE & datum) dat1:dat2 -> (#COLON dat1 & dat2) - ,datum -> (#COMMA . datum) #%hex% -> (#LABEL . hex) + ,datum -> (#COMMA & datum) #%hex% -> (#LABEL & hex) - #%hex=datum -> (#LABEL hex . datum) + #%hex=datum -> (#LABEL hex & datum) A separate process called "decoding" can transform such data into more complex types. For example, `(#HASH x y z)` could be decoded into a vector, so the @@ -62,33 +62,33 @@ Further notes about the syntax sugar table and examples above: `#rune(...)` doesn't require a list in the second position; any datum that works with the `#datum` syntax also works with `#rune`. - #rune1#rune2 -> (#rune1 . #rune2) + #rune1#rune2 -> (#rune1 & #rune2) - #rune"text" -> (#rune . "text") + #rune"text" -> (#rune & "text") - #rune\string -> (rune . string) + #rune\string -> (rune & string) - #rune'string -> (#rune #QUOTE . string) + #rune'string -> (#rune #QUOTE & string) As a counter-example, following a rune immediately with a bare string isn't possible without the delimiting backslash, since that would be ambiguous: - #abcdefgh ;Could be (#abcdef . gh) or (#abcde . fgh) or ... + #abcdefgh ;Could be (#abcdef & gh) or (#abcde & fgh) or ... * Syntax sugar can combine arbitrarily; some examples follow: #{...} -> (#HASH #BRACE ...) - #'foo -> (#HASH #QUOTE . foo) + #'foo -> (#HASH #QUOTE & foo) ##'[...] -> (#HASH #HASH #QUOTE #SQUARE ...) {x y}[i j] -> (#JOIN (#BRACE x y) #SQUARE i j) - foo.bar.baz{x y} -> (#JOIN (#DOT (#DOT foo . bar) . baz) #BRACE x y) + foo.bar.baz{x y} -> (#JOIN (#DOT (#DOT foo & bar) & baz) #BRACE x y) * While in Lisp and Scheme `'foo` parses as `(quote foo)`, in Zisp it parses - as `(#QUOTE . foo)` instead; the operand of `#QUOTE` is the entire cdr. + as `(#QUOTE & foo)` instead; the operand of `#QUOTE` is the entire cdr. The same principle is used when parsing other sugar; some examples follow: -- cgit v1.2.3