Sat, 14 Jul 2012 15:44:38 +0300
Restructured the command def parser, added parameter lists to definition file.
0 | 1 | /* |
2 | * botc source code | |
3 | * Copyright (C) 2012 Santeri `Dusk` 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. | |
3 | 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. | |
0 | 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 | #include "objwriter.h" | |
47 | ||
48 | // Where is the parser at? | |
49 | enum parsermode { | |
50 | MODE_TOPLEVEL, // at top level | |
51 | MODE_EVENT // inside event definition | |
52 | }; | |
53 | ||
54 | class ScriptReader { | |
55 | public: | |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
56 | // ==================================================================== |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
57 | // MEMBERS |
0 | 58 | FILE* fp; |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
59 | str filepath; |
0 | 60 | unsigned int pos; |
61 | unsigned int curline; | |
10
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
62 | unsigned int curchar; |
0 | 63 | str token; |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
64 | bool atnewline; |
8
c8bfa7e6ae1b
Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
65 | bool extdelimeters; |
0 | 66 | |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
67 | // ==================================================================== |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
68 | // METHODS |
9
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
69 | // scriptreader.cxx: |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
70 | ScriptReader (str path); |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
71 | ~ScriptReader (); |
0 | 72 | char ReadChar (); |
73 | bool Next (); | |
74 | str PeekNext (); | |
75 | void Seek (unsigned int n, int origin); | |
76 | void MustNext (const char* c = ""); | |
10
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
77 | str MustGetString (); |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
78 | void MustNumber (); |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
79 | void MustBool (); |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
80 | |
7
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
81 | void ParserError (const char* message, ...); |
118d3d5db64f
Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
82 | void ParserWarning (const char* message, ...); |
0 | 83 | |
9
d279af9afd6d
Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
84 | // parser.cxx: |
0 | 85 | void BeginParse (ObjWriter* w); |
10
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
86 | |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
87 | private: |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
88 | bool nextreintepret; |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
89 | char c; |
2c0f76090372
Restructured the command def parser, added parameter lists to definition file.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
90 | void ParserMessage (const char* header, char* message); |
0 | 91 | }; |
92 | ||
93 | #endif // __SCRIPTREADER_H__ |