From 49fa501f0d27d3696f085bf49128d93f1ba0889a Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 9 Apr 2023 15:42:10 +1000 Subject: [PATCH] lang/parse: struct private data now needs a "+" --- doc/changelog.md | 1 + doc/wuffs-the-language.md | 2 +- lang/parse/parse.go | 7 ++++++- lang/render/render.go | 2 +- std/bmp/decode_bmp.wuffs | 2 +- std/bzip2/decode_bzip2.wuffs | 2 +- std/cbor/decode_cbor.wuffs | 2 +- std/deflate/decode_deflate.wuffs | 2 +- std/gif/decode_gif.wuffs | 2 +- std/json/decode_json.wuffs | 2 +- std/lzw/decode_lzw.wuffs | 2 +- std/png/decode_png.wuffs | 2 +- std/tga/decode_tga.wuffs | 2 +- 13 files changed, 18 insertions(+), 12 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 2b501dd2..c2f5fe43 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -6,6 +6,7 @@ The dot points below probably aren't of interest unless you're _writing_ Wuffs code (instead of writing C/C++ code that _uses_ Wuffs' standard library). +- Wuffs struct private data now needs a "+" between the "()" pairs. - `wuffsfmt` double-indents hanging lines and each indent is now 4 spaces (not a tab). diff --git a/doc/wuffs-the-language.md b/doc/wuffs-the-language.md index 9b36d5fd..20b7ac98 100644 --- a/doc/wuffs-the-language.md +++ b/doc/wuffs-the-language.md @@ -49,7 +49,7 @@ to a 100-element array of unsigned 32-bit integers. Types can also be ## Structs Structs are a list of fields, enclosed in parentheses: `struct foo(x: base.u32, -y: base.u32)`, possibly extended with a second list of [optionally +y: base.u32)`, possibly extended (by a `+`) with a second list of [optionally initialized](/doc/note/initialization.md#partial-zero-initialization) fields. The struct name, `foo`, may be followed by a question mark `?`, which means that its methods may be [coroutines](/doc/note/coroutines.md). diff --git a/lang/parse/parse.go b/lang/parse/parse.go index f1829f47..003791e2 100644 --- a/lang/parse/parse.go +++ b/lang/parse/parse.go @@ -344,7 +344,12 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) { if err != nil { return nil, err } - if x := p.peek1(); x == t.IDOpenParen { + if x := p.peek1(); x == t.IDPlus { + p.src = p.src[1:] + if x := p.peek1(); x != t.IDOpenParen { + return nil, fmt.Errorf(`parse: expected "(", got %q at %s:%d`, + p.tm.ByID(x), p.filename, p.line()) + } extraFields, err := p.parseList(t.IDCloseParen, (*parser).parseExtraFieldNode) if err != nil { return nil, err diff --git a/lang/render/render.go b/lang/render/render.go index 35d0f160..f1cb8820 100644 --- a/lang/render/render.go +++ b/lang/render/render.go @@ -120,7 +120,7 @@ func Render(w io.Writer, tm *t.Map, src []t.Token, comments []string) (err error buf = appendTabs(buf, indent+indentAdjustment) // Apply or update varNameLength. - if len(lineTokens) < 3 { + if len(lineTokens) < 4 { varNameLength = 0 } else { id0 := lineTokens[0].ID diff --git a/std/bmp/decode_bmp.wuffs b/std/bmp/decode_bmp.wuffs index be200160..1740bc7e 100644 --- a/std/bmp/decode_bmp.wuffs +++ b/std/bmp/decode_bmp.wuffs @@ -72,7 +72,7 @@ pub struct decoder? implements base.image_decoder( swizzler : base.pixel_swizzler, util : base.utility, -)( +) + ( // scratch is one of: // - 2048 bytes = 256 * (8 bytes per BGRA_NONPREMUL_4X16LE). // - 1024 bytes = 1024 * (1 byte per INDEXED__BGRA_BINARY), plus diff --git a/std/bzip2/decode_bzip2.wuffs b/std/bzip2/decode_bzip2.wuffs index b4cb92b3..e766ba18 100644 --- a/std/bzip2/decode_bzip2.wuffs +++ b/std/bzip2/decode_bzip2.wuffs @@ -57,7 +57,7 @@ pub struct decoder? implements base.io_transformer( code_lengths_bitmask : base.u32, util : base.utility, -)( +) + ( scratch : base.u32, letter_counts : array[256] base.u32, diff --git a/std/cbor/decode_cbor.wuffs b/std/cbor/decode_cbor.wuffs index f12b2ab8..3abccb8c 100644 --- a/std/cbor/decode_cbor.wuffs +++ b/std/cbor/decode_cbor.wuffs @@ -94,7 +94,7 @@ pub struct decoder? implements base.token_decoder( end_of_data : base.bool, util : base.utility, -)( +) + ( // stack is conceptually an array of 2-bit integers, implemented as an // array of u32. The N'th 2-bit pair is whether we're in an array or // object, where N is the recursion depth: diff --git a/std/deflate/decode_deflate.wuffs b/std/deflate/decode_deflate.wuffs index 5d1fd18b..e97560f4 100644 --- a/std/deflate/decode_deflate.wuffs +++ b/std/deflate/decode_deflate.wuffs @@ -91,7 +91,7 @@ pub struct decoder? implements base.io_transformer( end_of_block : base.bool, util : base.utility, -)( +) + ( // huffs and n_huffs_bits are the lookup tables for Huffman decodings. // // There are up to 2 Huffman decoders active at any one time. As per this diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index 1a847086..3f69ef14 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -77,7 +77,7 @@ pub struct decoder? implements base.image_decoder( swizzler : base.pixel_swizzler, util : base.utility, -)( +) + ( compressed : array[4096] base.u8, // palettes[0] and palettes[1] are the Global and Local Color Table. diff --git a/std/json/decode_json.wuffs b/std/json/decode_json.wuffs index 2e28a4c6..a42e8aad 100644 --- a/std/json/decode_json.wuffs +++ b/std/json/decode_json.wuffs @@ -29,7 +29,7 @@ pub struct decoder? implements base.token_decoder( comment_type : base.u8, util : base.utility, -)( +) + ( // stack is conceptually an array of bits, implemented as an array of u32. // The N'th bit being 0 or 1 means that we're in an array or object, where // N is the recursion depth. diff --git a/std/lzw/decode_lzw.wuffs b/std/lzw/decode_lzw.wuffs index 75373f00..b72da0f6 100644 --- a/std/lzw/decode_lzw.wuffs +++ b/std/lzw/decode_lzw.wuffs @@ -58,7 +58,7 @@ pub struct decoder? implements base.io_transformer( prefixes : array[4096] base.u16[..= 4095], util : base.utility, -)( +) + ( // read_from per-code state. suffixes : array[4096] array[8] base.u8, // lm1s is the "length minus 1"s of the values for the implicit key-value diff --git a/std/png/decode_png.wuffs b/std/png/decode_png.wuffs index 9d26a93a..d77f0d95 100644 --- a/std/png/decode_png.wuffs +++ b/std/png/decode_png.wuffs @@ -143,7 +143,7 @@ pub struct decoder? implements base.image_decoder( swizzler : base.pixel_swizzler, util : base.utility, -)( +) + ( crc32 : crc32.ieee_hasher, zlib : zlib.decoder, diff --git a/std/tga/decode_tga.wuffs b/std/tga/decode_tga.wuffs index 276e7007..146da4c8 100644 --- a/std/tga/decode_tga.wuffs +++ b/std/tga/decode_tga.wuffs @@ -46,7 +46,7 @@ pub struct decoder? implements base.image_decoder( swizzler : base.pixel_swizzler, util : base.utility, -)( +) + ( dst_palette : array[4 * 256] base.u8, src_palette : array[4 * 256] base.u8, scratch : array[4] base.u8,