Do = Object.subtype(#Do); Do.new(body, cond) { self = super.new(); self.body = body; self.cond = cond; self; } Do.__eval__(env) { local result = self.body.__eval__(env); while (self.cond.__eval__(env)) { result = self.body.__eval__(env); } result; } Do.__codeon__(str) { str.push("do "); self.body.__codeon__(str); str.push(" while ( "); self.cond.__codeon__(str); str.push(" )"); } // parse the grammar expression // put it at the beginning of stmt (which is an alternation) metaGrammar.stmt.prepend("\"whatever i want\" - b:stmt WHILE LPAREN c:expr RPAREN EOS { $$ = Do.new(b, c); }"); { local i = 1; { whatever i want { i *= 2; print(i, "\n"); } while (i < 1000); whatever i want { i *= 2; print(i, "\n"); } while (i < 1000); whatever i want { i *= 2; print(i, "\n"); } while (i < 1000); } }