feat(lexer): extend Lexer and Token
This commit is contained in:
1 parent
bff836d5b9
commit
cfabe95271
2 files changed
+104
-5
No files matched your search
Binary file not shown.
@@ -3,14 +3,28 @@ package kestrel.sql.lexer
|
|||||||
enum class TokenType {
|
enum class TokenType {
|
||||||
Identifier, IntLiteral, RealLiteral, TextLiteral,
|
Identifier, IntLiteral, RealLiteral, TextLiteral,
|
||||||
Create, Table, Insert, Into, Values, Select, From, Where,
|
Create, Table, Insert, Into, Values, Select, From, Where,
|
||||||
Order, By, Asc, Desc, Limit, Delete, Update, Set, Drop,
|
Order, By, Asc, Desc, Limit, Offset, Delete, Update, Set, Drop, Truncate, Identity, Continue,
|
||||||
|
Alter, Add, Column, Rename, To, Default,
|
||||||
And, Or, Not, Null, True, False, Primary, Key, As,
|
And, Or, Not, Null, True, False, Primary, Key, As,
|
||||||
Index, On, Inner, Left, Outer, Join, Group, Having,
|
Index, On, Inner, Left, Right, Full, Cross, Outer, Join, Lateral, Group, Having, Over, Partition,
|
||||||
Begin, Commit, Rollback, Transaction, Explain,
|
Rows, Row, Range, Groups, Preceding, Following, Unbounded, Current, Exclude, Ties, Others,
|
||||||
Integer, Text, Boolean, Real,
|
Begin, Commit, Rollback, Transaction, Explain, Savepoint, Release,
|
||||||
|
Conflict, Nothing, Do, Returning,
|
||||||
|
Trigger, Before, After, For, Each,
|
||||||
|
Is, In, Between, Like, Case, When, Then, Else, End, Exists, View, Replace,
|
||||||
|
Union, All, Intersect, Except, With, Recursive, Distinct,
|
||||||
|
Cast, Cascade, Restrict, References, Foreign, Check, No, Action, Unique, Constraint,
|
||||||
|
Sequence, Increment, Minvalue, Maxvalue, Start, Cycle, Restart,
|
||||||
|
Merge, Using, Matched,
|
||||||
|
Prepare, Execute, Deallocate,
|
||||||
|
Temp, Temporary,
|
||||||
|
Collate,
|
||||||
|
Integer, Text, Boolean, Real, Decimal, Date,
|
||||||
Equal, NotEqual, Less, LessEqual, Greater, GreaterEqual,
|
Equal, NotEqual, Less, LessEqual, Greater, GreaterEqual,
|
||||||
Plus, Minus, Star, Slash, Dot,
|
Plus, Minus, Star, Slash, Dot,
|
||||||
LeftParen, RightParen, Comma, Semicolon,
|
LeftParen, RightParen, Comma, Semicolon,
|
||||||
|
/** `$1`, `$2`, ... - see [kestrel.sql.ast.ParameterExpression]. [Token.intValue] carries the 1-based index. */
|
||||||
|
Parameter,
|
||||||
EndOfInput
|
EndOfInput
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,10 +52,20 @@ internal val keywords: Map<String, TokenType> = mapOf(
|
|||||||
"ASC" to TokenType.Asc,
|
"ASC" to TokenType.Asc,
|
||||||
"DESC" to TokenType.Desc,
|
"DESC" to TokenType.Desc,
|
||||||
"LIMIT" to TokenType.Limit,
|
"LIMIT" to TokenType.Limit,
|
||||||
|
"OFFSET" to TokenType.Offset,
|
||||||
"DELETE" to TokenType.Delete,
|
"DELETE" to TokenType.Delete,
|
||||||
"UPDATE" to TokenType.Update,
|
"UPDATE" to TokenType.Update,
|
||||||
"SET" to TokenType.Set,
|
"SET" to TokenType.Set,
|
||||||
"DROP" to TokenType.Drop,
|
"DROP" to TokenType.Drop,
|
||||||
|
"TRUNCATE" to TokenType.Truncate,
|
||||||
|
"IDENTITY" to TokenType.Identity,
|
||||||
|
"CONTINUE" to TokenType.Continue,
|
||||||
|
"ALTER" to TokenType.Alter,
|
||||||
|
"ADD" to TokenType.Add,
|
||||||
|
"COLUMN" to TokenType.Column,
|
||||||
|
"RENAME" to TokenType.Rename,
|
||||||
|
"TO" to TokenType.To,
|
||||||
|
"DEFAULT" to TokenType.Default,
|
||||||
"AND" to TokenType.And,
|
"AND" to TokenType.And,
|
||||||
"OR" to TokenType.Or,
|
"OR" to TokenType.Or,
|
||||||
"NOT" to TokenType.Not,
|
"NOT" to TokenType.Not,
|
||||||
@@ -55,17 +79,92 @@ internal val keywords: Map<String, TokenType> = mapOf(
|
|||||||
"ON" to TokenType.On,
|
"ON" to TokenType.On,
|
||||||
"INNER" to TokenType.Inner,
|
"INNER" to TokenType.Inner,
|
||||||
"LEFT" to TokenType.Left,
|
"LEFT" to TokenType.Left,
|
||||||
|
"RIGHT" to TokenType.Right,
|
||||||
|
"FULL" to TokenType.Full,
|
||||||
|
"CROSS" to TokenType.Cross,
|
||||||
"OUTER" to TokenType.Outer,
|
"OUTER" to TokenType.Outer,
|
||||||
"JOIN" to TokenType.Join,
|
"JOIN" to TokenType.Join,
|
||||||
|
"LATERAL" to TokenType.Lateral,
|
||||||
"GROUP" to TokenType.Group,
|
"GROUP" to TokenType.Group,
|
||||||
"HAVING" to TokenType.Having,
|
"HAVING" to TokenType.Having,
|
||||||
|
"OVER" to TokenType.Over,
|
||||||
|
"PARTITION" to TokenType.Partition,
|
||||||
|
"ROWS" to TokenType.Rows,
|
||||||
|
"ROW" to TokenType.Row,
|
||||||
|
"RANGE" to TokenType.Range,
|
||||||
|
"GROUPS" to TokenType.Groups,
|
||||||
|
"PRECEDING" to TokenType.Preceding,
|
||||||
|
"FOLLOWING" to TokenType.Following,
|
||||||
|
"UNBOUNDED" to TokenType.Unbounded,
|
||||||
|
"CURRENT" to TokenType.Current,
|
||||||
|
"EXCLUDE" to TokenType.Exclude,
|
||||||
|
"TIES" to TokenType.Ties,
|
||||||
|
"OTHERS" to TokenType.Others,
|
||||||
"BEGIN" to TokenType.Begin,
|
"BEGIN" to TokenType.Begin,
|
||||||
"COMMIT" to TokenType.Commit,
|
"COMMIT" to TokenType.Commit,
|
||||||
"ROLLBACK" to TokenType.Rollback,
|
"ROLLBACK" to TokenType.Rollback,
|
||||||
"TRANSACTION" to TokenType.Transaction,
|
"TRANSACTION" to TokenType.Transaction,
|
||||||
"EXPLAIN" to TokenType.Explain,
|
"EXPLAIN" to TokenType.Explain,
|
||||||
|
"SAVEPOINT" to TokenType.Savepoint,
|
||||||
|
"RELEASE" to TokenType.Release,
|
||||||
|
"CONFLICT" to TokenType.Conflict,
|
||||||
|
"NOTHING" to TokenType.Nothing,
|
||||||
|
"DO" to TokenType.Do,
|
||||||
|
"RETURNING" to TokenType.Returning,
|
||||||
|
"TRIGGER" to TokenType.Trigger,
|
||||||
|
"BEFORE" to TokenType.Before,
|
||||||
|
"AFTER" to TokenType.After,
|
||||||
|
"FOR" to TokenType.For,
|
||||||
|
"EACH" to TokenType.Each,
|
||||||
"INTEGER" to TokenType.Integer,
|
"INTEGER" to TokenType.Integer,
|
||||||
"TEXT" to TokenType.Text,
|
"TEXT" to TokenType.Text,
|
||||||
"BOOLEAN" to TokenType.Boolean,
|
"BOOLEAN" to TokenType.Boolean,
|
||||||
"REAL" to TokenType.Real
|
"REAL" to TokenType.Real,
|
||||||
|
"IS" to TokenType.Is,
|
||||||
|
"IN" to TokenType.In,
|
||||||
|
"BETWEEN" to TokenType.Between,
|
||||||
|
"LIKE" to TokenType.Like,
|
||||||
|
"CASE" to TokenType.Case,
|
||||||
|
"WHEN" to TokenType.When,
|
||||||
|
"THEN" to TokenType.Then,
|
||||||
|
"ELSE" to TokenType.Else,
|
||||||
|
"END" to TokenType.End,
|
||||||
|
"EXISTS" to TokenType.Exists,
|
||||||
|
"VIEW" to TokenType.View,
|
||||||
|
"REPLACE" to TokenType.Replace,
|
||||||
|
"UNION" to TokenType.Union,
|
||||||
|
"ALL" to TokenType.All,
|
||||||
|
"INTERSECT" to TokenType.Intersect,
|
||||||
|
"EXCEPT" to TokenType.Except,
|
||||||
|
"WITH" to TokenType.With,
|
||||||
|
"RECURSIVE" to TokenType.Recursive,
|
||||||
|
"DISTINCT" to TokenType.Distinct,
|
||||||
|
"CAST" to TokenType.Cast,
|
||||||
|
"CASCADE" to TokenType.Cascade,
|
||||||
|
"RESTRICT" to TokenType.Restrict,
|
||||||
|
"DECIMAL" to TokenType.Decimal,
|
||||||
|
"DATE" to TokenType.Date,
|
||||||
|
"REFERENCES" to TokenType.References,
|
||||||
|
"FOREIGN" to TokenType.Foreign,
|
||||||
|
"CHECK" to TokenType.Check,
|
||||||
|
"NO" to TokenType.No,
|
||||||
|
"ACTION" to TokenType.Action,
|
||||||
|
"UNIQUE" to TokenType.Unique,
|
||||||
|
"CONSTRAINT" to TokenType.Constraint,
|
||||||
|
"SEQUENCE" to TokenType.Sequence,
|
||||||
|
"INCREMENT" to TokenType.Increment,
|
||||||
|
"MINVALUE" to TokenType.Minvalue,
|
||||||
|
"MAXVALUE" to TokenType.Maxvalue,
|
||||||
|
"START" to TokenType.Start,
|
||||||
|
"CYCLE" to TokenType.Cycle,
|
||||||
|
"RESTART" to TokenType.Restart,
|
||||||
|
"MERGE" to TokenType.Merge,
|
||||||
|
"USING" to TokenType.Using,
|
||||||
|
"MATCHED" to TokenType.Matched,
|
||||||
|
"PREPARE" to TokenType.Prepare,
|
||||||
|
"EXECUTE" to TokenType.Execute,
|
||||||
|
"DEALLOCATE" to TokenType.Deallocate,
|
||||||
|
"TEMP" to TokenType.Temp,
|
||||||
|
"TEMPORARY" to TokenType.Temporary,
|
||||||
|
"COLLATE" to TokenType.Collate
|
||||||
)
|
)
|
||||||
Reference in new issue
Block a user