parser.cxx

Sun, 15 Jul 2012 00:31:08 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 15 Jul 2012 00:31:08 +0300
changeset 22
b48e10ca8832
parent 21
ae602e667879
child 24
7dcc8419dbdb
permissions
-rw-r--r--

Added rudimentary global var support

0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * botc source code
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012 Santeri `Dusk` Piippo
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 * All rights reserved.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 *
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 *
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright notice,
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * this list of conditions and the following disclaimer.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * this list of conditions and the following disclaimer in the documentation
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * and/or other materials provided with the distribution.
3
08cab2b67dce oh blerb.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
14 * 3. Neither the name of the developer nor the names of its contributors may
08cab2b67dce oh blerb.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
15 * be used to endorse or promote products derived from this software without
08cab2b67dce oh blerb.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 2
diff changeset
16 * specific prior written permission.
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 * 4. Redistributions in any form must be accompanied by information on how to
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 * obtain complete source code for the software and any accompanying
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 * software that uses the software. The source code must either be included
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 * in the distribution or be available for no more than the cost of
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 * distribution plus a nominal fee, and must be freely redistributable
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 * under reasonable conditions. For an executable file, complete source
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 * code means the source code for all modules it contains. It does not
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 * include source code for modules or files that typically accompany the
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 * major components of the operating system on which the executable file
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 * runs.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 *
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 * POSSIBILITY OF SUCH DAMAGE.
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 */
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
41 #define __PARSER_CXX__
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
42
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 #include <stdio.h>
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 #include <stdlib.h>
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 #include "common.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 #include "str.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 #include "objwriter.h"
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 #include "scriptreader.h"
2
bb2c45522eb6 Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
49 #include "events.h"
8
c8bfa7e6ae1b Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 7
diff changeset
50 #include "commands.h"
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
51 #include "stringtable.h"
22
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
52 #include "variables.h"
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
54 #define MUST_TOPLEVEL if (g_CurMode != MODE_TOPLEVEL) \
7
118d3d5db64f Improved error handling; added parser warnings
Teemu Piippo <crimsondusk64@gmail.com>
parents: 3
diff changeset
55 ParserError ("%ss may only be defined at top level!", token.chars());
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
57 int g_NumStates = 0;
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
58 int g_NumEvents = 0;
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
59 int g_CurMode = MODE_TOPLEVEL;
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
60 str g_CurState = "";
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
61 bool g_stateSpawnDefined = false;
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
62
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 void ScriptReader::BeginParse (ObjWriter* w) {
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
64 bool gotMainLoop = false;
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 while (Next()) {
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
66 // printf ("got token %s\n", token.chars());
17
b4fcc69e426a Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
67 if (!token.icompare ("#include")) {
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
68 MustString ();
9
d279af9afd6d Added proper string checking
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
69
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
70 // First ensure that the file can be opened
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
71 FILE* newfile = fopen (token.chars(), "r");
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
72 if (!newfile)
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
73 ParserError ("couldn't open included file `%s`!", token.chars());
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
74 fclose (newfile);
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
75 ScriptReader* newreader = new ScriptReader (token.chars());
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
76 newreader->BeginParse (w);
17
b4fcc69e426a Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
77 } else if (!token.icompare ("state")) {
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 MUST_TOPLEVEL
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
80 MustString ();
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 // State name must be a word.
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
83 if (token.first (" ") != token.len())
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
84 ParserError ("state name must be a single word! got `%s`", token.chars());
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
85 str statename = token;
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
86
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
87 // stateSpawn is special - it *must* be defined. If we
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
88 // encountered it, then mark down that we have it.
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
89 if (!token.icompare ("stateSpawn"))
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
90 g_stateSpawnDefined = true;
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 // Must end in a colon
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 MustNext (":");
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
95 // If the previous state did not define a mainloop,
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
96 // define a dummy one now, since one has to be present.
17
b4fcc69e426a Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
97 if (g_CurState.len() && !gotMainLoop) {
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
98 w->Write (DH_MAINLOOP);
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
99 w->Write (DH_ENDMAINLOOP);
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
100 }
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
101
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
102 w->Write (DH_STATENAME);
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
103 w->WriteString (statename);
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
104 w->Write (DH_STATEIDX);
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
105 w->Write (g_NumStates);
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
106
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
107 g_NumStates++;
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
108 g_CurState = token;
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
109 gotMainLoop = false;
17
b4fcc69e426a Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
110 } else if (!token.icompare ("event")) {
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 MUST_TOPLEVEL
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // Event definition
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
114 MustString ();
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
116 EventDef* e = FindEventByName (token);
2
bb2c45522eb6 Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
117 if (!e)
12
1bdbfcca2fc6 MustString now behaves more like its siblings - sets token to result rather than returning it
Teemu Piippo <crimsondusk64@gmail.com>
parents: 9
diff changeset
118 ParserError ("bad event! got `%s`\n", token.chars());
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 MustNext ("{");
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
122 g_CurMode = MODE_EVENT;
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 w->Write (DH_EVENT);
2
bb2c45522eb6 Added event definitions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
125 w->Write<long> (e->number);
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
126 g_NumEvents++;
17
b4fcc69e426a Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
127 } else if (!token.icompare ("mainloop")) {
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
128 MUST_TOPLEVEL
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
129 MustNext ("{");
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
130 g_CurMode = MODE_MAINLOOP;
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
131 w->Write (DH_MAINLOOP);
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
132 gotMainLoop = true;
17
b4fcc69e426a Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
133 } else if (!token.icompare ("onenter") || !token.icompare ("onexit")) {
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
134 MUST_TOPLEVEL
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
135 bool onenter = !token.compare ("onenter");
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
136
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
137 MustNext ("{");
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
138 g_CurMode = onenter ? MODE_ONENTER : MODE_ONEXIT;
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
139 w->Write (onenter ? DH_ONENTER : DH_ONEXIT);
22
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
140 } else if (!token.compare ("int") || !token.compare ("bool")) {
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
141 // For now, only globals are supported
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
142 if (g_CurMode != MODE_TOPLEVEL || g_CurState.len())
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
143 ParserError ("variables must only be global for now");
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
144
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
145 // Variable definition
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
146 int type = !token.compare ("int") ? RETURNVAL_INT: RETURNVAL_BOOLEAN;
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
147
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
148 MustNext ();
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
149 str varname = token;
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
150 ScriptVar* var = DeclareGlobalVariable (this, varname, type);
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
151
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
152 if (!var)
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
153 ParserError ("declaring %s variable %s failed",
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
154 g_CurState.len() ? "state" : "global", varname.chars());
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
155
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
156 // Assign it, if desired
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
157 if (!PeekNext().compare ("=")) {
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
158 MustNext ("=");
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
159 MustValue (type);
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
160
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
161 var->value = token;
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
162 }
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
163
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
164 MustNext (";");
8
c8bfa7e6ae1b Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 7
diff changeset
165 } else if (!token.compare ("}")) {
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
166 // Closing brace
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
167 int dataheader = (g_CurMode == MODE_EVENT) ? DH_ENDEVENT :
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
168 (g_CurMode == MODE_MAINLOOP) ? DH_ENDMAINLOOP :
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
169 (g_CurMode == MODE_ONENTER) ? DH_ENDONENTER :
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
170 (g_CurMode == MODE_ONEXIT) ? DH_ENDONEXIT : -1;
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
171
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
172 if (dataheader == -1)
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
173 ParserError ("unexpected `}`");
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
174
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 // Closing brace..
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
176 w->Write (dataheader);
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
177 g_CurMode = MODE_TOPLEVEL;
18
dbcc3b784234 New rule: a semicolon is now required after events, mainloop, onexit and onenter definitions.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
178
dbcc3b784234 New rule: a semicolon is now required after events, mainloop, onexit and onenter definitions.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
179 MustNext (";");
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 } else {
8
c8bfa7e6ae1b Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 7
diff changeset
181 // Check if it's a command.
c8bfa7e6ae1b Commands are now read properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 7
diff changeset
182 CommandDef* comm = GetCommandByName (token);
15
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
183 if (comm)
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
184 ParseCommand (comm, w);
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
185 else
17
b4fcc69e426a Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
186 ParserError ("unknown keyword `%s`", token.chars());
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 }
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 }
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189
1
f0c61c204bc8 Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 0
diff changeset
190 if (g_CurMode != MODE_TOPLEVEL)
17
b4fcc69e426a Events and commands are now treated properly case-insensitively.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
191 ParserError ("script did not end at top level; did you forget a `}`?");
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
192
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
193 // stateSpawn must be defined!
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
194 if (!g_stateSpawnDefined)
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
195 ParserError ("script must have a state named `stateSpawn`!");
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196
19
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
197 // If the last state did not have a main loop, define a dummy one now.
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
198 if (!gotMainLoop) {
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
199 w->Write (DH_MAINLOOP);
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
200 w->Write (DH_ENDMAINLOOP);
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
201 }
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
202
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
203 // If we added strings here, we need to write a list of them.
21
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
204 unsigned int stringcount = CountStringTable ();
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
205 if (stringcount) {
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
206 w->Write<long> (DH_STRINGLIST);
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
207 w->Write<long> (stringcount);
21
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
208 for (unsigned int a = 0; a < stringcount; a++)
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
209 w->WriteString (g_StringTable[a]);
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
210 }
22
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
211
b48e10ca8832 Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
212 printf ("%u string%s written\n", stringcount, PLURAL (stringcount));
0
8dce9696d62d Initial commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 }
15
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
214
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
215 void ScriptReader::ParseCommand (CommandDef* comm, ObjWriter* w) {
16
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
216 // If this was defined at top-level, we stop right at square one!
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
217 if (g_CurMode == MODE_TOPLEVEL)
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
218 ParserError ("no commands allowed at top level!");
393359908179 Added mainloop/onenter/onexit support, fixed state writing.. this thing can compile the script for the `jumping arghbot` now!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
219
15
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
220 MustNext ("(");
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
221 int curarg = 0;
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
222 while (1) {
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
223 if (curarg >= comm->maxargs) {
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
224 if (!PeekNext().compare (","))
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
225 ParserError ("got `,` while expecting command-terminating `)`, are you passing too many parameters? (max %d)",
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
226 comm->maxargs);
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
227 MustNext (")");
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
228 curarg++;
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
229 break;
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
230 }
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
231
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
232 /*
15
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
233 if (!Next ())
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
234 ParserError ("unexpected end-of-file, unterminated command");
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
235
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
236 // If we get a ")" now, the user probably gave too few parameters
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
237 if (!token.compare (")"))
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
238 ParserError ("unexpected `)`, did you pass too few parameters? (need %d)", comm->numargs);
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
239 */
15
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
240
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
241 switch (comm->argtypes[curarg]) {
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
242 case RETURNVAL_INT:
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
243 MustNumber();
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
244 w->Write<long> (DH_PUSHNUMBER);
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
245 w->Write<long> (atoi (token.chars ()));
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
246 break;
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
247 case RETURNVAL_BOOLEAN:
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
248 MustBool();
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
249 w->Write<long> (DH_PUSHNUMBER);
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
250 w->Write<long> (BoolValue ());
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
251 break;
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
252 case RETURNVAL_STRING:
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
253 MustString();
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
254 w->Write<long> (DH_PUSHSTRINGINDEX);
21
ae602e667879 Added -l command line parameter, if given, botc will list all available commands and exit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
255 w->Write<long> (PushToStringTable (token.chars()));
20
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
256 break;
d7b13805d1e0 Added string table and support for string parameters in commands.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 19
diff changeset
257 }
15
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
258
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
259 if (curarg < comm->numargs - 1) {
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
260 MustNext (",");
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
261 } else if (curarg < comm->maxargs - 1) {
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
262 // Can continue, but can terminate as well.
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
263 if (!PeekNext ().compare (")")) {
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
264 MustNext (")");
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
265 curarg++;
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
266 break;
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
267 } else
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
268 MustNext (",");
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
269 }
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
270
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
271 curarg++;
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
272 }
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
273 MustNext (";");
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
274
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
275 // If the script skipped any optional arguments, fill in defaults.
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
276 while (curarg < comm->maxargs) {
19
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
277 w->Write<long> (DH_PUSHNUMBER);
15
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
278 w->Write<long> (comm->defvals[curarg]);
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
279 curarg++;
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
280 }
19
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
281
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
282 w->Write<long> (DH_COMMAND);
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
283 w->Write<long> (comm->number);
66993500719f Commands w/ arguments are now written correctly.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
284 w->Write<long> (comm->maxargs);
15
284c2fc6c1cd Moved command parser to a new function.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
285 }

mercurial