]> git.xonotic.org Git - xonotic/darkplaces.git/blob - token.c
Parser is now tail recursive. Implemented parse tree, self-cleaning on failure
[xonotic/darkplaces.git] / token.c
1 /*
2 Copyright (C) 2000-2021 Ashley Rose Hale (LadyHavoc)
3 Copyright (C) 2021 David Knapp (Cloudwalk)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 */
21
22 #include "darkplaces.h"
23 #include "token.h"
24
25 // Advance forward in the stream as many times as 'count', cleanly.
26 const char *Token_Next(const char *data, int count)
27 {
28         const char *out = data;
29         for (int i = 0; i < count; i++)
30         {
31                 if (!*out)
32                         break;
33                 out++;
34         }
35
36         return out;
37 }
38
39 // Skips newlines, and handles different line endings.
40 qbool Token_Newline(const char **data)
41 {
42         if(**data == '\n')
43                 goto newline;
44         if(**data == '\r')
45         {
46                 if(**data + 1 == '\n')
47                         (*data)++;
48                 goto newline;
49         }
50         return false;
51 newline:
52         (*data)++;
53         return true;
54 }