Skip to main content

module examples::modfun::Checker

rascal-0.34.0
typepal-0.8.10

Usage

import examples::modfun::Checker;

Source code

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

Dependencies

import examples::modfun::Syntax;
extend examples::fun::Checker;

data AType

data AType  
= moduleType(str name)
;

function prettyAType

str prettyAType(moduleType(str name)) = "module(<name>)";

data IdRole

data IdRole  
= moduleId()
;

data PathRole

data PathRole  
= importPath()
;

function collect

void collect(current: (ModuleDecl) `module <ModId mid> { <Decl* decls> }`, Collector c) {
c.define("<mid>", moduleId(), mid, defType(moduleType("<mid>")));
//c.enterScope(current);
collect(decls, c);
//c.leaveScope(current);
}

void collect(current: (ImportDecl) `import <ModId mid> ;`, Collector c){
c.addPathToDef(mid, {moduleId()}, importPath());
}

void collect(current: (VarDecl) `def <Id id> : <Type tp> = <Expression expression> ;`, Collector c) {
c.define("<id>", variableId(), id, defType(tp));
c.requireEqual(tp, expression, error(current, "Expected initializing expression of type %t, found %t", expression, tp));
collect(tp, expression, c);
}