diff options
Diffstat (limited to 'docs/parser.md')
| -rw-r--r-- | docs/parser.md | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/docs/parser.md b/docs/parser.md index a4e5d78..eb41362 100644 --- a/docs/parser.md +++ b/docs/parser.md @@ -4,39 +4,38 @@ Zisp s-expressions are defined in terms of an extremely minimal set of data types; only that which is necessary to build representations of more complex expressions and data types: - +--------+-----------------+---------------+--------+----------+------+ - | TYPE | Bare String | Quoted String | Rune | Pair | Nil | - +--------+-----------------+---------------+--------+----------+------+ - | E.G. | foo, |foo bar| | "foo bar" | #name | (X . Y) | () | - +--------+-----------------+---------------+--------+----------+------+ - -Bare strings and quoted strings are polymorphic sub-types of the generic -string type. Bare strings are implicitly interned. + +--------+-----------------+--------+----------+------+ + | TYPE | String | Rune | Pair | Nil | + +--------+-----------------+--------+----------+------+ + | E.G. | foo, |foo bar| | #name | (X . Y) | () | + +--------+-----------------+--------+----------+------+ The parser can also output non-negative integers, but this is only used for 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: +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 . (... . ()))) The following table summarizes the other supported transformations: - #datum -> (#HASH . datum) #rune(...) -> (#rune ...) + "xyz" -> (#QUOTE . |xyz|) #datum -> (#HASH . datum) + + [...] -> (#SQUARE ...) #rune(...) -> (#rune ...) - [...] -> (#SQUARE ...) dat1dat2 -> (#JOIN dat1 . dat2) + {...} -> (#BRACE ...) dat1dat2 -> (#JOIN dat1 . dat2) - {...} -> (#BRACE ...) dat1.dat2 -> (#DOT dat1 . dat2) + 'datum -> (#QUOTE . datum) dat1.dat2 -> (#DOT dat1 . dat2) - 'datum -> (#QUOTE . datum) dat1:dat2 -> (#COLON dat1 . dat2) + `datum -> (#GRAVE . datum) dat1:dat2 -> (#COLON dat1 . dat2) - `datum -> (#GRAVE . datum) #%hex% -> (#LABEL . hex) + ,datum -> (#COMMA . datum) #%hex% -> (#LABEL . hex) - ,datum -> (#COMMA . datum) #%hex=datum -> (#LABEL hex . datum) + #%hex=datum -> (#LABEL hex . datum) -A separate process called "decoding" can transform these objects into other -data types. For example, `(#HASH x y z)` could become a vector, so that the +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 expression `#(x y z)` works just like in Scheme. See the next section for details about the decoder. @@ -50,19 +49,12 @@ Further notes about the syntax sugar table and examples above: means zero or more data; hex is a hexadecimal number of up to 12 digits. * The `#datum` form only applies when the datum following the hash sign is a - list, quoted string, quote expression, another expression starting with a - hash sign, a bare string starting with a backslash escape (see next), or a - pipe-quoted bare string (see next). - -* A backslash causes the immediately following character to lose any special - meaning it would have, and be considered as part of a bare string instead. - (This does not apply to space or control characters.) For example, the - following three character sequences are each a valid bare string: - - foo\(bar\) \]blah \#\'xyz + list, quoted string, quote expression, another expression starting with the + hash sign, or a pipe-quoted bare string (see next). A bare string can follow + the hash sign by separating the two with a backslash: `#\string` - Bare strings can also be "quoted" with pipes as in Scheme; it should be - noted that this still produces a "bare string" in terms of data type: +* Bare strings can be "quoted" with pipes as in Scheme; it should be noted that + this still produces a "bare string" in terms of data type: |foo bar baz| @@ -79,7 +71,7 @@ Further notes about the syntax sugar table and examples above: #rune'string -> (#rune #QUOTE . string) As a counter-example, following a rune immediately with a bare string isn't - possible, since it's ambiguous: + possible without the delimiting backslash, since that would be ambiguous: #abcdefgh ;Could be (#abcdef . gh) or (#abcde . fgh) or ... @@ -117,6 +109,6 @@ Further notes about the syntax sugar table and examples above: <!-- ;; Local Variables: -;; fill-column: 77 +;; fill-column: 80 ;; End: --> |
