-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.hpp
More file actions
72 lines (58 loc) · 2.35 KB
/
Copy pathlexer.hpp
File metadata and controls
72 lines (58 loc) · 2.35 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
70
71
72
// Sözcüksel çözümleyici.
//
// SPEC §9'daki dört kuralı uygular:
// 1. Parantez derinliği girintiyi bastırır
// 2. brace_block içinde INDENT/DEDENT yok, NEWLINE var
// 3. f-string'in {...} bölümü alt-lexer'a bırakılır (gövde ham tutulur)
// 4. '=>' sonrası '{' HER ZAMAN bloktur, map literal'i değil
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include "diag.hpp"
#include "source.hpp"
#include "token.hpp"
namespace rs {
class Lexer {
public:
Lexer(const Source& src, Diagnostics& diag) noexcept : src_(&src), diag_(&diag) {}
// Tüm kaynağı tarar. Hatalar diag'a yazılır; taramaya elden geldiğince
// devam edilir ki kullanıcı tek seferde birden çok hata görsün.
[[nodiscard]] std::vector<Token> tokenize();
private:
// İç içe geçme türü. '{' iki farklı şey olabildiği için ayrı tutuluyor.
enum class Nest : std::uint8_t { Paren, Bracket, MapBrace, BlockBrace };
// --- imleç ---
[[nodiscard]] bool eof() const noexcept { return i_ >= src_->size(); }
[[nodiscard]] char peek(std::uint32_t ileri = 0) const noexcept;
char advance() noexcept;
bool match(char beklenen) noexcept;
// --- üretim ---
void emit(Tok kind, Span span);
void emitValue(Token t);
// --- katmanlar ---
void handleIndentation();
void skipInlineSpace();
void scanToken();
void scanIdentOrKeyword();
void scanNumber();
void scanString(char tirnak, bool ham, bool bicimli, std::uint32_t basla);
void scanOperator();
// --- yardımcılar ---
[[nodiscard]] bool newlineAllowed() const noexcept;
// brace_block KENDİ girinti bağlamını taşır: içinde 'if x:' yazılabilmesi
// için INDENT/DEDENT üretilmek ZORUNDA. (İlk tasarımda bastırılıyordu;
// 09 ve 13 numaralı örnekler bunun imkânsız olduğunu gösterdi.)
[[nodiscard]] bool indentTracked() const noexcept { return newlineAllowed(); }
[[nodiscard]] Span here(std::uint32_t basla) const noexcept;
void closeNest(Nest beklenen, Tok kind, Span span);
const Source* src_;
Diagnostics* diag_;
std::uint32_t i_ = 0;
std::vector<Token> out_;
std::vector<std::uint32_t> indents_{0};
std::vector<Nest> nesting_;
bool lineStart_ = true;
Tok lastSignificant_ = Tok::Newline; // '=>' sonrası '{' ayrımı için
};
} // namespace rs