/// <summary>nothing has been pre-consumed</summary> /// <returns>null if there is no order by</returns> /// <exception cref="System.SqlSyntaxErrorException" /> protected internal virtual GroupBy GroupBy() { if (lexer.Token() != MySqlToken.KwGroup) { return(null); } lexer.NextToken(); Match(MySqlToken.KwBy); var expr = exprParser.Expression(); var order = SortOrder.Asc; GroupBy groupBy; switch (lexer.Token()) { case MySqlToken.KwDesc: { order = SortOrder.Desc; goto case MySqlToken.KwAsc; } case MySqlToken.KwAsc: { lexer.NextToken(); goto default; } default: { break; } } switch (lexer.Token()) { case MySqlToken.KwWith: { lexer.NextToken(); MatchIdentifier("ROLLUP"); return(new GroupBy(expr, order, true)); } case MySqlToken.PuncComma: { break; } default: { return(new GroupBy(expr, order, false)); } } for (groupBy = new GroupBy().AddOrderByItem(expr, order); lexer.Token() == MySqlToken.PuncComma;) { lexer.NextToken(); order = SortOrder.Asc; expr = exprParser.Expression(); switch (lexer.Token()) { case MySqlToken.KwDesc: { order = SortOrder.Desc; goto case MySqlToken.KwAsc; } case MySqlToken.KwAsc: { lexer.NextToken(); goto default; } default: { break; } } groupBy.AddOrderByItem(expr, order); if (lexer.Token() == MySqlToken.KwWith) { lexer.NextToken(); MatchIdentifier("ROLLUP"); return(groupBy.SetWithRollup()); } } return(groupBy); }