-
Notifications
You must be signed in to change notification settings - Fork 3
/
Parsing.winxed
41 lines (37 loc) · 977 Bytes
/
Parsing.winxed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Routines to help with parsing.
These routines assume a 2-part lookahead mechanism. The 's' parameter is an
Integer stack to hold lookahead characters. The 'b' parameter is a
StringIterator.
*/
inline peek_next(var s, var i) return int
{
if (!have_more_chars(s, i))
return ASCII_NULL;
if (elements(s) > 0)
return int(s[0]);
int _c = shift_int(i);
unshift_int(s, _c);
return _c;
}
inline get_next(var s, var i) return int
{
if (!have_more_chars(s, i))
return ASCII_NULL;
if (elements(s) > 0)
return shift_int(s);
return shift_int(i);
}
inline eat_whitespace(var s, var b)
{
int c = ASCII_SPACE;
while(have_more_chars(s, b) && codepoint_is_whitespace(c))
c = get_next(s, b);
if (c != ASCII_NULL && !codepoint_is_whitespace(c))
unshift_int(s, c);
}
inline have_more_chars(var s, var b) return int
{
if (b || elements(s) > 0)
return true;
return false;
}