/// <summary> /// Instantiate expression tree from tokens. /// </summary> private static FilterExpressionRoot CompileFilters(IEnumerable <Token> token) { var reader = new TokenReader(token); var op = CompileL0(reader); if (reader.IsRemainToken) { throw CreateUnexpectedTokenError(reader.Get().ToString(), reader.RemainQuery); } return(new FilterExpressionRoot { Operator = op }); }
/// <summary> /// Instantiate sources from tokens. /// </summary> private static IEnumerable <FilterSourceBase> CompileSources(IEnumerable <Token> token) { // filter // filter: "argument" // filter: "argument1", "argument2", ... -> filter: "argument1", filter: "argument2", ... var reader = new TokenReader(token); while (reader.IsRemainToken) { var filter = reader.Get(); if (filter.Type != TokenType.Literal && filter.Type != TokenType.OperatorMultiple) { throw CreateUnexpectedTokenError(filter.Value, reader.RemainQuery); } Type fstype; if (!FilterSourceResolver.TryGetValue(filter.Value, out fstype)) { throw new ArgumentException( QueryCompilerResources.QueryUnknownFilterSource + " " + filter.Value); } if (reader.IsRemainToken && reader.LookAhead().Type == TokenType.Collon) // with argument { reader.AssertGet(TokenType.Collon); do { var argument = reader.AssertGet(TokenType.String); yield return(Activator.CreateInstance(fstype, argument.Value) as FilterSourceBase); // separated by comma if (reader.IsRemainToken) { reader.AssertGet(TokenType.Comma); } } while (reader.IsRemainToken && reader.LookAhead().Type == TokenType.String); } else { yield return(Activator.CreateInstance(fstype) as FilterSourceBase); if (reader.IsRemainToken) { // filters are divided by comma reader.AssertGet(TokenType.Comma); } } } }
/// <summary> /// Instantiate sources from tokens. /// </summary> private static IEnumerable <FilterSourceBase> CompileSources(IEnumerable <Token> token) { // filter // filter: "argument" // filter: "argument1", "argument2", ... -> filter: "argument1", filter: "argument2", ... var reader = new TokenReader(token); while (reader.IsRemainToken) { var filter = reader.Get(); if (filter.Type != TokenType.Literal && filter.Type != TokenType.OperatorMultiple) { throw new ArgumentException("このトークンは無効です: " + filter.Type + " (リテラルか \'*\' です。)"); } Type fstype; if (!FilterSourceResolver.TryGetValue(filter.Value, out fstype)) { throw new ArgumentException("フィルタ ソースが一致しません: " + filter.Value); } if (reader.IsRemainToken && reader.LookAhead().Type == TokenType.Collon) // with argument { reader.AssertGet(TokenType.Collon); do { var argument = reader.AssertGet(TokenType.String); yield return(Activator.CreateInstance(fstype, argument.Value) as FilterSourceBase); // separated by comma if (reader.IsRemainToken) { reader.AssertGet(TokenType.Comma); } } while (reader.IsRemainToken && reader.LookAhead().Type == TokenType.String); } else { yield return(Activator.CreateInstance(fstype) as FilterSourceBase); if (reader.IsRemainToken) { // filters are divided by comma reader.AssertGet(TokenType.Comma); } } } }
private static ListMembers GetListValue(TokenReader reader) { reader.AssertGet(TokenType.Period); var user = reader.AssertGet(TokenType.Literal).Value; reader.AssertGet(TokenType.Period); string slug; var slugToken = reader.Get(); switch (slugToken.Type) { case TokenType.String: case TokenType.Literal: slug = slugToken.Value; break; default: throw CreateUnexpectedTokenError(slugToken.Value, reader.RemainQuery); } return(new ListMembers(user, slug)); }
private static ListMembers GetListValue(TokenReader reader) { reader.AssertGet(TokenType.Period); var user = reader.AssertGet(TokenType.Literal).Value; reader.AssertGet(TokenType.Period); string slug; var slugToken = reader.Get(); switch (slugToken.Type) { case TokenType.String: case TokenType.Literal: slug = slugToken.Value; break; default: throw CreateUnexpectedTokenError(slugToken.Value, reader.RemainQuery); } return new ListMembers(user, slug); }
/// <summary> /// Instantiate expression tree from tokens. /// </summary> private static FilterExpressionRoot CompileFilters(IEnumerable<Token> token) { var reader = new TokenReader(token); var op = CompileL0(reader); if (reader.IsRemainToken) { throw CreateUnexpectedTokenError(reader.Get().ToString(), reader.RemainQuery); } return new FilterExpressionRoot { Operator = op }; }
/// <summary> /// Instantiate sources from tokens. /// </summary> private static IEnumerable<FilterSourceBase> CompileSources(IEnumerable<Token> token) { // filter // filter: "argument" // filter: "argument1", "argument2", ... -> filter: "argument1", filter: "argument2", ... var reader = new TokenReader(token); while (reader.IsRemainToken) { var filter = reader.Get(); if (filter.Type != TokenType.Literal && filter.Type != TokenType.OperatorMultiple) { throw new ArgumentException("このトークンは無効です: " + filter.Type + " (リテラルか \'*\' です。)"); } Type fstype; if (!FilterSourceResolver.TryGetValue(filter.Value, out fstype)) throw new ArgumentException("フィルタ ソースが一致しません: " + filter.Value); if (reader.IsRemainToken && reader.LookAhead().Type == TokenType.Collon) // with argument { reader.AssertGet(TokenType.Collon); do { var argument = reader.AssertGet(TokenType.String); yield return Activator.CreateInstance(fstype, argument.Value) as FilterSourceBase; // separated by comma if (reader.IsRemainToken) { reader.AssertGet(TokenType.Comma); } } while (reader.IsRemainToken && reader.LookAhead().Type == TokenType.String); } else { yield return Activator.CreateInstance(fstype) as FilterSourceBase; if (reader.IsRemainToken) { // filters are divided by comma reader.AssertGet(TokenType.Comma); } } } }
/// <summary> /// Instantiate sources from tokens. /// </summary> private static IEnumerable<FilterSourceBase> CompileSources(IEnumerable<Token> token) { // filter // filter: "argument" // filter: "argument1", "argument2", ... -> filter: "argument1", filter: "argument2", ... var reader = new TokenReader(token); while (reader.IsRemainToken) { var filter = reader.Get(); if (filter.Type != TokenType.Literal && filter.Type != TokenType.OperatorMultiple) { throw CreateUnexpectedTokenError(filter.Value, reader.RemainQuery); } Type fstype; if (!FilterSourceResolver.TryGetValue(filter.Value, out fstype)) { throw new ArgumentException( QueryCompilerResources.QueryUnknownFilterSource + " " + filter.Value); } if (reader.IsRemainToken && reader.LookAhead().Type == TokenType.Collon) // with argument { reader.AssertGet(TokenType.Collon); do { var argument = reader.AssertGet(TokenType.String); yield return Activator.CreateInstance(fstype, argument.Value) as FilterSourceBase; // separated by comma if (reader.IsRemainToken) { reader.AssertGet(TokenType.Comma); } } while (reader.IsRemainToken && reader.LookAhead().Type == TokenType.String); } else { yield return Activator.CreateInstance(fstype) as FilterSourceBase; if (reader.IsRemainToken) { // filters are divided by comma reader.AssertGet(TokenType.Comma); } } } }
/// <summary> /// Instantiate expression tree from tokens. /// </summary> private static FilterExpressionRoot CompileFilters(IEnumerable<Token> token) { var reader = new TokenReader(token); var op = CompileL0(reader); if (reader.IsRemainToken) throw new FilterQueryException("不正なトークンです: " + reader.Get(), reader.RemainQuery); return new FilterExpressionRoot { Operator = op }; }