1 /* 2 * Copyright (c) 2025 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 ******************** This file was generated by sksllex. Do not edit. ******************* 17 *****************************************************************************************/ 18 #ifndef SKSL_Lexer 19 #define SKSL_Lexer 20 #include "include/core/SkStringView.h" 21 #include <cstddef> 22 #include <cstdint> 23 namespace SkSL { 24 25 struct Token { 26 enum class Kind { 27 TK_END_OF_FILE, 28 TK_FLOAT_LITERAL, 29 TK_INT_LITERAL, 30 TK_TRUE_LITERAL, 31 TK_FALSE_LITERAL, 32 TK_IF, 33 TK_STATIC_IF, 34 TK_ELSE, 35 TK_FOR, 36 TK_WHILE, 37 TK_DO, 38 TK_SWITCH, 39 TK_STATIC_SWITCH, 40 TK_CASE, 41 TK_DEFAULT, 42 TK_BREAK, 43 TK_CONTINUE, 44 TK_DISCARD, 45 TK_RETURN, 46 TK_IN, 47 TK_OUT, 48 TK_INOUT, 49 TK_UNIFORM, 50 TK_CONST, 51 TK_FLAT, 52 TK_NOPERSPECTIVE, 53 TK_INLINE, 54 TK_NOINLINE, 55 TK_HASSIDEEFFECTS, 56 TK_READONLY, 57 TK_WRITEONLY, 58 TK_BUFFER, 59 TK_STRUCT, 60 TK_LAYOUT, 61 TK_HIGHP, 62 TK_MEDIUMP, 63 TK_LOWP, 64 TK_ES3, 65 TK_RESERVED, 66 TK_IDENTIFIER, 67 TK_DIRECTIVE, 68 TK_LPAREN, 69 TK_RPAREN, 70 TK_LBRACE, 71 TK_RBRACE, 72 TK_LBRACKET, 73 TK_RBRACKET, 74 TK_DOT, 75 TK_COMMA, 76 TK_PLUSPLUS, 77 TK_MINUSMINUS, 78 TK_PLUS, 79 TK_MINUS, 80 TK_STAR, 81 TK_SLASH, 82 TK_PERCENT, 83 TK_SHL, 84 TK_SHR, 85 TK_BITWISEOR, 86 TK_BITWISEXOR, 87 TK_BITWISEAND, 88 TK_BITWISENOT, 89 TK_LOGICALOR, 90 TK_LOGICALXOR, 91 TK_LOGICALAND, 92 TK_LOGICALNOT, 93 TK_QUESTION, 94 TK_COLON, 95 TK_EQ, 96 TK_EQEQ, 97 TK_NEQ, 98 TK_GT, 99 TK_LT, 100 TK_GTEQ, 101 TK_LTEQ, 102 TK_PLUSEQ, 103 TK_MINUSEQ, 104 TK_STAREQ, 105 TK_SLASHEQ, 106 TK_PERCENTEQ, 107 TK_SHLEQ, 108 TK_SHREQ, 109 TK_BITWISEOREQ, 110 TK_BITWISEXOREQ, 111 TK_BITWISEANDEQ, 112 TK_SEMICOLON, 113 TK_ARROW, 114 TK_WHITESPACE, 115 TK_LINE_COMMENT, 116 TK_BLOCK_COMMENT, 117 TK_INVALID, 118 TK_NONE, 119 }; 120 TokenToken121 Token() {}Token(Kind kind, int32_t offset, int32_t length, int32_t line) 122 : fKind(kind) 123 , fOffset(offset) 124 , fLength(length) 125 , fLine(line) {} 126 127 Kind fKind = Kind::TK_NONE; 128 int32_t fOffset = -1; 129 int32_t fLength = -1; 130 int32_t fLine = -1; 131 }; 132 133 class Lexer { 134 public: start(skstd::string_view text)135 void start(skstd::string_view text) { 136 fText = text; 137 fOffset = 0; 138 fLine = 1; 139 } 140 141 Token next(); 142 143 struct Checkpoint { 144 int32_t fOffset; 145 int32_t fLine; 146 }; 147 getCheckpoint()148 Checkpoint getCheckpoint() const { 149 return {fOffset, fLine}; 150 } 151 rewindToCheckpoint(Checkpoint checkpoint)152 void rewindToCheckpoint(Checkpoint checkpoint) { 153 fOffset = checkpoint.fOffset; 154 fLine = checkpoint.fLine; 155 } 156 157 private: 158 skstd::string_view fText; 159 int32_t fOffset; 160 int32_t fLine; 161 }; 162 163 } // namespace 164 #endif 165