1 /* 2 Copyright (C) 2003 - 2018 by David White <dave@whitevine.net> 3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/ 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY. 11 12 See the COPYING file for more details. 13 */ 14 15 #pragma once 16 17 #include <string> 18 19 namespace wfl 20 { 21 namespace tokenizer 22 { 23 24 typedef std::string::const_iterator iterator; 25 26 /// TOKEN_TYPE is already defined in a Winnt.h (a windows header which is included under some conditions.) 27 enum TOKEN_TYPE { TOKEN_OPERATOR, TOKEN_STRING_LITERAL, 28 TOKEN_IDENTIFIER, TOKEN_INTEGER, TOKEN_DECIMAL, 29 TOKEN_LPARENS, TOKEN_RPARENS, 30 TOKEN_LSQUARE, TOKEN_RSQUARE, 31 TOKEN_COMMA, TOKEN_SEMICOLON, 32 TOKEN_WHITESPACE, TOKEN_EOL, TOKEN_KEYWORD, 33 TOKEN_COMMENT, TOKEN_POINTER }; 34 35 struct token { 36 tokenwfl::tokenizer::token37 token() : 38 type(TOKEN_COMMENT), 39 begin(), 40 end(), 41 line_number(1), 42 filename() 43 { 44 } 45 tokenwfl::tokenizer::token46 token(iterator& i1, iterator i2, TOKEN_TYPE type) : 47 type(type), 48 begin(i1), 49 end(i2), 50 line_number(1), 51 filename() 52 { 53 } 54 55 TOKEN_TYPE type; 56 iterator begin, end; 57 int line_number; 58 const std::string* filename; 59 }; 60 61 token get_token(iterator& i1, iterator i2); 62 63 struct token_error 64 { token_errorwfl::tokenizer::token_error65 token_error() : description_(), formula_() {} token_errorwfl::tokenizer::token_error66 token_error(const std::string& dsc, const std::string& formula) : description_(dsc), formula_(formula) {} 67 std::string description_; 68 std::string formula_; 69 }; 70 71 } 72 73 } 74