-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlex.h
46 lines (36 loc) · 875 Bytes
/
lex.h
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
//
// Created by alexwang on 11/24/17.
//
#ifndef AL_LEX_H
#define AL_LEX_H
#include <istream>
#include <memory>
#include <regex>
#include <re2/set.h>
#include "parser.tab.hpp"
#include <codecvt>
#include <locale>
#include "ast.h"
#include <string>
namespace al {
class Lexer {
public:
explicit Lexer(const std::string &s) :s(s), input(s) { }
std::string nextUtf8CodePoint() {
char c = input[0];
uint32_t cp_len = 1;
if((c & 0xf8) == 0xf0) cp_len = 4;
else if((c & 0xf0) == 0xe0) cp_len = 3;
else if((c & 0xe0) == 0xc0) cp_len = 2;
string ret = input.substr(0, cp_len).as_string();
input.remove_prefix(cp_len);
return ret;
}
bool parseQuoteString(std::string &str, std::string eos);
Parser::symbol_type lex();
private:
std::string s;
re2::StringPiece input;
};
}
#endif //AL_LEX_H