Cheatsheets for pexprs

This commit is contained in:
Tony Garnock-Jones 2023-11-01 15:15:24 +01:00
parent 39bfeedb54
commit ebd8b3f05b
6 changed files with 61 additions and 17 deletions

View File

@ -73,6 +73,7 @@ automatic, perfect-fidelity conversion between syntaxes.
## Additional resources
- [Preserves Expressions (P-expressions, pexprs)](preserves-expressions.html)
- Some [conventions for common data types](conventions.html)
- [Open questions](questions.html); see also the
[issues list]({{page.projectpages}}/issues)

View File

@ -1,22 +1,21 @@
The definition of `Atom` is as given in the Preserves text syntax.
The definitions of `Atom`, `ws`, and `linecomment` are as given in the Preserves text syntax.
```text
Document := Expr* sp
Expr := sp (Atom | Compound | Punct | Embedded | Annotated)
Document := Expr* ws
Expr := ws (SimpleExpr | Punct)
SimpleExpr := Atom | Compound | Embedded | Annotated
Compound := Sequence | Record | Block | Group | Set
Punct := `,` | `;` | `:`+
sp := (space | tab | cr | lf)*
Sequence := `[` Expr* Trailer sp `]`
Record := `<` Expr* Trailer sp `>`
Block := `{` Expr* Trailer sp `}`
Group := `(` Expr* Trailer sp `)`
Set := `#{` Expr* Trailer sp `}`
Sequence := `[` Expr* Trailer ws `]`
Record := `<` Expr* Trailer ws `>`
Block := `{` Expr* Trailer ws `}`
Group := `(` Expr* Trailer ws `)`
Set := `#{` Expr* Trailer ws `}`
Trailer := Annotation*
Embedded := `#!` Expr
Annotated := Annotation Expr
Annotation := `@` Expr | `#` ((space | tab) linecomment) (cr | lf)
Embedded := `#!` SimpleExpr
Annotated := Annotation SimpleExpr
Annotation := `@` SimpleExpr | `#` ((space | tab) linecomment) (cr | lf)
```

View File

@ -0,0 +1,23 @@
The definitions of `Atom`, `ws`, and `linecomment` are as given in the Preserves text syntax.
{:.postcard-grammar.textsyntax}
| *Document* | := | *Expr*<sup></sup> **ws**
| *Expr* | := | **ws** (*SimpleExpr* &#124; *Punct*)
| *SimpleExpr* | := | *Atom* &#124; *Compound* &#124; *Embedded* &#124; *Annotated*
| *Compound* | := | *Sequence* &#124; *Record* &#124; *Block* &#124; *Group* &#124; *Set*
| *Punct* | := | `,` &#124; `;` &#124; `:`<sup>+</sup>
{:.postcard-grammar.textsyntax}
| *Sequence* | := | `[` *Expr*<sup></sup> *Trailer* **ws** `]`
| *Record* | := | `<` *Expr*<sup></sup> *Trailer* **ws** `>`
| *Block* | := | `{` *Expr*<sup></sup> *Trailer* **ws** `}`
| *Group* | := | `(` *Expr*<sup></sup> *Trailer* **ws** `)`
| *Set* | := | `#{` *Expr*<sup></sup> *Trailer* **ws** `}`
{:.postcard-grammar.textsyntax}
| *Trailer* | := | *Annotation*<sup></sup>
{:.postcard-grammar.textsyntax}
| *Embedded* | := | `#!` *SimpleExpr*
| *Annotated* | := | *Annotation* *SimpleExpr*
| *Annotation* | := | `@` *SimpleExpr* &#124; `#` ((**space** &#124; **tab**) *linecomment*) (**cr** &#124; **lf**)

View File

@ -6,6 +6,20 @@ title: "Preserves Quick Reference (Plaintext)"
Tony Garnock-Jones <tonyg@leastfixedpoint.com>
{{ site.version_date }}. Version {{ site.version }}.
These are non-normative "reference card" definitions. See also the normative [semantics]({{
site.baseurl }}/preserves.html), [text syntax specification]({{ site.baseurl
}}/preserves-text.html), and [machine-oriented syntax specification]({{ site.baseurl
}}/preserves-binary.html), and the experimental [P-expressions definition]({{ site.baseurl
}}/preserves-expressions.html).
## <a id="binary"></a>Machine-Oriented Binary Syntax
{% include cheatsheet-binary-plaintext.md %}
## <a id="text"></a>Human-Oriented Text Syntax
{% include cheatsheet-text-plaintext.md %}
## <a id="pexprs"></a>P-expression Syntax
{% include cheatsheet-pexprs-plaintext.md %}

View File

@ -8,8 +8,9 @@ Tony Garnock-Jones <tonyg@leastfixedpoint.com>
These are non-normative "reference card" definitions. See also the normative [semantics]({{
site.baseurl }}/preserves.html), [text syntax specification]({{ site.baseurl
}}/preserves-text.html) and [machine-oriented syntax specification]({{ site.baseurl
}}/preserves-binary.html).
}}/preserves-text.html), and [machine-oriented syntax specification]({{ site.baseurl
}}/preserves-binary.html), and the experimental [P-expressions definition]({{ site.baseurl
}}/preserves-expressions.html).
## <a id="binary"></a>Machine-Oriented Binary Syntax
@ -18,3 +19,7 @@ site.baseurl }}/preserves.html), [text syntax specification]({{ site.baseurl
## <a id="text"></a>Human-Oriented Text Syntax
{% include cheatsheet-text.md %}
## <a id="pexprs"></a>P-expression Syntax
{% include cheatsheet-pexprs.md %}

View File

@ -7,6 +7,7 @@ October 2023. Version 0.3.0.
[text syntax]: preserves-text.html
**Experimental.**
This document defines a grammar called *Preserves Expressions*
(*P-expressions*, *pexprs*) that includes [ordinary Preserves text
syntax][text syntax] but offers extensions sufficient to support a Lisp-
@ -49,8 +50,8 @@ a compound expression, special punctuation, an `Embedded` expression, or
an `Annotated` expression. The class `SimpleExpr` includes all of `Expr`
except special punctuation.
Expr = ws (SimpleExpr | Punct)
SimpleExpr = Atom | Compound | Embedded | Annotated
Expr = ws (SimpleExpr / Punct)
SimpleExpr = Atom / Compound / Embedded / Annotated
Embedded and annotated values are as in the text syntax, differing only
in that uses of `Value` are replaced with `SimpleExpr`.
@ -58,6 +59,7 @@ in that uses of `Value` are replaced with `SimpleExpr`.
Embedded = "#!" SimpleExpr
Annotated = Annotation SimpleExpr
Annotation = "@" SimpleExpr / "#" [(%x20 / %x09) linecomment] (CR / LF)
linecomment = *<any unicode scalar value except CR or LF>
P-expression special punctuation marks are comma, semicolon, and sequences of one or more colons.