From e923d87fa5a59919fc890481a3de1b5d94d5e1ab Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 5 Feb 2024 22:38:49 +0100 Subject: [PATCH] Switch from `#!` to `#:` for embedded values --- _config.yml | 4 ++-- _includes/cheatsheet-binary-plaintext.md | 2 +- _includes/cheatsheet-binary.md | 2 +- _includes/cheatsheet-pexprs-plaintext.md | 2 +- _includes/cheatsheet-pexprs.md | 2 +- _includes/cheatsheet-text-plaintext.md | 2 +- _includes/cheatsheet-text.md | 2 +- _includes/text-examples.md | 2 +- implementations/dhall/render.dhall | 4 ++-- .../javascript/packages/core/src/embedded.ts | 2 +- .../javascript/packages/core/src/reader.ts | 2 +- .../javascript/packages/core/src/writer.ts | 2 +- .../packages/schema/test/reader.test.ts | 2 +- implementations/python/preserves/fold.py | 2 +- implementations/python/preserves/text.py | 2 +- implementations/python/preserves/values.py | 8 ++++---- implementations/python/tests/samples.pr | 6 +++--- .../preserves/preserves-schema/schema.prs | 2 +- .../racket/preserves/preserves/pexprs.rkt | 2 +- .../preserves/preserves/read-text-generic.rkt | 2 +- .../preserves/preserves/tests/samples.pr | 6 +++--- .../racket/preserves/preserves/write-text.rkt | 2 +- preserves-binary.md | 2 +- preserves-expressions.md | 14 ++++++------- preserves-schema.md | 20 +++++++++---------- preserves-text.md | 4 ++-- preserves.md | 4 ++-- schema/schema.prs | 2 +- tests/samples.pr | 6 +++--- 29 files changed, 57 insertions(+), 57 deletions(-) diff --git a/_config.yml b/_config.yml index 1ac7196..1ad3492 100644 --- a/_config.yml +++ b/_config.yml @@ -13,5 +13,5 @@ defaults: layout: page title: "Preserves" -version_date: "January 2024" -version: "0.993.0" +version_date: "February 2024" +version: "0.994.0" diff --git a/_includes/cheatsheet-binary-plaintext.md b/_includes/cheatsheet-binary-plaintext.md index 3b31abe..2256145 100644 --- a/_includes/cheatsheet-binary-plaintext.md +++ b/_includes/cheatsheet-binary-plaintext.md @@ -5,7 +5,7 @@ For a value `V`, we write `«V»` for the binary encoding of `V`. «#t» = [0x81] «@W V» = [0x85] ++ «W» ++ «V» - «#!V» = [0x86] ++ «V» + «#:V» = [0x86] ++ «V» «V» if V ∈ Double = [0x87, 0x08] ++ binary64(V) diff --git a/_includes/cheatsheet-binary.md b/_includes/cheatsheet-binary.md index 35db691..9b02a83 100644 --- a/_includes/cheatsheet-binary.md +++ b/_includes/cheatsheet-binary.md @@ -8,7 +8,7 @@ class="postcard-grammar binarysyntax">*V*. {:.postcard-grammar.binarysyntax} «`@`*W* *V*» | = | `85` «*W*» «*V*» -«`#!`*V*» | = | `86` «*V*» +«`#:`*V*» | = | `86` «*V*» {:.postcard-grammar.binarysyntax} «*V*» | = | `87``08` **binary64**(*V*) | if *V* ∈ Double diff --git a/_includes/cheatsheet-pexprs-plaintext.md b/_includes/cheatsheet-pexprs-plaintext.md index 832478c..6930b54 100644 --- a/_includes/cheatsheet-pexprs-plaintext.md +++ b/_includes/cheatsheet-pexprs-plaintext.md @@ -15,7 +15,7 @@ Set := `#{` Expr* Trailer ws `}` Trailer := (ws Annotation)* -Embedded := `#!` SimpleExpr +Embedded := `#:` SimpleExpr Annotated := Annotation SimpleExpr Annotation := `@` SimpleExpr | `#` ((space | tab) linecomment) (cr | lf) ``` diff --git a/_includes/cheatsheet-pexprs.md b/_includes/cheatsheet-pexprs.md index 4a5d4e5..5ae14ae 100644 --- a/_includes/cheatsheet-pexprs.md +++ b/_includes/cheatsheet-pexprs.md @@ -18,6 +18,6 @@ The definitions of `Atom`, `ws`, and `linecomment` are as given in the Preserves | *Trailer* | := | (**ws** *Annotation*) {:.postcard-grammar.textsyntax} -| *Embedded* | := | `#!` *SimpleExpr* +| *Embedded* | := | `#:` *SimpleExpr* | *Annotated* | := | *Annotation* *SimpleExpr* | *Annotation* | := | `@` *SimpleExpr* | `#` ((**space** | **tab**) *linecomment*) (**cr** | **lf**) diff --git a/_includes/cheatsheet-text-plaintext.md b/_includes/cheatsheet-text-plaintext.md index af09470..405669b 100644 --- a/_includes/cheatsheet-text-plaintext.md +++ b/_includes/cheatsheet-text-plaintext.md @@ -9,7 +9,7 @@ Set := `#{` (commas Value)* commas `}` Dictionary := `{` (commas Value ws `:` Value)* commas `}` commas := (ws `,`)* ws -Embedded := `#!` Value +Embedded := `#:` Value Annotated := Annotation Value Annotation := `@` Value | `#` ((space | tab) linecomment) (cr | lf) diff --git a/_includes/cheatsheet-text.md b/_includes/cheatsheet-text.md index b894129..14bbbeb 100644 --- a/_includes/cheatsheet-text.md +++ b/_includes/cheatsheet-text.md @@ -11,7 +11,7 @@ | **commas** | := | (**ws** `,`) **ws** | {:.postcard-grammar.textsyntax} -| *Embedded* | := | `#!`*Value* | +| *Embedded* | := | `#:`*Value* | | *Annotated* | := | *Annotation* *Value* | | *Annotation* | := | `@`*Value* |`#` ((**space** | **tab**) *linecomment*) (**cr** | **lf**) | diff --git a/_includes/text-examples.md b/_includes/text-examples.md index 66c09bd..c0944f3 100644 --- a/_includes/text-examples.md +++ b/_includes/text-examples.md @@ -11,6 +11,6 @@ syntax](https://preserves.dev/preserves-text.html): Sequence : [value1 value2 ...] Set : #{value1 value2 ...} Dictionary : {key1: value1 key2: value2 ...: ...} - Embedded : #!value + Embedded : #:value Commas are optional in sequences, sets, and dictionaries. diff --git a/implementations/dhall/render.dhall b/implementations/dhall/render.dhall index e05db05..a8918f1 100644 --- a/implementations/dhall/render.dhall +++ b/implementations/dhall/render.dhall @@ -41,7 +41,7 @@ let render ) m ++ " }" - , embedded = λ(value : Text) → "#!${value}" + , embedded = λ(value : Text) → "#:${value}" } let Preserves/boolean = ./boolean.dhall @@ -94,7 +94,7 @@ let example0 = )} '' ≡ '' - { a: 1 b: [ 2 3 ] c: { d: 1.0 e: -1.0 } d: #!#t e: > } + { a: 1 b: [ 2 3 ] c: { d: 1.0 e: -1.0 } d: #:#t e: > } '' in render diff --git a/implementations/javascript/packages/core/src/embedded.ts b/implementations/javascript/packages/core/src/embedded.ts index 1df670f..bfdd846 100644 --- a/implementations/javascript/packages/core/src/embedded.ts +++ b/implementations/javascript/packages/core/src/embedded.ts @@ -26,7 +26,7 @@ export class Embedded { } toString(): string { - return '#!' + (this.embeddedValue as any).toString(); + return '#:' + (this.embeddedValue as any).toString(); } __as_preserve__(): T extends R ? Value : never { diff --git a/implementations/javascript/packages/core/src/reader.ts b/implementations/javascript/packages/core/src/reader.ts index 684ea8c..ebd5fcc 100644 --- a/implementations/javascript/packages/core/src/reader.ts +++ b/implementations/javascript/packages/core/src/reader.ts @@ -354,7 +354,7 @@ export class Reader { default: this.state.error('Invalid #x syntax', startPos); } case '[': return this.state.readBase64Binary(); - case '!': return embed(this.embeddedType.fromValue( + case ':': return embed(this.embeddedType.fromValue( new Reader(this.state, genericEmbeddedTypeDecode).next(), this.state.options)); default: diff --git a/implementations/javascript/packages/core/src/writer.ts b/implementations/javascript/packages/core/src/writer.ts index a89a19c..fbe4b87 100644 --- a/implementations/javascript/packages/core/src/writer.ts +++ b/implementations/javascript/packages/core/src/writer.ts @@ -297,7 +297,7 @@ export class Writer { } else { ((v: Embedded) => { - this.state.pieces.push('#!'); + this.state.pieces.push('#:'); if ('write' in this.embeddedWrite) { this.embeddedWrite.write(this.state, v.embeddedValue); } else { diff --git a/implementations/javascript/packages/schema/test/reader.test.ts b/implementations/javascript/packages/schema/test/reader.test.ts index 7b58ba0..4953e4d 100644 --- a/implementations/javascript/packages/schema/test/reader.test.ts +++ b/implementations/javascript/packages/schema/test/reader.test.ts @@ -18,7 +18,7 @@ describe('reader schema', () => { expect(s.embeddedType._variant).toBe('false'); }); it('understands patterns under embed', () => { - const s = readSchema('version 1 . X = #!0 .'); + const s = readSchema('version 1 . X = #:0 .'); const def: Meta.Definition = s.definitions.get(Symbol.for('X'))!; if (def._variant !== 'Pattern') fail('bad definition 1'); if (def.value._variant !== 'SimplePattern') fail ('bad definition 2'); diff --git a/implementations/python/preserves/fold.py b/implementations/python/preserves/fold.py index aaec596..e78bc5e 100644 --- a/implementations/python/preserves/fold.py +++ b/implementations/python/preserves/fold.py @@ -9,7 +9,7 @@ def map_embeddeds(f, v): ```python >>> map_embeddeds(lambda w: Embedded(f'w={w}'), ['a', Embedded(123), {'z': 6.0}]) - ('a', #!'w=123', {'z': 6.0}) + ('a', #:'w=123', {'z': 6.0}) ``` """ diff --git a/implementations/python/preserves/text.py b/implementations/python/preserves/text.py index 43ad0d9..cc25cb4 100644 --- a/implementations/python/preserves/text.py +++ b/implementations/python/preserves/text.py @@ -356,7 +356,7 @@ class Parser(TextCodec): if c == 'd': return self.wrap(self.read_hex_float()) raise DecodeError('Invalid #x syntax') if c == '[': return self.wrap(self.read_base64_binary()) - if c == '!': + if c == ':': if self.parse_embedded is None: raise DecodeError('No parse_embedded function supplied') return self.wrap(Embedded(self.parse_embedded(self.next()))) diff --git a/implementations/python/preserves/values.py b/implementations/python/preserves/values.py index 2f55e99..5625bc0 100644 --- a/implementations/python/preserves/values.py +++ b/implementations/python/preserves/values.py @@ -575,7 +575,7 @@ class Embedded: >>> import io >>> e = Embedded(io.StringIO('some text')) >>> e # doctest: +ELLIPSIS - #!<_io.StringIO object at ...> + #:<_io.StringIO object at ...> >>> e.embeddedValue # doctest: +ELLIPSIS <_io.StringIO object at ...> @@ -588,7 +588,7 @@ class Embedded: ... TypeError: Cannot preserves-format: None >>> print(preserves.stringify(Embedded(None), format_embedded=lambda x: 'abcdef')) - #!"abcdef" + #:"abcdef" ``` @@ -610,12 +610,12 @@ class Embedded: return hash(self.embeddedValue) def __repr__(self): - return '#!%r' % (self.embeddedValue,) + return '#:%r' % (self.embeddedValue,) def __preserve_write_binary__(self, encoder): encoder.buffer.append(0x86) encoder.append(encoder.encode_embedded(self.embeddedValue)) def __preserve_write_text__(self, formatter): - formatter.chunks.append('#!') + formatter.chunks.append('#:') formatter.append(formatter.format_embedded(self.embeddedValue)) diff --git a/implementations/python/tests/samples.pr b/implementations/python/tests/samples.pr index 18de1a8..6f87650 100644 --- a/implementations/python/tests/samples.pr +++ b/implementations/python/tests/samples.pr @@ -167,9 +167,9 @@ list11: list12: noinput0: @"No input at all" - embed0: - embed1: - embed2: + embed0: + embed1: + embed2: record1: >> record2: >>>> record2a: @"Commas not allowed in records" , >>>"> diff --git a/implementations/racket/preserves/preserves-schema/schema.prs b/implementations/racket/preserves/preserves-schema/schema.prs index 55ff87b..1122a6a 100644 --- a/implementations/racket/preserves/preserves-schema/schema.prs +++ b/implementations/racket/preserves/preserves-schema/schema.prs @@ -41,7 +41,7 @@ SimplePattern = # special builtins: bool, double, int, string, bytes, symbol / - # matches an embedded value in the input: #!p + # matches an embedded value in the input: #:p / # =symbol, < any>, or plain non-symbol atom diff --git a/implementations/racket/preserves/preserves/pexprs.rkt b/implementations/racket/preserves/preserves/pexprs.rkt index e8016d8..9686426 100644 --- a/implementations/racket/preserves/preserves/pexprs.rkt +++ b/implementations/racket/preserves/preserves/pexprs.rkt @@ -279,7 +279,7 @@ [(BLOCK ps ...) (grouped (convert-inner ps) " " "" "{ " " }")] [(SET ps ...) (grouped (convert-inner ps) " " "" "#{ " " }")] [(TRAILER-ANCHOR) ""] - [(embedded v) (list "#!" (convert (encode-embedded v)))] + [(embedded v) (list "#:" (convert (encode-embedded v)))] [(strip-annotations (record 'p (list s))) (symbol->string s)] [v (preserve->string v)])) diff --git a/implementations/racket/preserves/preserves/read-text-generic.rkt b/implementations/racket/preserves/preserves/read-text-generic.rkt index a937c08..fbf71d7 100644 --- a/implementations/racket/preserves/preserves/read-text-generic.rkt +++ b/implementations/racket/preserves/preserves/read-text-generic.rkt @@ -114,7 +114,7 @@ [#\d (read-hex-float)] [c (parse-error* "Invalid #x syntax: ~v" c)])] [#\[ (read-base64-binary '())] - [#\! (embedded (decode-embedded (next)))] + [#\: (embedded (decode-embedded (next)))] [c (on-hash c)])] [c (on-char c)])) diff --git a/implementations/racket/preserves/preserves/tests/samples.pr b/implementations/racket/preserves/preserves/tests/samples.pr index 18de1a8..6f87650 100644 --- a/implementations/racket/preserves/preserves/tests/samples.pr +++ b/implementations/racket/preserves/preserves/tests/samples.pr @@ -167,9 +167,9 @@ list11: list12: noinput0: @"No input at all" - embed0: - embed1: - embed2: + embed0: + embed1: + embed2: record1: >> record2: >>>> record2a: @"Commas not allowed in records" , >>>"> diff --git a/implementations/racket/preserves/preserves/write-text.rkt b/implementations/racket/preserves/preserves/write-text.rkt index 2690e35..eb2737d 100644 --- a/implementations/racket/preserves/preserves/write-text.rkt +++ b/implementations/racket/preserves/preserves/write-text.rkt @@ -176,7 +176,7 @@ [(? set?) (write-sequence distance "#{" (if commas? "," "") "}" write-value (set->list v))] [(? dict?) (write-sequence distance "{" (if commas? "," "") "}" write-key-value (dict->list v))] [(embedded value) - (! "#!") + (! "#:") (write-value distance (encode-embedded value))] [other (error 'write-preserve/text "Attempt to serialize non-preserve: ~v" other)])) diff --git a/preserves-binary.md b/preserves-binary.md index b441d44..d0e3db1 100644 --- a/preserves-binary.md +++ b/preserves-binary.md @@ -130,7 +130,7 @@ representation of `D`. ### Embeddeds. - «#!V» = [0x86] ++ «V» + «#:V» = [0x86] ++ «V» The `Repr` of an `Embedded` is the `Repr` of a `Value` chosen to represent the denoted object, prefixed with `[0x86]`. diff --git a/preserves-expressions.md b/preserves-expressions.md index c89b15d..8aa3008 100644 --- a/preserves-expressions.md +++ b/preserves-expressions.md @@ -3,7 +3,7 @@ title: "P-expressions" --- Tony Garnock-Jones -October 2023. Version 0.3.0. +February 2024. Version 0.3.1. [text syntax]: preserves-text.html @@ -56,7 +56,7 @@ except special punctuation. Embedded and annotated values are as in the text syntax, differing only in that uses of `Value` are replaced with `SimpleExpr`. - Embedded = "#!" SimpleExpr + Embedded = "#:" SimpleExpr Annotated = Annotation SimpleExpr Annotation = "@" SimpleExpr / "#" [(%x20 / %x09) linecomment] (CR / LF) linecomment = * @@ -100,7 +100,7 @@ We write ⌜*p*⌝ for the encoding into Preserves of a P-expression *p*. | ⌜`{`*p* ...`}`⌝ | = | `` | | ⌜`(`*p* ...`)`⌝ | = | `` | | ⌜`#{`*p* ...`}`⌝ | = | `` | -| ⌜`#!`*p*⌝ | = | `#!`⌜*p*⌝ | +| ⌜`#:`*p*⌝ | = | `#:`⌜*p*⌝ | | ⌜`@`*p* *q*⌝ | = | `@`⌜*p*⌝ ⌜*q*⌝ | | ⌜*p*⌝ | = | *p* | when *p* ∈ **Atom** | | ⌜`,`⌝ | = | `

` | @@ -196,9 +196,9 @@ text-syntax encodings. ``` ```preserves - ⌜[1 + 2.0, print "Hello", predicate: #t, foo, #!remote, bar]⌝ + ⌜[1 + 2.0, print "Hello", predicate: #t, foo, #:remote, bar]⌝ = [1 + 2.0

print "Hello"

predicate

#t

- foo

#!remote

bar] + foo

#:remote

bar] ``` ```preserves @@ -295,7 +295,7 @@ P-expression *p* ∈ `Expr` − {`,`}. | **uncomma**(`{`*p* ...`}`) | = | `{`**uncomma**(*p*) ...`}` | omitting any *p* = `,` | | **uncomma**(`(`*p* ...`)`) | = | `(`**uncomma**(*p*) ...`)` | omitting any *p* = `,` | | **uncomma**(`#{`*p* ...`}`) | = | `#{`**uncomma**(*p*) ...`}` | omitting any *p* = `,` | -| **uncomma**(`#!`*p*) | = | `#!`**uncomma**(*p*) | | +| **uncomma**(`#:`*p*) | = | `#:`**uncomma**(*p*) | | | **uncomma**(`@`*p* *q*) | = | `@`**uncomma**(*p*) **uncomma**(*q*) | | | **uncomma**(*p*) | = | *p* | if *p* ∈ **Atom** ∪ **Punct** − {`,`} | @@ -308,7 +308,7 @@ P-expression *p* ∈ `Expr` − {`,`} to a corresponding Preserves `Value`. | ⌞`<`ℓ *p* ...`>`⌟ | = | `<`⌞ℓ⌟ ⌞*p*⌟ ...`>` | | | ⌞`{`*k*`:`*v* ...`}`⌟ | = | `{`⌞*k*⌟`:`⌞*v*⌟ ...`}` | if all ⌞*k*⌟ ... are distinct | | ⌞`#{`*p* ...`}`⌟ | = | `#{`⌞*p*⌟ ...`}` | if all ⌞*p*⌟ ... are distinct | -| ⌞`#!`*p*⌟ | = | `#!`⌞*p*⌟ | | +| ⌞`#:`*p*⌟ | = | `#:`⌞*p*⌟ | | | ⌞`@`*p* *q*⌟ | = | `@`⌞*p*⌟ ⌞*q*⌟ | | | ⌞*p*⌟ | = | *p* | when *p* ∈ **Atom** | diff --git a/preserves-schema.md b/preserves-schema.md index 8452ec5..79b0bc9 100644 --- a/preserves-schema.md +++ b/preserves-schema.md @@ -327,11 +327,11 @@ Specifying the name of a kind of `Atom` matches that kind of atom: AtomKindPattern = "bool" / "double" / "int" / "string" / "bytes" / "symbol" Embedded input `Value`s are matched with embedded patterns. The -portion under the `#!` prefix is the *interface* schema for the +portion under the `#:` prefix is the *interface* schema for the embedded value.[^interface-schema] The result of a match is an instance of the schema-wide `embeddedType`, if one is supplied. - EmbeddedPattern = "#!" SimplePattern + EmbeddedPattern = "#:" SimplePattern A literal pattern may be expressed in any of three ways: non-symbol atoms stand for themselves directly; symbols, prefixed with an equal @@ -368,9 +368,9 @@ identifier. the interface schema associated with an embedded value describes the messages that may be sent to that actor. - **Examples.** `#!any` may denote a reference to an Actor able to - receive any value as a message; `#!#t`, a reference to an Actor - expecting *only* the "true" message; `#!Session`, a reference to + **Examples.** `#:any` may denote a reference to an Actor able to + receive any value as a message; `#:#t`, a reference to an Actor + expecting *only* the "true" message; `#:Session`, a reference to an Actor expecting any message matching a schema defined as `Session` in this file. @@ -628,7 +628,7 @@ Simple patterns are as described above: # special builtins: bool, double, int, string, bytes, symbol / - # matches an embedded value in the input: #!p + # matches an embedded value in the input: #:p / # =symbol, < any>, or plain non-symbol atom @@ -973,16 +973,16 @@ definitions for the metaschema. further; also, consideration of *dependent* schemas (analogous to dependent contracts) could be of interest. - **Example.** In the following fragment, `#!Session` is the handle a + **Example.** In the following fragment, `#:Session` is the handle a connected user uses to interact with a chatroom. In the implementation, `Says` messages are dropped if their `who` doesn't match the `uid` supplied in the `Join` assertion. It'd be nice to capture that using a dependent schema, passing in the specific `uid` value to the `Session` constructor, something like - `#!(Session uid)`. + `#:(Session uid)`. - Join = . - Session = @observeSpeech / Says . + Join = . + Session = @observeSpeech / Says . Says = . diff --git a/preserves-text.md b/preserves-text.md index 2f3f25a..2ba40d8 100644 --- a/preserves-text.md +++ b/preserves-text.md @@ -263,9 +263,9 @@ grammar above.[^rationale-no-general-machine-syntax] annotations potentially contained within machine-encoded values. Finally, an `Embedded` is written as a `Value` chosen to represent the -denoted object, prefixed with `#!`. +denoted object, prefixed with `#:`. - Embedded = "#!" Value + Embedded = "#:" Value ## Annotations and Comments diff --git a/preserves.md b/preserves.md index 46bafd9..9210751 100644 --- a/preserves.md +++ b/preserves.md @@ -214,8 +214,8 @@ sequences use [the Preserves binary encoding](preserves-binary.html). The total ordering specified [above](#total-order) means that the following statements are true: - - `"bzz"` < `"c"` < `"caa"` < `#!"a"` - - `#t` < `3.0f` < `3.0` < `3` < `"3"` < `|3|` < `[]` < `#!#t` + - `"bzz"` < `"c"` < `"caa"` < `#:"a"` + - `#t` < `3.0f` < `3.0` < `3` < `"3"` < `|3|` < `[]` < `#:#t` - `[#f]` < `[foo]`, because `Boolean` appears before `Symbol` in the kind ordering - `[x]` < `[x y]`, because there is no element remaining to compare against `y` - `[a b]` < `[x]`, because `a` is smaller than `x` diff --git a/schema/schema.prs b/schema/schema.prs index 55ff87b..1122a6a 100644 --- a/schema/schema.prs +++ b/schema/schema.prs @@ -41,7 +41,7 @@ SimplePattern = # special builtins: bool, double, int, string, bytes, symbol / - # matches an embedded value in the input: #!p + # matches an embedded value in the input: #:p / # =symbol, < any>, or plain non-symbol atom diff --git a/tests/samples.pr b/tests/samples.pr index 18de1a8..6f87650 100644 --- a/tests/samples.pr +++ b/tests/samples.pr @@ -167,9 +167,9 @@ list11: list12: noinput0: @"No input at all" - embed0: - embed1: - embed2: + embed0: + embed1: + embed2: record1: >> record2: >>>> record2a: @"Commas not allowed in records" , >>>">