4
* Copyright © 2003 Keith Packard
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
29
public namespace Lex {
31
public exception syntax ();
35
return File::getc (f);
36
} catch File::io_error (string reason, File::error_type error, file f) {
38
case File::error_type.UTF8:
39
printf ("invalid utf\n");
42
raise File::io_error (reason, error, f);
48
bool skipwhite (file f, bool allow_newline) {
49
while ((int c = lexc (f)) != -1) {
50
if (c == '\n' && !allow_newline) {
54
if (!Ctype::isspace(c)) {
62
public void skipline (file f) {
63
while ((int c = lexc (f)) != -1)
70
string next_word (file f) {
74
while ((int c = lexc (f)) != -1) {
88
if (!quoted && !escaped)
90
if (Ctype::isspace (c))
96
s = s + String::new(c);
102
public bool eol (file f) {
103
skipwhite (f, false);
113
public string word (file f) {
114
if (skipwhite (f, false)) {
118
return next_word (f);
121
public string firstword (file f) {
123
return next_word (f);
126
public string[] recv(file f) {
128
string[...] words = {};
131
void add (string w) {
132
words[dim(words)] = w;
135
string w = firstword (f);