1/** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// Autogenerated file -- DO NOT EDIT! 17 18#include <gen/keywordsMap.h> 19#include <lexer/keywordsUtil.h> 20#include <lexer/token/letters.h> 21#include <macros.h> 22#include <utils/span.h> 23 24namespace panda::es2panda::lexer { 25 26class Keywords { 27public: 28 explicit Keywords(Lexer* lexer, lexer::LexerNextTokenFlags flags) : util_(KeywordsUtil(lexer, flags)) {} 29 NO_COPY_SEMANTIC(Keywords); 30 NO_MOVE_SEMANTIC(Keywords); 31 ~Keywords() = default; 32 33 KeywordsUtil &Util() { 34 return util_; 35 } 36 37 // NOLINTNEXTLINE(readability-function-size) 38 static void SetKeyword(KeywordsUtil *util, const KeywordString& kws) { 39 switch(kws.keywordType) { 40% keywords.each do |group| 41% group.each do |key, kw| 42 case <%= kw[1] %>: { 43 return util->SetKeyword<<%= kw[1] %>>(kws.str, kws.tokenType); 44 } 45% end 46% end 47 default: { 48 break; 49 } 50 } 51 } 52 53% functions.each do |key, prefixes| 54 inline void Scan<%= key.upcase %>() 55 { 56 switch(util_.Iterator().Peek()) { 57% prefixes.select{|p| !p.nil? }.each do |prefix| 58 case LEX_CHAR_LOWERCASE_<%=prefix.upcase%>: /* '<%=prefix%>' */ { 59 util_.Iterator().Forward(1); 60 Scan<%= key.upcase %><%= prefix.upcase %>(); 61 return; 62 } 63% end 64% if prefixes.include?(nil) 65% kw = keywords.find{ |x| x.has_key?(key)}[key] 66 default: { 67 if (!KeywordsUtil::IsIdentifierPart(util_.Iterator().PeekCp())) { 68 util_.SetKeyword<<%=kw[1]%>>("<%=key%>", <%=kw[0]%>); 69 return; 70 } 71 break; 72 } 73 } 74% else 75 default: { 76 break; 77 } 78 } 79% end 80 util_.ScanIdContinueMaybeKeyword(Span<const KeywordString>(KeywordsMap::KEYWORDS_<%= key[0].upcase %>)); 81 } 82 83% end 84 85private: 86 KeywordsUtil util_; 87}; 88 89} // namespace panda::es2panda::lexer 90