1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "banjo/identifier_table.h"
6 
7 #include "banjo/source_location.h"
8 
9 namespace banjo {
10 
IdentifierTable()11 IdentifierTable::IdentifierTable() {
12     keyword_table_ = {
13 #define KEYWORD(Name, Spelling) {Spelling, Token::Subkind::k##Name},
14 #include "banjo/token_definitions.inc"
15     };
16 }
17 
MakeIdentifier(SourceLocation previous_end,StringView source_data,const SourceFile & source_file,bool escaped_identifier) const18 Token IdentifierTable::MakeIdentifier(SourceLocation previous_end, StringView source_data, const SourceFile& source_file,
19                                       bool escaped_identifier) const {
20     auto subkind = Token::Subkind::kNone;
21     if (!escaped_identifier) {
22         auto lookup = keyword_table_.find(source_data);
23         if (lookup != keyword_table_.end())
24             subkind = lookup->second;
25     }
26     return Token(previous_end, SourceLocation(source_data, source_file), Token::Kind::kIdentifier, subkind);
27 }
28 
29 } // namespace banjo
30