src/lexer.cc

Sun, 19 Jan 2014 20:16:00 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 19 Jan 2014 20:16:00 +0200
changeset 82
841562f5a32f
parent 81
071715c17296
child 85
264a61e9eba0
permissions
-rw-r--r--

- added the public-domain updaterevision so I can have access to git stuff
- lexer #include now works properly! woot!
- merged commands.def and events.def to botc_defs.bts. This is essentially the "zcommon.acs" of botc.

73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
75
bf8c57437231 - renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents: 74
diff changeset
2 Copyright (c) 2014, Santeri Piippo
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions are met:
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * Redistributions of source code must retain the above copyright
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 notice, this list of conditions and the following disclaimer.
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * Redistributions in binary form must reproduce the above copyright
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * Neither the name of the <organization> nor the
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 names of its contributors may be used to endorse or promote products
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 derived from this software without specific prior written permission.
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 */
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include <cstring>
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "lexer.h"
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 static string_list g_file_name_stack;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 static lexer* g_main_lexer = null;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
37 // =============================================================================
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
38 //
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 lexer::lexer()
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 assert (g_main_lexer == null);
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 g_main_lexer = this;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
45 // =============================================================================
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
46 //
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 lexer::~lexer()
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 g_main_lexer = null;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
52 // =============================================================================
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
53 //
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 void lexer::process_file (string file_name)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
56 g_file_name_stack << file_name;
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 FILE* fp = fopen (file_name, "r");
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 if (fp == null)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 error ("couldn't open %1 for reading: %2", file_name, strerror (errno));
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 lexer_scanner sc (fp);
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
63 check_file_header (sc);
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 while (sc.get_next_token())
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 // Preprocessor commands:
74
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
68 if (sc.get_token_type() == tk_hash)
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 must_get_next_from_scanner (sc, tk_symbol);
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 if (sc.get_token_text() == "include")
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 must_get_next_from_scanner (sc, tk_string);
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 string file_name = sc.get_token_text();
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 if (g_file_name_stack.contains (file_name))
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 error ("attempted to #include %1 recursively", sc.get_token_text());
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 process_file (file_name);
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 else
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 error ("unknown preprocessor directive \"#%1\"", sc.get_token_text());
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 else
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 token tok;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 tok.file = file_name;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 tok.line = sc.get_line();
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 tok.column = sc.get_column();
74
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
91 tok.type = sc.get_token_type();
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 tok.text = sc.get_token_text();
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
93
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
94 // devf ("Token #%1: %2:%3:%4: %5 (%6)\n", m_tokens.size(),
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
95 // tok.file, tok.line, tok.column, describe_token (&tok), describe_token_type (tok.type));
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
96
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 m_tokens << tok;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 m_token_position = m_tokens.begin() - 1;
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
102 g_file_name_stack.remove (file_name);
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
103 }
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
104
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
105 // ============================================================================
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
106 //
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
107 static bool is_valid_header (string header)
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
108 {
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
109 if (header.ends_with ("\n"))
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
110 header.remove_from_end (1);
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
111
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
112 string_list tokens = header.split (" ");
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
113
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
114 if (tokens.size() != 2 || tokens[0] != "#!botc" || tokens[1].empty())
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
115 return false;
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
116
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
117 string_list nums = tokens[1].split (".");
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
118
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
119 if (nums.size() == 2)
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
120 nums << "0";
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
121 elif (nums.size() != 3)
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
122 return false;
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
123
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
124 bool ok_a, ok_b, ok_c;
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
125 long major = nums[0].to_long (&ok_a);
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
126 long minor = nums[1].to_long (&ok_b);
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
127 long patch = nums[2].to_long (&ok_c);
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
128
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
129 if (!ok_a || !ok_b || !ok_c)
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
130 return false;
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
131
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
132 if (VERSION_NUMBER < MAKE_VERSION_NUMBER (major, minor, patch))
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
133 error ("The script file requires " APPNAME " v%1, this is v%2",
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
134 make_version_string (major, minor, patch), get_version_string (e_short_form));
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
135
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
136 return true;
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
137 }
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
138
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
139 // ============================================================================
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
140 //
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
141 void lexer::check_file_header (lexer_scanner& sc)
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
142 {
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
143 if (!is_valid_header (sc.read_line()))
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
144 error ("Not a valid botscript file! File must start with '#!botc <version>'");
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 // =============================================================================
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 //
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 bool lexer::get_next (e_token req)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 iterator pos = m_token_position;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
75
bf8c57437231 - renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents: 74
diff changeset
153 if (m_tokens.is_empty())
bf8c57437231 - renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents: 74
diff changeset
154 return false;
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 m_token_position++;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
81
071715c17296 - further lexer corrections
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
158 if (is_at_end() || (req != tk_any && get_token_type() != req))
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 m_token_position = pos;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 return false;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 return true;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 // =============================================================================
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 //
81
071715c17296 - further lexer corrections
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
169 void lexer::must_get_next (e_token tt)
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 if (!get_next())
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 error ("unexpected EOF");
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
81
071715c17296 - further lexer corrections
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
174 if (tt != tk_any)
071715c17296 - further lexer corrections
Teemu Piippo <crimsondusk64@gmail.com>
parents: 79
diff changeset
175 must_be (tt);
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 // =============================================================================
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 // eugh..
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 //
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
181 void lexer::must_get_next_from_scanner (lexer_scanner& sc, e_token tt)
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 if (!sc.get_next_token())
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 error ("unexpected EOF");
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
186 if (tt != tk_any && sc.get_token_type() != tt)
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
187 { // TODO
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
188 token tok;
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
189 tok.type = sc.get_token_type();
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
190 tok.text = sc.get_token_text();
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
191
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
192 error ("at %1:%2: expected %3, got %4",
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
193 g_file_name_stack.last(),
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
194 sc.get_line(),
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
195 describe_token_type (tt),
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
196 describe_token (&tok));
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
197 }
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 // =============================================================================
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 //
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 void lexer::must_get_any_of (const list<e_token>& toks)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 if (!get_next())
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 error ("unexpected EOF");
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 for (e_token tok : toks)
75
bf8c57437231 - renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents: 74
diff changeset
208 if (get_token_type() == tok)
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 return;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 string toknames;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 for (const e_token& tok_type : toks)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 if (&tok_type == &toks.last())
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 toknames += " or ";
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 elif (toknames.is_empty() == false)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 toknames += ", ";
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219
74
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
220 toknames += describe_token_type (tok_type);
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 error ("expected %1, got %2", toknames, describe_token (get_token()));
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 // =============================================================================
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 //
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 int lexer::get_one_symbol (const string_list& syms)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 if (!get_next())
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 error ("unexpected EOF");
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232
75
bf8c57437231 - renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents: 74
diff changeset
233 if (get_token_type() == tk_symbol)
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 for (int i = 0; i < syms.size(); ++i)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 if (syms[i] == get_token()->text)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 return i;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 error ("expected one of %1, got %2", syms, describe_token (get_token()));
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 return -1;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 // =============================================================================
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 //
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 void lexer::must_be (e_token tok)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 {
75
bf8c57437231 - renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents: 74
diff changeset
250 if (get_token_type() != tok)
74
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
251 error ("expected %1, got %2", describe_token_type (tok),
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 describe_token (get_token()));
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 // =============================================================================
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 //
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 string lexer::describe_token_private (e_token tok_type, lexer::token* tok)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 {
79
2425fa6a4f21 - parser now processes commands.def properly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 75
diff changeset
259 if (tok_type < tk_last_named_token)
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 return "\"" + lexer_scanner::get_token_string (tok_type) + "\"";
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 switch (tok_type)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 {
82
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
264 case tk_symbol: return tok ? tok->text : "a symbol";
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
265 case tk_number: return tok ? tok->text : "a number";
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
266 case tk_string: return tok ? ("\"" + tok->text + "\"") : "a string";
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
267 case tk_any: return tok ? tok->text : "any token";
841562f5a32f - added the public-domain updaterevision so I can have access to git stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
268 default: break;
73
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271 return "";
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 // =============================================================================
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 //
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 bool lexer::peek_next (lexer::token* tk)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 iterator pos = m_token_position;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 bool r = get_next();
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 if (r && tk != null)
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 *tk = *m_token_position;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 m_token_position = pos;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 return r;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 }
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 // =============================================================================
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 //
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 lexer* lexer::get_main_lexer()
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291 {
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 return g_main_lexer;
1ee9b312dc18 - *hot stuff coming through*
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 }
74
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
294
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
295 // =============================================================================
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
296 //
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
297 string lexer::peek_next_string (int a)
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
298 {
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
299 if (m_token_position + a >= m_tokens.end())
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
300 return "";
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
301
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
302 iterator oldpos = m_token_position;
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
303 m_token_position += a;
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
304 string result = get_token()->text;
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
305 m_token_position = oldpos;
75
bf8c57437231 - renamed files to .cxx, restructured parser.cc
Teemu Piippo <crimsondusk64@gmail.com>
parents: 74
diff changeset
306 return result;
74
007fbadfa7f9 more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
307 }

mercurial