private static void AnalyzeFile(string file) { Console.WriteLine($"Analyzing {file}"); var runtime = new InjectionRuntime(); var messages = runtime.Load(file); var originalCollor = Console.ForegroundColor; foreach (var message in messages.OrderBy(m => m.StartLine)) { switch (message.Severity) { case MessageSeverity.Error: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(message.ToString()); break; case MessageSeverity.Warning: Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(message.ToString()); break; } } Console.ForegroundColor = originalCollor; }
public CompletionList GetCompletions(string fileContent, int line, int column) { var runtime = new InjectionRuntime(); runtime.Load(fileContent, "test.sc"); return(GetCompletions(runtime.CurrentScript.Syntax, runtime.Metadata, line, column)); }
public void Load(string sourceCode) { var messages = runtime.Load(sourceCode, "test.sc"); if (messages.Any()) { Assert.Fail("Script loading error found: " + messages.ToString()); } }
public static InjectionValue Execute(string subName, string codeBlock) { var runtime = new InjectionRuntime(); var parser = new Parser(); runtime.Load(parser.ParseFile(codeBlock, new FailTestErrorListener())); return(runtime.CallSubrutine(subName)); }
public static Task <InjectionValue> RunSubrutine(string subrutineName, Func <CancellationToken?> retrieveCancellationToken, string file) { return(Task.Run(() => { var runtime = new InjectionRuntime(retrieveCancellationToken); var parser = new Parser(); runtime.Load(parser.ParseFile(file, new FailTestErrorListener())); return runtime.CallSubrutine(subrutineName); })); }
public static void TestSubrutine(int expected, string subrutineName, string file) { var runtime = new InjectionRuntime(); var parser = new Parser(); runtime.Load(parser.ParseFile(file, new FailTestErrorListener())); var actual = runtime.CallSubrutine(subrutineName); Assert.AreEqual(InjectionValueKind.Integer, actual.Kind, file); Assert.AreEqual(expected, actual.Integer, file); }
private void UpdateDiagnostic() { string content; Uri uri; lock (documentLock) { content = documents[lastDocumentUri.AbsoluteUri]; uri = lastDocumentUri; } var runtime = new InjectionRuntime(); var messages = runtime.Load(content, uri.LocalPath); diagnosticReporter.Report(uri, messages); }
public static void TestSubrutine(string expected, string codeBlock, NativeSubrutineDefinition[] natives = null) { var subrutine = $"sub test()\r\n{codeBlock}\r\n end sub"; var runtime = new InjectionRuntime(); if (natives != null) { runtime.Metadata.Add(natives); } var parser = new Parser(); runtime.Load(parser.ParseFile(subrutine, new FailTestErrorListener())); var actual = runtime.CallSubrutine("test"); Assert.AreEqual(InjectionValueKind.String, actual.Kind, codeBlock); Assert.AreEqual(expected, actual.String, codeBlock); }
public static void TestSubrutine(string codeBlock, NativeSubrutineDefinition[] natives = null, NativeSubrutineDefinition[] intrinsicVariables = null) { var subrutine = $"sub test()\r\n{codeBlock}\r\n end sub"; var runtime = new InjectionRuntime(); if (natives != null) { runtime.Metadata.Add(natives); } if (intrinsicVariables != null) { runtime.Metadata.AddIntrinsicVariables(intrinsicVariables); } var parser = new Parser(); runtime.Load(parser.ParseFile(subrutine, new FailTestErrorListener())); runtime.CallSubrutine("test"); }
public static MessageCollection Parse(string fileContent) { var runtime = new InjectionRuntime(); return(runtime.Load(fileContent, "test.sc")); }
public Location GetDefinition(string fileContent, int line, int column) { string fileName = "test.sc"; var runtime = new InjectionRuntime(); runtime.Load(fileContent, fileName); var rule = FindRule(runtime.CurrentScript.Syntax, line, column); if (rule == null) { return(null); } if (rule is injectionParser.CallContext call) { var subrutineName = call.SYMBOL().GetText(); var argumentCount = call.argumentList()?.arguments()?.argument()?.Length ?? 0; if (runtime.Metadata.TryGetSubrutine(subrutineName, argumentCount, out var subrutineDefinition)) { var subrutineDefName = subrutineDefinition.Syntax.subrutineName(); return(new Location() { Range = new Range(new Position(subrutineDefName.Start.Line, subrutineDefName.Start.Column + 1), new Position(subrutineDefName.Stop.Line, subrutineDefName.Start.Column + 1 + subrutineName.Length)) }); } } else if (rule is injectionParser.LvalueContext lvalue) { var subrutine = GetSubrutine(lvalue); if (subrutine != null) { var definitions = new Dictionary <string, ParserRuleContext>(StringComparer.OrdinalIgnoreCase); var collector = new SymbolDefinitionsCollector(definitions); collector.Visit(subrutine); string name = lvalue.SYMBOL()?.GetText() ?? lvalue.indexedSymbol().SYMBOL().GetText(); if (definitions.TryGetValue(name, out var definitionRule)) { var endColumn = definitionRule.Start.Column + 1 + definitionRule.GetText().Length; return(new Location() { Range = new Range(new Position(definitionRule.Start.Line, definitionRule.Start.Column + 1), new Position(definitionRule.Start.Line, endColumn)) }); } } } else if (rule is injectionParser.GotoContext gotoContext) { var subrutine = GetSubrutine(gotoContext); if (subrutine != null) { var definitions = new Dictionary <string, ParserRuleContext>(StringComparer.OrdinalIgnoreCase); var collector = new SymbolDefinitionsCollector(definitions); collector.Visit(subrutine); string name = gotoContext.SYMBOL().GetText(); if (definitions.TryGetValue(name, out var definitionRule)) { var endColumn = definitionRule.Start.Column + definitionRule.GetText().Length - 2; return(new Location() { Range = new Range(new Position(definitionRule.Start.Line, definitionRule.Start.Column + 1), new Position(definitionRule.Start.Line, endColumn)) }); } } } else if (rule is injectionParser.OperandContext operand) { var subrutine = GetSubrutine(operand); if (subrutine != null) { var definitions = new Dictionary <string, ParserRuleContext>(StringComparer.OrdinalIgnoreCase); var collector = new SymbolDefinitionsCollector(definitions); collector.Visit(subrutine); string name = operand.SYMBOL()?.GetText() ?? operand.indexedSymbol().SYMBOL().GetText(); if (definitions.TryGetValue(name, out var definitionRule)) { var endColumn = definitionRule.Start.Column + 1 + definitionRule.GetText().Length; return(new Location() { Range = new Range(new Position(definitionRule.Start.Line, definitionRule.Start.Column + 1), new Position(definitionRule.Start.Line, endColumn)) }); } } } return(null); }