diff --git a/src/Carbunql.LexicalAnalyzer/Lexer.Expression.cs b/src/Carbunql.LexicalAnalyzer/Lexer.Expression.cs index 6a8162c8..9fc3fc98 100644 --- a/src/Carbunql.LexicalAnalyzer/Lexer.Expression.cs +++ b/src/Carbunql.LexicalAnalyzer/Lexer.Expression.cs @@ -74,7 +74,6 @@ public static IEnumerable ReadExpressionLexes(ReadOnlyMemory memory, continue; } - // alias, expression separator, or 'from' keyword break; } diff --git a/src/Carbunql.LexicalAnalyzer/Lexer.Value.CharactorValue.cs b/src/Carbunql.LexicalAnalyzer/Lexer.Value.CharactorValue.cs index ee34b324..3aa8cd4c 100644 --- a/src/Carbunql.LexicalAnalyzer/Lexer.Value.CharactorValue.cs +++ b/src/Carbunql.LexicalAnalyzer/Lexer.Value.CharactorValue.cs @@ -1,22 +1,30 @@ -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace Carbunql.LexicalAnalyzer; public static partial class Lexer { - /// - /// Defines a set of characters considered as symbols that terminate an identifier. - /// - //internal static readonly HashSet Symbols = new HashSet - //{ - // '+', '-', '*', '/', '%', // Arithmetic operators - // '(', ')', '[', ']', '{', '}', // Brackets and braces - // '~', '@', '#', '$', '^', '&', // Special symbols - // '!', '?', ':', ';', ',', '.', '<', '>', '=', '|', '\\', // Other symbols - // '`', '"', '\'' // Quotation marks - //}; - + private static HashSet SpecialValueWords = new HashSet + { + "true", + "false", + "null", + + "current_timestamp", + "current_date", + "current_time", + "timestamp", + "now", + + "yesterday", + "today", + "tomorrow", + + "-infinity", + "infinity", + "allballs", + "epoch", + }; [MemberNotNullWhen(true)] public static bool TryParseCharactorValue(ReadOnlyMemory memory, int start, out Lex lex, out int endPosition) @@ -41,9 +49,9 @@ public static bool TryParseCharactorValue(ReadOnlyMemory memory, int start // Special word (e.g. true, false, null, timestamp) foreach (var keyword in SpecialValueWords.Where(x => x.Length == length)) { - if (memory.EqualsWordIgnoreCase(position, keyword, out position)) + if (memory.EqualsWordIgnoreCase(start, keyword, out _)) { - lex = new Lex(memory, LexType.Type, start, position - start); + lex = new Lex(memory, LexType.Value, start, position - start); endPosition = position; return true; } @@ -83,89 +91,6 @@ public static bool TryParseCharactorValue(ReadOnlyMemory memory, int start return true; } - - [MemberNotNullWhen(true)] - private static bool TryParseCharactorValues(ReadOnlyMemory memory, int position, out IEnumerable lexes) - { - lexes = Enumerable.Empty(); - var start = position; - - if (TryGetCharacterEndPosition(memory, position, out _)) - { - lexes = ParseCharactorValues(memory, position); - return true; - } - return false; - } - - [MemberNotNullWhen(true)] - private static IEnumerable ParseCharactorValues(ReadOnlyMemory memory, int position) - { - var start = position; - - if (!TryGetCharacterEndPosition(memory, position, out position)) - { - throw new FormatException(); - } - - // check next charactor - if (memory.IsAtEndOrWhiteSpace(position)) - { - if (IsSpacialValueWord(memory, start, position - start)) - { - yield return new Lex(memory, LexType.Value, start, position - start); - } - - yield return new Lex(memory, LexType.Column, start, position - start); - yield break; - } - - // Identifier separator - if (memory.EqualsChar(position, '.', out _)) - { - yield return new Lex(memory, LexType.Namespace, start, position - start); - - position++;//skip comma - start = position; - while (TryGetCharacterEndPosition(memory, position, out position)) - { - if (memory.EqualsChar(position, '.', out _)) - { - yield return new Lex(memory, LexType.Namespace, start, position - start); - position++;//skip comma - start = position; - continue; - } - else - { - yield return new Lex(memory, LexType.Column, start, position - start); - yield break; - } - } - throw new FormatException(); - } - - // left paren - if (memory.EqualsChar(position, '(', out _)) - { - yield return new Lex(memory, LexType.Function, start, position - start); - yield break; - } - - // mulitiword - - - // other - if (IsSpacialValueWord(memory, start, position - start)) - { - yield return new Lex(memory, LexType.Value, start, position - start); - yield break; - } - - yield return new Lex(memory, LexType.Column, start, position - start); - yield break; - } - /// /// Attempts to find the end position of a valid identifier starting at a given position in the specified memory segment. /// diff --git a/src/Carbunql.LexicalAnalyzer/Lexer.Value.SpecialValue.cs b/src/Carbunql.LexicalAnalyzer/Lexer.Value.SpecialValue.cs deleted file mode 100644 index 51cb00dc..00000000 --- a/src/Carbunql.LexicalAnalyzer/Lexer.Value.SpecialValue.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace Carbunql.LexicalAnalyzer; - -public static partial class Lexer -{ - private static HashSet SpecialValueWords = new HashSet - { - "true", - "false", - "null", - - "current_timestamp", - "current_date", - "current_time", - "timestamp", - "now", - - "yesterday", - "today", - "tomorrow", - - "-infinity", - "infinity", - "allballs", - "epoch", - }; - - private static bool IsSpacialValueWord(ReadOnlyMemory memory, in int position, int length) - { - foreach (var keyword in SpecialValueWords.Where(x => x.Length == length)) - { - if (MemoryEqualsIgnoreCase(memory, position, keyword)) - { - return true; - } - } - return false; - } -}