forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenizer.h
More file actions
69 lines (55 loc) · 1.7 KB
/
tokenizer.h
File metadata and controls
69 lines (55 loc) · 1.7 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef LFORTRAN_SRC_PARSER_TOKENIZER_H
#define LFORTRAN_SRC_PARSER_TOKENIZER_H
#include <libasr/exception.h>
#include <lpython/parser/parser_stype.h>
namespace LFortran
{
class Tokenizer
{
public:
unsigned char *cur;
unsigned char *tok;
unsigned char *cur_line;
unsigned int line_num;
unsigned char *string_start;
int last_token=-1;
std::vector<uint64_t> enddo_label_stack = {0};
bool enddo_newline_process = false;
int enddo_state = 0;
int enddo_insert_count = 0;
public:
// Set the string to tokenize. The caller must ensure `str` will stay valid
// as long as `lex` is being called.
void set_string(const std::string &str);
// Get next token. Token ID is returned as function result, the semantic
// value is put into `yylval`.
int lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnostics &diagnostics);
// Return the current token as std::string
std::string token() const
{
return std::string((char *)tok, cur - tok);
}
// Return the current token as YYSTYPE::Str
void token(Str &s) const
{
s.p = (char*) tok;
s.n = cur-tok;
}
// Return the current token as YYSTYPE::Str, strips first and last character
void token_str(Str &s) const
{
s.p = (char*) tok + 1;
s.n = cur-tok-2;
}
// Return the current token's location
void token_loc(Location &loc) const
{
loc.first = tok-string_start;
loc.last = cur-string_start-1;
}
void add_rel_warning(diag::Diagnostics &diagnostics, int rel_token) const;
};
bool lex_int(const unsigned char *s, const unsigned char *e, uint64_t &u,
Str &suffix);
} // namespace LFortran
#endif