summaryrefslogtreecommitdiff
path: root/src/lexer.h
blob: 5847269a9d9c05ead327c2556382f7945ce9e2fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef BU_LEXER_H
#define BU_LEXER_H

#include "bu/variant.h"

namespace Bu
{
	class Stream;

	/**
	 * The base class for creating a lexical analyzer.  This is designed to work
	 * in tandem with the Bu::Parser class, which uses this to tokenize textual
	 * input.  It can be used by just about anything that cares about tokens
	 * more than raw input, though.
	 */
	class Lexer
	{
	public:
		Lexer();
		virtual ~Lexer();

		typedef int32_t TokenType;

		class Token
		{
		public:
			Token();
			Token( TokenType iToken );

			template<class t>
			Token( TokenType iToken, const t &v ) :
				iToken( iToken ),
				vExtra( v )
			{
			}
			TokenType iToken;
			Bu::Variant vExtra;
		};

		virtual Token *nextToken()=0;

		virtual Bu::FString tokenToString( const Token &t );
	};
};

#endif