Fri, 15 Mar 2013 20:11:18 +0200
Initial commit
0 | 1 | /* |
2 | * botc source code | |
3 | * Copyright (C) 2012 Santeri `azimuth` Piippo | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright notice, | |
10 | * this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
12 | * this list of conditions and the following disclaimer in the documentation | |
13 | * and/or other materials provided with the distribution. | |
14 | * 3. Neither the name of the developer nor the names of its contributors may | |
15 | * be used to endorse or promote products derived from this software without | |
16 | * specific prior written permission. | |
17 | * 4. Redistributions in any form must be accompanied by information on how to | |
18 | * obtain complete source code for the software and any accompanying | |
19 | * software that uses the software. The source code must either be included | |
20 | * in the distribution or be available for no more than the cost of | |
21 | * distribution plus a nominal fee, and must be freely redistributable | |
22 | * under reasonable conditions. For an executable file, complete source | |
23 | * code means the source code for all modules it contains. It does not | |
24 | * include source code for modules or files that typically accompany the | |
25 | * major components of the operating system on which the executable file | |
26 | * runs. | |
27 | * | |
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
38 | * POSSIBILITY OF SUCH DAMAGE. | |
39 | */ | |
40 | ||
41 | #ifndef __SCRIPTREADER_H__ | |
42 | #define __SCRIPTREADER_H__ | |
43 | ||
44 | #include <stdio.h> | |
45 | #include "str.h" | |
46 | ||
47 | #define MAX_FILESTACK 8 | |
48 | #define MAX_SCOPE 32 | |
49 | #define MAX_CASE 64 | |
50 | ||
51 | #define PERFORM_FORMAT(in, out) \ | |
52 | va_list v; \ | |
53 | va_start (v, in); \ | |
54 | char* out = vdynformat (in, v, 256); \ | |
55 | va_end (v); | |
56 | ||
57 | class Scanner { | |
58 | public: | |
59 | // ==================================================================== | |
60 | // MEMBERS | |
61 | FILE* fp[MAX_FILESTACK]; | |
62 | char* saFilePath[MAX_FILESTACK]; | |
63 | int fc; | |
64 | ||
65 | ulong ulaPosition[MAX_FILESTACK]; | |
66 | ulong ulaLineNumber[MAX_FILESTACK]; | |
67 | ulong ulaCurChar[MAX_FILESTACK]; | |
68 | long laSavedPos[MAX_FILESTACK]; // filepointer cursor position | |
69 | str token; | |
70 | short dCommentMode; | |
71 | long lPrevPos; | |
72 | str zPrevToken; | |
73 | ||
74 | // ==================================================================== | |
75 | // METHODS | |
76 | Scanner (str path); | |
77 | ~Scanner (); | |
78 | void OpenFile (str path); | |
79 | void CloseFile (unsigned int u = MAX_FILESTACK); | |
80 | char ReadChar (); | |
81 | char PeekChar (int offset = 0); | |
82 | bool Next (bool peek = false); | |
83 | void Prev (); | |
84 | str PeekNext (int offset = 0); | |
85 | void Seek (unsigned int n, int origin); | |
86 | void MustNext (const char* c = ""); | |
87 | void MustThis (const char* c); | |
88 | void MustString (bool gotquote = false); | |
89 | void MustNumber (bool fromthis = false); | |
90 | void MustBool (); | |
91 | bool BoolValue (); | |
92 | ||
93 | void ParserError (const char* message, ...); | |
94 | void ParserWarning (const char* message, ...); | |
95 | ||
96 | private: | |
97 | bool bAtNewLine; | |
98 | char c; | |
99 | void ParserMessage (const char* header, char* message); | |
100 | }; | |
101 | ||
102 | #endif // __SCRIPTREADER_H__ |