Skip to main content

module examples::evenOdd::Checker

rascal-0.40.16
typepal-0.14.8

Usage

import examples::evenOdd::Checker;

Source code

http://github.com/usethesource/typepal/src/examples/evenOdd/Checker.rsc

Dependencies

import String;
import examples::evenOdd::Syntax;
extend analysis::typepal::TypePal;

function isEven

bool isEven(Integer integer)
= toInt("<integer>") mod 2 == 0;

function collect

void collect(current: (EvenOdd) `<Statement+ statements>`, Collector c){
collect(statements, c);
}

void collect(current: (Statement) `even <Integer integer>;`, Collector c){
c.require("even", current, [],
void(Solver s) { s.requireTrue(isEven(integer), error(current, "Even statement should contain an even number, found %q", integer));
});
}

void collect(current: (Statement) `odd <Integer integer>;`, Collector c){
c.require("odd", current, [],
void(Solver s) { s.requireTrue(!isEven(integer), error(current, "Odd statement should contain an odd number, found %q", integer));
});
}