Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / Lexer.h
diff options
context:
space:
mode:
1 files changed, 134 insertions, 0 deletions
-rw-r--r--JSImpl/src/Lexer.h134
diff --git a/JSImpl/src/Lexer.h b/JSImpl/src/Lexer.h
new file mode 100644
index 0000000..00acc7a
--- /dev/null
+++ b/JSImpl/src/Lexer.h
@@ -0,0 +1,134 @@
+#pragma once
+
+#include "CommonTypes.h"
+
+enum class TokenType
+{
+ // Single-character tokens.
+ LeftParen,
+ RightParen,
+ LeftBrace,
+ RightBrace,
+ Comma,
+ Dot,
+ Minus,
+ Plus,
+ Semicolon,
+ Star,
+ Division,
+ Modulo,
+ BitwiseNot,
+ BitwiseAnd,
+ BitwiseXor,
+ BitwiseOr,
+ QuestionMark,
+ Colon,
+ LeftSquareBracket,
+ RightSquareBracket,
+
+ // One or two character tokens
+ Bang,
+ BangEqual,
+ Equal,
+ EqualEqual,
+ StrictEqual,
+ StrictNotEqual,
+ Greater,
+ GreaterEqual,
+ Less,
+ LessEqual,
+ MinusMinus,
+ PlusPlus,
+ LeftShift,
+ RightShift,
+ LogicalAnd,
+ LogicalOr,
+ StarEqual,
+ DivideEqual,
+ ModuloEqual,
+ PlusEqual,
+ MinusEqual,
+ LeftShiftEqual,
+ RightShiftEqual,
+ BitwiseAndEqual,
+ BitwiseXorEqual,
+ BitwiseOrEqual,
+ Backslash,
+
+ Identifier,
+ String,
+ Number,
+
+ // Keywords. ECMAScript 2015
+ Break,
+ Case,
+ Catch,
+ Class,
+ Const,
+ Continue,
+ Debugger,
+ Default,
+ Delete,
+ Do,
+ Else,
+ Export,
+ Extends,
+ Finally,
+ For,
+ Function,
+ If,
+ Import,
+ In,
+ Instanceof,
+ New,
+ Return,
+ Super,
+ Switch,
+ This,
+ Throw,
+ Try,
+ Typeof,
+ Var,
+ Let,
+ Void,
+ While,
+ With,
+ Yield,
+ Null,
+ Undefined,
+ True,
+ False,
+
+ Whitespace,
+ Tab,
+ NewLine,
+ Comment,
+
+ Eof,
+ Invalid
+};
+
+struct Token
+{
+ TokenType Type;
+ unsigned Line;
+ unsigned Column;
+ IPLString Lexeme;
+ double Number;
+};
+
+struct LexerResult
+{
+ bool IsSuccessful;
+ IPLError Error;
+ IPLVector<Token> tokens;
+};
+
+struct LexerSettings
+{
+ bool CreateWhitespaceTokens;
+ bool CreateCommentTokens;
+};
+
+LexerResult Tokenize(const char* code, const LexerSettings& settings);
+LexerResult Tokenize(const char* code); \ No newline at end of file