class StringConsumerEngine inherits System { consumers: ConsumerList <- (new ConsumerList) .push((new WhitespaceConsumer).init()) .push((new ExpressionConsumer).init()) .push((new IfConsumer).init()) ; str: String; tl: TokenList <- new TokenList; init(code: String) : Object {{ assert(not (code = ""), "init", "input code cannot be empty!"); assert(str = "", "init", "already initialised!"); str <- code; }}; try_consume() : Bool { let consumer: Object <- consumers.find(str) in if isvoid consumer then false else case consumers.find(str) of c: IStringConsumer => { str <- str.substr(c.consumed_length(), str.length() - c.consumed_length()); tl.push(c.token()); true; }; o: Object => false; esac fi }; out() : Object { out_string(str) }; empty() : Bool { str = "" }; generated_tokens() : TokenList { tl }; };