mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Add endwhile syntax
This commit is contained in:
1 parent
d1a4abe321
commit
b1e3a15c08
9 files changed
+53
-29
No files matched your search
@@ -3,6 +3,7 @@
|
||||
|
||||
## Work In Progress
|
||||
|
||||
- Added `endwhile` syntax.
|
||||
- Added `example/imageviewer`.
|
||||
- Added `example/jsonptr`.
|
||||
- Added `std/bmp`.
|
||||
|
||||
@@ -31,7 +31,8 @@ Minor features or restrictions include:
|
||||
an `if` or `while` condition are optional, but the `{}` curly braces are
|
||||
mandatory. There is no 'dangling else' ambiguity.
|
||||
- Labeled jumps look like `break.loopname` and `continue.loopname`, for a
|
||||
matching `while.loopname`.
|
||||
matching `while.loopname`. The `while.loopname`'s closing curly brace must be
|
||||
followed by `endwhile.loopname`.
|
||||
|
||||
Wuffs code is formatted by the
|
||||
[`wuffsfmt`](https://godoc.org/github.com/google/wuffs/cmd/wuffsfmt) program.
|
||||
|
||||
@@ -644,6 +644,22 @@ func (p *parser) parseLabel() (t.ID, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (p *parser) parseEndwhile(label t.ID) bool {
|
||||
if p.peek1() != t.IDEndwhile {
|
||||
return false
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if p.peek1() != t.IDDot {
|
||||
return false
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if p.peek1() != label {
|
||||
return false
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
x := p.peek1()
|
||||
if x == t.IDVar {
|
||||
@@ -721,6 +737,10 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if (label != 0) && !p.parseEndwhile(label) {
|
||||
return nil, fmt.Errorf(`parse: expected endwhile.%s at %s:%d`,
|
||||
label.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
return a.NewWhile(label, condition, asserts, body).AsNode(), nil
|
||||
}
|
||||
return p.parseAssignNode()
|
||||
|
||||
+20
-18
@@ -366,24 +366,25 @@ const (
|
||||
IDConst = ID(0xA2)
|
||||
IDContinue = ID(0xA3)
|
||||
IDElse = ID(0xA4)
|
||||
IDFunc = ID(0xA5)
|
||||
IDIOBind = ID(0xA6)
|
||||
IDIOLimit = ID(0xA7)
|
||||
IDIf = ID(0xA8)
|
||||
IDImplements = ID(0xA9)
|
||||
IDInv = ID(0xAA)
|
||||
IDIterate = ID(0xAB)
|
||||
IDPost = ID(0xAC)
|
||||
IDPre = ID(0xAD)
|
||||
IDPri = ID(0xAE)
|
||||
IDPub = ID(0xAF)
|
||||
IDReturn = ID(0xB0)
|
||||
IDStruct = ID(0xB1)
|
||||
IDUse = ID(0xB2)
|
||||
IDVar = ID(0xB3)
|
||||
IDVia = ID(0xB4)
|
||||
IDWhile = ID(0xB5)
|
||||
IDYield = ID(0xB6)
|
||||
IDEndwhile = ID(0xA5)
|
||||
IDFunc = ID(0xA6)
|
||||
IDIOBind = ID(0xA7)
|
||||
IDIOLimit = ID(0xA8)
|
||||
IDIf = ID(0xA9)
|
||||
IDImplements = ID(0xAA)
|
||||
IDInv = ID(0xAB)
|
||||
IDIterate = ID(0xAC)
|
||||
IDPost = ID(0xAD)
|
||||
IDPre = ID(0xAE)
|
||||
IDPri = ID(0xAF)
|
||||
IDPub = ID(0xB0)
|
||||
IDReturn = ID(0xB1)
|
||||
IDStruct = ID(0xB2)
|
||||
IDUse = ID(0xB3)
|
||||
IDVar = ID(0xB4)
|
||||
IDVia = ID(0xB5)
|
||||
IDWhile = ID(0xB6)
|
||||
IDYield = ID(0xB7)
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -723,6 +724,7 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDConst: "const",
|
||||
IDContinue: "continue",
|
||||
IDElse: "else",
|
||||
IDEndwhile: "endwhile",
|
||||
IDFunc: "func",
|
||||
IDIOBind: "io_bind",
|
||||
IDIOLimit: "io_limit",
|
||||
|
||||
@@ -257,7 +257,7 @@ pri func decoder.decode_blocks?(dst: base.io_writer, src: base.io_reader) {
|
||||
continue.outer
|
||||
}
|
||||
}
|
||||
}
|
||||
} endwhile.outer
|
||||
}
|
||||
|
||||
// decode_uncompressed decodes an uncompresed block as per the RFC section
|
||||
|
||||
@@ -362,7 +362,7 @@ pri func decoder.decode_huffman_fast!(dst: base.io_writer, src: base.io_reader)
|
||||
args.dst.copy_n32_from_history_fast!(n: length, distance: (dist_minus_1 + 1))
|
||||
break
|
||||
}
|
||||
}
|
||||
} endwhile.loop
|
||||
|
||||
// Ensure n_bits < 8 by rewindng args.src, if we loaded too many of its
|
||||
// bytes into the bits variable.
|
||||
|
||||
@@ -272,7 +272,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
length -= n_copied
|
||||
yield? base."$short write"
|
||||
}
|
||||
}
|
||||
} endwhile.loop
|
||||
|
||||
// TODO: "assert n_bits < 8"? What about (bits >> n_bits)?
|
||||
|
||||
|
||||
@@ -992,8 +992,8 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
continue.inner
|
||||
}
|
||||
return lzw_status
|
||||
}
|
||||
}
|
||||
} endwhile.inner
|
||||
} endwhile.outer
|
||||
|
||||
this.compressed_ri = 0
|
||||
this.compressed_wi = 0
|
||||
|
||||
@@ -119,7 +119,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
continue.outer
|
||||
}
|
||||
whitespace_length += 1
|
||||
} // while.ws
|
||||
} endwhile.ws
|
||||
|
||||
// Emit whitespace.
|
||||
if whitespace_length > 0 {
|
||||
@@ -286,7 +286,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
string_length += 1
|
||||
}
|
||||
} // while.string_loop
|
||||
} endwhile.string_loop
|
||||
|
||||
// The trailing '"' is filler.
|
||||
while true {
|
||||
@@ -523,7 +523,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
}
|
||||
|
||||
return "#bad input"
|
||||
} // while.goto_parsed_a_leaf_value
|
||||
} endwhile.goto_parsed_a_leaf_value
|
||||
|
||||
// We've just parsed a leaf (non-container) value: literal (null,
|
||||
// false, true), number or string.
|
||||
@@ -531,7 +531,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader) {
|
||||
break.outer
|
||||
}
|
||||
expect = expect_after_value
|
||||
} // while.outer
|
||||
} endwhile.outer
|
||||
}
|
||||
|
||||
pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
@@ -654,7 +654,7 @@ pri func decoder.decode_number!(src: base.io_reader) base.u32[..= 0x3FF] {
|
||||
n = this.decode_digits!(src: args.src, n: n)
|
||||
|
||||
break.goto_done
|
||||
} // while.goto_done
|
||||
} endwhile.goto_done
|
||||
return n | floating_point
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user