private static bool DoExclude(ref StateContext context) { switch (context.Character) { case ',': context.Exclude(); context.State = State.None; break; case '}': context.Exclude(); context.Pop(); context.State = State.None; break; default: if (context.IsLetterOrDigitOrUnderscore()) { //如果首字符是数字,则激发错误 if (char.IsDigit(context.Character) && !context.HasBuffer()) { context.OnError("SyntaxError: The identifier of the data schema cannot start with a digit."); return(false); } //判断标识中间是否含有空白字符 if (context.Flags.HasWhitespace()) { context.OnError("SyntaxError: The identifier of the data schema contains whitespace characters."); return(false); } context.Accept(); } else if (!context.IsWhitespace()) { context.OnError($"SyntaxError: The identifier of the data schema contains '{context.Character}' illegal character."); return(false); } break; } //重置是否含有空格的标记 context.Flags.HasWhitespace(context.IsWhitespace()); return(true); }
private static bool DoExclude(ref StateContext context) { switch (context.Character) { case ',': context.Exclude(); context.State = State.None; break; case '}': context.Exclude(); context.Pop(); context.State = State.None; break; default: if (context.IsLetterOrDigitOrUnderscore()) { //如果首字符是数字,则激发错误 if (char.IsDigit(context.Character) && !context.HasBuffer()) { context.OnError(""); return(false); } //判断标识中间是否含有空白字符 if (context.Flags.HasWhitespace()) { context.OnError(""); return(false); } context.Accept(); } else if (!context.IsWhitespace()) { context.OnError(""); return(false); } break; } //重置是否含有空格的标记 context.Flags.HasWhitespace(context.IsWhitespace()); return(true); }
private static bool DoSortingField(ref StateContext context) { switch (context.Character) { case '~': case '!': if (context.HasBuffer()) { context.OnError("SyntaxError: Expected sorting field in the data schema, but missing."); return(false); } context.Accept(); return(true); case ',': if (context.AddSorting()) { context.State = State.SortingGutter; return(true); } return(false); case ')': if (context.AddSorting()) { context.State = State.Include; return(true); } return(false); default: if (context.IsLetterOrDigitOrUnderscore()) { context.Accept(); return(true); } context.OnError($"SyntaxError: The sorting field of the data schema contains '{context.Character}' illegal character."); return(false); } }
private static bool DoSortingField(ref StateContext context) { switch (context.Character) { case '~': case '!': if (context.HasBuffer()) { context.OnError(""); return(false); } context.Accept(); return(true); case ',': if (context.AddSorting()) { context.State = State.SortingGutter; return(true); } return(false); case ')': if (context.AddSorting()) { context.State = State.Include; return(true); } return(false); default: if (context.IsLetterOrDigitOrUnderscore()) { context.Accept(); return(true); } context.OnError(""); return(false); } }
private static bool DoPagingSize(ref StateContext context) { string buffer; switch (context.Character) { case '?': if (context.HasBuffer()) { context.OnError("SyntaxError: The pagination size format of the data schema is incorrect."); return(false); } context.Current.Paging.PageSize = 20; context.State = State.Include; return(true); case ',': if (!context.TryGetBuffer(out buffer)) { context.OnError("SyntaxError: Expected pagination size in the data schema, but missing."); return(false); } context.Current.Paging.PageSize = int.Parse(buffer); context.State = State.None; return(true); case '(': if (!context.TryGetBuffer(out buffer)) { context.OnError("SyntaxError: Expected pagination size in the data schema, but missing."); return(false); } if (buffer != "?") { context.Current.Paging.PageSize = int.Parse(buffer); } context.State = State.SortingField; return(true); case '{': if (!context.TryGetBuffer(out buffer)) { context.OnError("SyntaxError: Expected pagination size in the data schema, but missing."); return(false); } if (buffer != "?") { context.Current.Paging.PageSize = int.Parse(buffer); } context.Push(); context.State = State.None; return(true); default: if (char.IsDigit(context.Character)) { context.Accept(); return(true); } context.OnError($"SyntaxError: The pagination size of the data schema contains '{context.Character}' illegal character."); return(false); } }
private static bool DoPagingCount(ref StateContext context) { string buffer; switch (context.Character) { case '?': if (context.HasBuffer()) { context.OnError("SyntaxError: The pagination number format of the data schema is incorrect."); return(false); } context.Current.Paging = null; context.State = State.Include; return(true); case '*': if (context.HasBuffer()) { context.OnError("SyntaxError: The pagination number format of the data schema is incorrect."); return(false); } context.Current.Paging = Paging.Disabled; context.State = State.Include; return(true); case '/': if (!context.TryGetBuffer(out buffer)) { context.OnError("SyntaxError: Expected pagination number in the data schema, but missing."); return(false); } context.Current.Paging = Paging.Page(int.Parse(buffer)); context.State = State.PagingSize; return(true); case '(': if (!context.TryGetBuffer(out buffer)) { context.OnError("SyntaxError: Expected pagination number in the data schema, but missing."); return(false); } context.Current.Paging = Paging.Page(1, int.Parse(buffer)); context.State = State.SortingField; return(true); case '{': if (!context.TryGetBuffer(out buffer)) { context.OnError("SyntaxError: Expected pagination number in the data schema, but missing."); return(false); } context.Current.Paging = Paging.Page(1, int.Parse(buffer)); context.Push(); context.State = State.None; return(true); default: if (char.IsDigit(context.Character)) { context.Accept(); return(true); } context.OnError($"SyntaxError: The pagination number of the data schema contains '{context.Character}' illegal character."); return(false); } }
private static bool DoPagingSize(ref StateContext context) { string buffer; switch (context.Character) { case '?': if (context.HasBuffer()) { context.OnError(""); return(false); } context.Current.Paging.PageSize = 20; context.State = State.Include; return(true); case ',': if (!context.TryGetBuffer(out buffer)) { context.OnError(""); return(false); } context.Current.Paging.PageSize = int.Parse(buffer); context.State = State.None; return(true); case '(': if (!context.TryGetBuffer(out buffer)) { context.OnError(""); return(false); } if (buffer != "?") { context.Current.Paging.PageSize = int.Parse(buffer); } context.State = State.SortingField; return(true); case '{': if (!context.TryGetBuffer(out buffer)) { context.OnError(""); return(false); } if (buffer != "?") { context.Current.Paging.PageSize = int.Parse(buffer); } context.Push(); context.State = State.None; return(true); default: if (char.IsDigit(context.Character)) { context.Accept(); return(true); } context.OnError(""); return(false); } }
private static bool DoPagingCount(ref StateContext context) { string buffer; switch (context.Character) { case '?': if (context.HasBuffer()) { context.OnError(""); return(false); } context.Current.Paging = null; context.State = State.Include; return(true); case '*': if (context.HasBuffer()) { context.OnError(""); return(false); } context.Current.Paging = Paging.Disable; context.State = State.Include; return(true); case '/': if (!context.TryGetBuffer(out buffer)) { context.OnError(""); return(false); } context.Current.Paging = Paging.Page(int.Parse(buffer)); context.State = State.PagingSize; return(true); case '(': if (!context.TryGetBuffer(out buffer)) { context.OnError(""); return(false); } context.Current.Paging = Paging.Page(1, int.Parse(buffer)); context.State = State.SortingField; return(true); case '{': if (!context.TryGetBuffer(out buffer)) { context.OnError(""); return(false); } context.Current.Paging = Paging.Page(1, int.Parse(buffer)); context.Push(); context.State = State.None; return(true); default: if (char.IsDigit(context.Character)) { context.Accept(); return(true); } context.OnError(""); return(false); } }