internal static Tuple <Stack <SBExpressionData>, IErrorCollector> ParseSimpleArguments(string expression) { var addons = AddonManager.Create(); addons.AddAssembly(AddonManager.StepBroCoreAssembly, true); addons.AddAssembly(typeof(System.Math).Assembly, false); addons.AddAssembly(typeof(System.Linq.Enumerable).Assembly, false); //if (module != null) addons.AddAssembly(module, false); var file = new ScriptFile(); file.AddNamespaceUsing(-1, addons.Lookup(null, "System")); file.AddNamespaceUsing(-1, addons.Lookup(null, "System.Linq")); //foreach (var u in usings) //{ // file.AddNamespaceUsing(addons.Lookup(null, u.FullName)); //} var builder = new FileBuilder(new AntlrInputStream(expression), addons, file); builder.Listener.PrepareForExpressionParsing("StepBroFileBuilder.ParseExpression"); var context = builder.Parser.arguments(); var walker = new ParseTreeWalker(); walker.Walk(builder.Listener, context); return(new Tuple <Stack <SBExpressionData>, IErrorCollector>(builder.Listener.GetArguments(), builder.Errors)); }
internal static FileBuilder ParseProcedure( IAddonManager addonManager, string[] usings, Type usingType, params string[] content) { if (addonManager == null) { addonManager = AddonManager.Create(); addonManager.AddAssembly(typeof(Math).Assembly, false); addonManager.AddAssembly(typeof(Enumerable).Assembly, false); } addonManager.AddAssembly(AddonManager.StepBroCoreAssembly, true); // Add StepBro.Core always. if (usingType != null) { addonManager.AddAssembly(usingType.Assembly, false); } var contentBuilder = new StringBuilder(); foreach (var s in content) { contentBuilder.AppendLine(s); } var file = new ScriptFile(); file.AddNamespaceUsing(-1, addonManager.Lookup(null, "System")); file.AddNamespaceUsing(-1, addonManager.Lookup(null, "System.Linq")); file.AddNamespaceUsing(-1, addonManager.Lookup(null, typeof(StepBro.Core.DataReport).Namespace)); if (usings != null) { foreach (var u in usings) { file.AddNamespaceUsing(-1, addonManager.Lookup(null, u)); } } if (usingType != null) { file.AddNamespaceUsing(-1, addonManager.Lookup(null, usingType.Namespace)); } var builder = new FileBuilder(new AntlrInputStream(contentBuilder.ToString()), addonManager, file); builder.Listener.PrepareForExpressionParsing("StepBroFileBuilder.ParseExpression"); var context = builder.Parser.procedureDeclaration(); var walker = new ParseTreeWalker(); walker.Walk(builder.Listener, context); if (file.Errors.ErrorCount > 0) { throw new Exception("PARSING ERRORS"); } return(builder); }
internal static TypeReference ParseType(string content) { var builder = FileBuilder.Create(content); var context = builder.Parser.type(); var walker = new ParseTreeWalker(); walker.Walk(builder.Listener, context); return(builder.Listener.LastParsedType); }
internal static FileBuilder ParseExpression(ScriptFile fileContext, IAddonManager addons, string expression) { var builder = new FileBuilder(new AntlrInputStream(expression), addons, fileContext); builder.Listener.PrepareForExpressionParsing("StepBroFileBuilder.ParseExpression"); var context = builder.Parser.parExpression(); var walker = new ParseTreeWalker(); walker.Walk(builder.Listener, context); return(builder); }
internal static FileBuilder ParseParExpression(Type typeUsing, Type[] typeNamespaces, string content) { var builder = FileBuilder.Create(content, typeUsing, typeNamespaces); builder.Listener.PrepareForExpressionParsing("StepBroFileBuilder.ParseParExpression"); var context = builder.Parser.parExpression(); var walker = new ParseTreeWalker(); walker.Walk(builder.Listener, context); return(builder); }
internal static IValueContainer <T> ParseFileVariable <T>(Type typeUsing, Type[] typeNamespaces, string content) { var builder = FileBuilder.Create(content, typeUsing, typeNamespaces); builder.Listener.PrepareForExpressionParsing("StepBroFileBuilder.ParseExpression"); var context = builder.Parser.fileVariable(); var walker = new ParseTreeWalker(); walker.Walk(builder.Listener, context); if (builder.Errors.ErrorCount > 0) { throw new Exception("PARSING ERRORS"); } return(builder.File.ListFileVariables().FirstOrDefault() as IValueContainer <T>); }