[fine] Some resilience, a design improvement for iterator
This commit is contained in:
parent
15548afc38
commit
f2e82942df
4 changed files with 29 additions and 8 deletions
|
|
@ -83,16 +83,20 @@ fun more_examples(weapon: MeleeWeapon or RangedWeapon) -> f64 or () {
|
|||
}
|
||||
|
||||
// Some fun with iterators
|
||||
class Finished {}
|
||||
let FINISHED = new Finished {}
|
||||
|
||||
class Iterator {
|
||||
current: f64;
|
||||
|
||||
fun next(self) -> f64 or () {
|
||||
fun next(self) -> f64 or Finished {
|
||||
if self.current < 10 {
|
||||
let result = self.current;
|
||||
self.current = self.current + 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
FINISHED
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,4 +5,3 @@ fun test() {
|
|||
// NOTE: These errors should be better
|
||||
// @expect-errors:
|
||||
// | 2:10: Error at 'true': expected a block after `if`
|
||||
// | 2:15: Error at '{': expect ';' to end an expression statement
|
||||
|
|
|
|||
|
|
@ -11,8 +11,12 @@ fun test() {
|
|||
// We need to make sure things are parsed correctly.
|
||||
//
|
||||
// TODO: Better parser recovery will improve the specifics of the errors.
|
||||
//
|
||||
// TODO: This is parsed wrong; the `{` is consumed after the '.' and it
|
||||
// should instead be ignored. This is the "greedy" expression parsing that
|
||||
// matklad talks about in his resilient parser article.
|
||||
//
|
||||
// @expect-errors:
|
||||
// | 7:12: Error at '{': expected an expression
|
||||
// | 7:13: Error at 'let': expect ';' to end a let statement
|
||||
// | 7:26: cannot find value foo here
|
||||
// | 8:0: Error at '}': unbalanced '}'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue