1
// $Id: PLFParser.cc,v 1.12 2001/06/11 08:45:21 grumbel Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 1999 Ingo Ruhnke <grumbel@gmx.de>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
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.
26
#include "StringConverter.hh"
27
#include "PLFParser.hh"
28
#include "PingusError.hh"
33
PLFParserEOF::PLFParserEOF()
37
PLFParser::PLFParser()
42
PLFParser::~PLFParser()
47
PLFParser::init(string filename)
58
// Open the file and do some error checking.
60
PLFParser::open(string filename)
62
in.open(filename.c_str());
66
throw PingusError("Couldn't open: " + filename);
70
cout << "Successfully opened plf file" << endl;
73
// Return the next char from file and check for eof.
75
PLFParser::get_char(void)
80
if (verbose > 1) cout << "PLFParser: Result of get_char() will be undefined" << endl;
81
// throw PingusError("");
87
if (verbose > 1) cout << "PLF::get_char(): Found EOF!" << endl;
89
// throw PLFParserEOF();
98
// Return the next char from file, remove all comments and spaces before.
100
PLFParser::get_raw_atom(void)
106
// Ignoring "//" comments
109
if ((ic = get_char()) == '/') {
110
while(get_char() != '\n'); // Ignoring until EOL
118
if ((c = get_char()) == '*') {
122
if (get_char() == '/')
132
while (isspace(c = get_char()));
134
if (isspace(last_atom))
142
// Return the next atom and keep it.
144
PLFParser::get_atom(void)
146
last_atom = get_raw_atom();
152
PLFParser::get_groupname(void)
159
while((isalpha(atom = get_atom()) || atom == '_'))
168
syntax_error(string("Invalid group name: Found char: '") + atom + "'");
173
// Return the name of the value identiver.
175
PLFParser::get_valueid(void)
185
if (atom == '}' && ret_val.empty()) {
189
if (isalpha(atom) || atom == '_') {
191
} else if (isspace(atom)) {
193
} else if (atom == '=') {
197
syntax_error(string("Unexpected char: '") + atom + "'");
205
PLFParser::get_value(void)
215
if (atom == '"' && ret_val == "") {
216
while((atom = get_char()) != '"') {
227
if (!isalnum(atom) && atom != '-' && atom != '_' && atom != '.')
232
syntax_error(string("Unexpected char '") + atom + "'");
243
PLFParser::get_cast(void)
265
// Jumps to the position of the next token after 'a', no other char's
266
// then spaces are allowed before 'a'.
268
PLFParser::jump_after(char c)
275
if (isspace(atom) || atom == c) {
284
syntax_error(string("jump_after(): Expected '") + c + "', got '" + atom + "'" );
288
PLFParser::jump(void)
300
// Print a error message with lineno and filename.
302
PLFParser::syntax_error(string error = "")
306
error_str = "PLF: Syntax Error at line " + to_string (lineno);
309
error_str += ":PLF:" + error + "\n";
311
throw PingusError(error_str);
314
// Parse the file and fill all structs with the values.
316
PLFParser::parse(void)
325
groupname = get_groupname();
329
set_group_start(groupname);
334
valueid = get_valueid();
346
cout << "ValueID: " << valueid << endl;
347
cout << "Cast: " << cast << endl;
348
cout << "Value: " << value << endl;
350
set_value(valueid, cast, value);
356
/* catch(PLFParserEOF a) {
357
if (verbose > 1) cout << "PLF: Catched EOF" << endl;