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