git @ Cat's Eye Technologies Tamsin / 44fe306
`fail` takes a term as argument and expands variables therein. --HG-- branch : no-stored-token Cat's Eye Technologies 11 years ago
2 changed file(s) with 10 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
3535 | "return" Term
3636 | "fail" Term
3737 | "print" Term
38 | "□"
3839 | LitToken
3940 | ProdName ["(" [Term {"," Term} ")"] ["@" Term].
4041 Term := Term0.
308309 = original
309310
310311 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.
312313
313314 | debug = return ok.
314315 | main = (debug & return walla | "0").
315316 + 0
316317 = walla
317318
318 | debug = fail.
319 | debug = fail notdebugging.
319320 | main = (debug & return walla | "0").
320321 + 0
321322 = 0
323
324 | main = set E = 「Goodbye, world!」 & fail E.
325 + hsihdsihdsih
326 ? Goodbye, world!
322327
323328 The rule `[FOO]` is a short form for `(FOO | return nil)`.
324329
475475 t = self.term()
476476 return ('RETURN', t)
477477 elif self.consume('fail'):
478 return ('FAIL',)
478 t = self.term()
479 return ('FAIL', t)
479480 elif self.consume(u'□'):
480481 return ('EOF',)
481482 elif self.consume('print'):
718719 elif ast[0] == 'RETURN':
719720 return (True, ast[1].expand(self.context))
720721 elif ast[0] == 'FAIL':
721 return (False, Term("fail"))
722 return (False, ast[1].expand(self.context))
722723 elif ast[0] == 'EOF':
723724 if self.scanner.eof():
724725 return (True, EOF)