forked from carbon-language/carbon-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lex_scan_helper.h
58 lines (46 loc) · 2.02 KB
/
lex_scan_helper.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
47
48
49
50
51
52
53
54
55
56
57
58
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_EXPLORER_SYNTAX_LEX_SCAN_HELPER_H_
#define CARBON_EXPLORER_SYNTAX_LEX_SCAN_HELPER_H_
#include <string>
#include "explorer/syntax/parse_and_lex_context.h"
#include "explorer/syntax/parser.h"
// Exposes yyinput; defined in lexer.lpp.
extern auto YyinputWrapper(yyscan_t yyscanner) -> int;
namespace Carbon {
class StringLexHelper {
public:
StringLexHelper(const char* text, yyscan_t yyscanner,
Carbon::ParseAndLexContext& context)
: str_(text), yyscanner_(yyscanner), context_(context), is_eof_(false) {}
// Advances yyscanner by one char. Sets is_eof to true and returns false on
// EOF.
auto Advance() -> bool;
// Returns the last scanned char.
auto last_char() -> char { return str_.back(); };
// Returns the scanned string.
auto str() -> const std::string& { return str_; };
auto is_eof() -> bool { return is_eof_; };
private:
std::string str_;
yyscan_t yyscanner_;
Carbon::ParseAndLexContext& context_;
// Skips reading next char.
bool is_eof_;
};
// Tries to Read `hashtag_num` hashtags. Returns true on success.
// Reads `hashtag_num` characters on success, and number of consecutive hashtags
// (< `hashtag_num`) + 1 characters on failure.
auto ReadHashTags(Carbon::StringLexHelper& scan_helper, size_t hashtag_num)
-> bool;
// Removes quotes and escapes a single line string. Reports an error on
// invalid escaping.
auto ProcessSingleLineString(llvm::StringRef str,
Carbon::ParseAndLexContext& context,
size_t hashtag_num) -> Carbon::Parser::symbol_type;
auto ProcessMultiLineString(llvm::StringRef str,
Carbon::ParseAndLexContext& context,
size_t hashtag_num) -> Carbon::Parser::symbol_type;
} // namespace Carbon
#endif // CARBON_EXPLORER_SYNTAX_LEX_SCAN_HELPER_H_