`fail` takes a term as argument and expands variables therein.
--HG--
branch : no-stored-token
Cat's Eye Technologies
11 years ago
35 | 35 |
| "return" Term
|
36 | 36 |
| "fail" Term
|
37 | 37 |
| "print" Term
|
|
38 |
| "□"
|
38 | 39 |
| LitToken
|
39 | 40 |
| ProdName ["(" [Term {"," Term} ")"] ["@" Term].
|
40 | 41 |
Term := Term0.
|
|
308 | 309 |
= original
|
309 | 310 |
|
310 | 311 |
The rule `fail` always fails. This lets you establish global flags, of
|
311 | |
a sort.
|
|
312 |
a sort. It takes a term, which it uses as the failure message.
|
312 | 313 |
|
313 | 314 |
| debug = return ok.
|
314 | 315 |
| main = (debug & return walla | "0").
|
315 | 316 |
+ 0
|
316 | 317 |
= walla
|
317 | 318 |
|
318 | |
| debug = fail.
|
|
319 |
| debug = fail notdebugging.
|
319 | 320 |
| main = (debug & return walla | "0").
|
320 | 321 |
+ 0
|
321 | 322 |
= 0
|
|
323 |
|
|
324 |
| main = set E = 「Goodbye, world!」 & fail E.
|
|
325 |
+ hsihdsihdsih
|
|
326 |
? Goodbye, world!
|
322 | 327 |
|
323 | 328 |
The rule `[FOO]` is a short form for `(FOO | return nil)`.
|
324 | 329 |
|
475 | 475 |
t = self.term()
|
476 | 476 |
return ('RETURN', t)
|
477 | 477 |
elif self.consume('fail'):
|
478 | |
return ('FAIL',)
|
|
478 |
t = self.term()
|
|
479 |
return ('FAIL', t)
|
479 | 480 |
elif self.consume(u'□'):
|
480 | 481 |
return ('EOF',)
|
481 | 482 |
elif self.consume('print'):
|
|
718 | 719 |
elif ast[0] == 'RETURN':
|
719 | 720 |
return (True, ast[1].expand(self.context))
|
720 | 721 |
elif ast[0] == 'FAIL':
|
721 | |
return (False, Term("fail"))
|
|
722 |
return (False, ast[1].expand(self.context))
|
722 | 723 |
elif ast[0] == 'EOF':
|
723 | 724 |
if self.scanner.eof():
|
724 | 725 |
return (True, EOF)
|