blob: 2c150bfa59c259b5e2696981479d850743577f4a [file] [log] [blame]
Ethan Nicholas5b5f0962017-09-11 13:50:14 -07001/*
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>
Ethan Nicholas6823b502021-06-15 11:42:07 -040014#include "include/core/SkStringView.h"
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070015namespace SkSL {
16
17struct Token {
Ethan Nicholas5a9e7fb2020-04-17 12:45:51 -040018 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,
Ethan Nicholas5a9e7fb2020-04-17 12:45:51 -040038 TK_IN,
39 TK_OUT,
40 TK_INOUT,
41 TK_UNIFORM,
42 TK_CONST,
43 TK_FLAT,
44 TK_NOPERSPECTIVE,
Ethan Nicholasf3c8f5d2020-08-20 13:09:14 +000045 TK_INLINE,
John Stiles0dd1a772021-03-09 22:14:27 -050046 TK_NOINLINE,
Ethan Nicholas5a9e7fb2020-04-17 12:45:51 -040047 TK_HASSIDEEFFECTS,
Ethan Nicholas5a9e7fb2020-04-17 12:45:51 -040048 TK_STRUCT,
49 TK_LAYOUT,
John Stilesb6a73192021-07-20 15:32:21 -040050 TK_HIGHP,
51 TK_MEDIUMP,
52 TK_LOWP,
John Stiles44899a22021-08-12 23:05:50 -040053 TK_ES3,
Ethan Nicholas5a9e7fb2020-04-17 12:45:51 -040054 TK_IDENTIFIER,
55 TK_DIRECTIVE,
Ethan Nicholas5a9e7fb2020-04-17 12:45:51 -040056 TK_LPAREN,
57 TK_RPAREN,
58 TK_LBRACE,
59 TK_RBRACE,
60 TK_LBRACKET,
61 TK_RBRACKET,
62 TK_DOT,
63 TK_COMMA,
64 TK_PLUSPLUS,
65 TK_MINUSMINUS,
66 TK_PLUS,
67 TK_MINUS,
68 TK_STAR,
69 TK_SLASH,
70 TK_PERCENT,
71 TK_SHL,
72 TK_SHR,
73 TK_BITWISEOR,
74 TK_BITWISEXOR,
75 TK_BITWISEAND,
76 TK_BITWISENOT,
77 TK_LOGICALOR,
78 TK_LOGICALXOR,
79 TK_LOGICALAND,
80 TK_LOGICALNOT,
81 TK_QUESTION,
Ethan Nicholas5a9e7fb2020-04-17 12:45:51 -040082 TK_COLON,
83 TK_EQ,
84 TK_EQEQ,
85 TK_NEQ,
86 TK_GT,
87 TK_LT,
88 TK_GTEQ,
89 TK_LTEQ,
90 TK_PLUSEQ,
91 TK_MINUSEQ,
92 TK_STAREQ,
93 TK_SLASHEQ,
94 TK_PERCENTEQ,
95 TK_SHLEQ,
96 TK_SHREQ,
97 TK_BITWISEOREQ,
98 TK_BITWISEXOREQ,
99 TK_BITWISEANDEQ,
Ethan Nicholas5a9e7fb2020-04-17 12:45:51 -0400100 TK_SEMICOLON,
101 TK_ARROW,
102 TK_WHITESPACE,
103 TK_LINE_COMMENT,
104 TK_BLOCK_COMMENT,
105 TK_INVALID,
John Stiles7cbb09c22021-01-07 16:07:00 -0500106 TK_NONE,
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700107 };
108
Ethan Nicholas5fad2b82021-09-27 10:39:18 -0400109 Token() {}
110 Token(Kind kind, int32_t offset, int32_t length, int32_t line)
111 : fKind(kind), fOffset(offset), fLength(length), fLine(line) {}
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700112
Ethan Nicholas5fad2b82021-09-27 10:39:18 -0400113 Kind fKind = Kind::TK_NONE;
114 int32_t fOffset = -1;
115 int32_t fLength = -1;
116 int32_t fLine = -1;
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700117};
118
119class Lexer {
120public:
Ethan Nicholas6823b502021-06-15 11:42:07 -0400121 void start(skstd::string_view text) {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700122 fText = text;
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700123 fOffset = 0;
Ethan Nicholas5fad2b82021-09-27 10:39:18 -0400124 fLine = 1;
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700125 }
126
127 Token next();
128
Ethan Nicholas5fad2b82021-09-27 10:39:18 -0400129 struct Checkpoint {
130 int32_t fOffset;
131 int32_t fLine;
132 };
John Stilescc6961b2021-01-22 09:49:45 -0500133
Ethan Nicholas5fad2b82021-09-27 10:39:18 -0400134 Checkpoint getCheckpoint() const { return {fOffset, fLine}; }
135
136 void rewindToCheckpoint(Checkpoint checkpoint) {
137 fOffset = checkpoint.fOffset;
138 fLine = checkpoint.fLine;
139 }
John Stilescc6961b2021-01-22 09:49:45 -0500140
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700141private:
Ethan Nicholas6823b502021-06-15 11:42:07 -0400142 skstd::string_view fText;
Ethan Nicholasc7735f12018-08-03 11:48:20 -0400143 int32_t fOffset;
Ethan Nicholas5fad2b82021-09-27 10:39:18 -0400144 int32_t fLine;
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700145};
146
Brian Osman3c358422020-03-23 10:44:12 -0400147} // namespace SkSL
Ethan Nicholas5b5f0962017-09-11 13:50:14 -0700148#endif