summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Lexer.h
blob: d94f708897978c305c75856a50746f1d452cefa9 (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
47
#ifndef LEXER_H
#define LEXER_H
#include <vector>
#include <string>
#include <utility>
#include <cctype>
#include <iostream>
#include "Token.h"

using namespace std;

/**
 * Lexer is a class which gets some text, analyzes it and returns a vector of tokens.
 */
class Lexer
{
public:
	Lexer();
	virtual ~Lexer();
	/**
	 * parse_line(line) analyzes input and returns vector of tokens.
	 */
	vector<Token> parse_line(string line);
	pair<string, Token> parse_token(string line);

	//helper function to evaluate type of token
	bool is_keyword(string value);
	bool is_punctuation(char c);
	bool is_operator(string value );

private:
	void add_keyword(string word);
	void add_punctuation_char(char c);
	void add_operator(string oper);
	string unescape_string(string text);

	/**
	 * Tokens have type and value. Type is evaluated in function guess_type(value).
	 */
	type_of_token guess_type(string value);

	vector<string> keywords;
	vector<char> punctuation;
	vector<string> operators;
};

#endif // LEXER_H