module: %parse-string author: Nick Kramer (nkramer@cs.cmu.edu) synopsis: A useful little data structure that's not useful enough to export outside the library. copyright: Copyright (C) 1994, Carnegie Mellon University. All rights reserved. rcs-header: $Header: /scm/cvs/fundev/Sources/lib/string-extensions/parse-string.dylan,v 1.1 2004/03/12 00:09:20 cgay Exp $ //====================================================================== // // Copyright (c) 1994 Carnegie Mellon University // All rights reserved. // // Use and copying of this software and preparation of derivative // works based on this software are permitted, including commercial // use, provided that the following conditions are observed: // // 1. This copyright notice must be retained in full on any copies // and on appropriate parts of any derivative works. // 2. Documentation (paper or online) accompanying any system that // incorporates this software, or any part of it, must acknowledge // the contribution of the Gwydion Project at Carnegie Mellon // University. // // This software is made available "as is". Neither the authors nor // Carnegie Mellon University make any warranty about the software, // its performance, or its conformity to any specification. // // Bug reports, questions, comments, and suggestions should be sent by // E-mail to the Internet address "gwydion-bugs@cs.cmu.edu". // //====================================================================== // Parse strings: A string along with some state. A parse-string // supports two operations: lookahead and consume. lookahead(s) gets // the next character in the parse string, while consume(s) moves the // pointer along. // define class () constant slot string :: , required-init-keyword: #"string"; // KJP: constant slot index :: , init-value: 0; end class ; define constant = false-or(); define method consume (s :: ) => s :: ; if (s.index >= size(s.string)) #f; else s.index := s.index + 1; s; end if; end method consume; define method lookahead (s :: ) => answer :: ; if (s.index >= size(s.string)) #f; else s.string[s.index]; end if; end method lookahead; define method parse-string-done? (s :: ) => answer :: ; s.index >= s.string.size; end method parse-string-done?; // Seals for file parse-string.dylan // -- subclass of define sealed domain make(singleton()); define sealed domain initialize();