using EC.Helper.RabbitFunc.Compiler; using EC.Helper.RabbitFunc.Expressions; namespace EC.Helper.RabbitFunc; public class RabbitFuncUtil { public static LambdaExpression CompileFromSource(string source) { if (source == null) throw new ArgumentNullException(nameof(source)); LambdaExpression? lambda = null; using var reader = new StringReader(source); var tokenizer = new Tokenizer(reader); var parser = new Parser(tokenizer); while (!tokenizer.EndOfStream) { var expression = parser.Parse(); if (expression == null) break; lambda = expression; } return lambda ?? throw new CompilerException(tokenizer.Position, "The formula was not found"); } public static LambdaExpression CompileFromFile(string path) { if (path == null) throw new ArgumentNullException(nameof(path)); LambdaExpression? lambda = null; using var stream = new FileStream(path, FileMode.Open, FileAccess.Read); using var reader = new StreamReader(stream, System.Text.Encoding.UTF8); var tokenizer = new Tokenizer(reader); var parser = new Parser(tokenizer); while (!tokenizer.EndOfStream) { var expression = parser.Parse(); if (expression == null) break; lambda = expression; } return lambda ?? throw new CompilerException(tokenizer.Position, "The formula was not found"); } }