|
5 | 5 | #include <fstream> |
6 | 6 |
|
7 | 7 | namespace frontend { |
8 | | - static context::Options optionsValue; |
9 | | - |
10 | 8 | char Lexer::peek() const { |
11 | 9 | return position < source.size() ? source[position] : '\0'; |
12 | 10 | } |
@@ -34,22 +32,21 @@ namespace frontend { |
34 | 32 | } |
35 | 33 |
|
36 | 34 | Lexer Lexer::fromFile(const std::string &filepath, const context::Options options) { |
37 | | - std::ifstream fileStream(filepath); |
38 | | - if (!fileStream) { |
39 | | - optionsValue.logger.error({}, "IO error: could not open file ", filepath); |
| 35 | + std::ifstream inputFileStream(filepath); |
| 36 | + if (!inputFileStream) { |
| 37 | + options.logger.error({}, "IO error: could not open file ", filepath); |
40 | 38 | } |
41 | | - std::ostringstream stringStream; |
42 | | - stringStream << fileStream.rdbuf(); |
43 | | - return Lexer(filepath, stringStream.str(), options); |
| 39 | + std::ostringstream outputStringStream; |
| 40 | + outputStringStream << inputFileStream.rdbuf(); |
| 41 | + return Lexer(filepath, outputStringStream.str(), options); |
44 | 42 | } |
45 | 43 |
|
46 | 44 | Lexer Lexer::fromRepl(const std::string &source, const context::Options options) { |
47 | 45 | return Lexer("", source, options); |
48 | 46 | } |
49 | 47 |
|
50 | 48 | Lexer::Lexer(std::string filepath, std::string source, const context::Options options) : source(std::move(source)), |
51 | | - filepath(std::move(filepath)) { |
52 | | - optionsValue = options; |
| 49 | + filepath(std::move(filepath)), options(options) { |
53 | 50 | } |
54 | 51 |
|
55 | 52 | token::Token Lexer::nextToken() { |
@@ -105,7 +102,7 @@ namespace frontend { |
105 | 102 | } |
106 | 103 | const std::string value = source.substr(start, position - start); |
107 | 104 | if (currentCharacter != '"') { |
108 | | - optionsValue.logger.error(currentLocation, "syntax error: unbalanced quote"); |
| 105 | + options.logger.error(currentLocation, "syntax error: unbalanced quote"); |
109 | 106 | } |
110 | 107 | get(); // Consume '"'. |
111 | 108 | return {token::String{value}, currentLocation}; |
@@ -153,7 +150,7 @@ namespace frontend { |
153 | 150 | default: |
154 | 151 | break; |
155 | 152 | } |
156 | | - optionsValue.logger.error(currentLocation, "syntax error: unexpected character ", currentCharacter); |
| 153 | + options.logger.error(currentLocation, "syntax error: unexpected character ", currentCharacter); |
157 | 154 | } |
158 | 155 |
|
159 | 156 | std::vector<token::Token> Lexer::lex() { |
|
0 commit comments