public async Task BinaryOperatorInterpreterAddition() { var parser = new BaZicParser(); var inputCode = @"EXTERN FUNCTION Main(args[]) VARIABLE var1 = 2 + 3 # Should be 5 VARIABLE var2 = ""2"" + 3 # Should be 23 VARIABLE var3 = 2 + 3.0 # Should be 5 VARIABLE var4 = ""Hello"" + true # Should be HelloTrue END FUNCTION"; var interpreter = new BaZicInterpreter(parser.Parse(inputCode, true).Program); await interpreter.StartDebugAsync(true); var result = interpreter.GetStateChangedHistoryString(); Assert.IsNull(interpreter.Error); Assert.IsTrue(result.Contains("[Log] Variable 'var1' declared. Default value : 5 (System.Int32)")); Assert.IsTrue(result.Contains("[Log] Variable 'var2' declared. Default value : 23 (System.String)")); Assert.IsTrue(result.Contains("[Log] Variable 'var3' declared. Default value : 5 (System.Double)")); Assert.IsTrue(result.Contains("[Log] Variable 'var4' declared. Default value : HelloTrue (System.String)")); inputCode = @"EXTERN FUNCTION Main(args[]) VARIABLE var4 = true + false # Should fail END FUNCTION"; interpreter = new BaZicInterpreter(parser.Parse(inputCode, true).Program); await interpreter.StartDebugAsync(true); result = interpreter.GetStateChangedHistoryString(); Assert.IsTrue(result.Contains("[Error] Unexpected and unmanaged error has been detected : Operator '+' cannot be applied to operands of type 'bool' and 'bool'")); }
public async Task BaZicInterpreterWithUiProgramBadControlAccessorUse() { var parser = new BaZicParser(); var inputCode = @" EXTERN FUNCTION Main(args[]) Button1.Content = ""Hello"" END FUNCTION"; var xamlCode = @" <Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" Name=""Window""> <Grid> <Button Name=""Button1""/> </Grid> </Window>"; var bazicProgram = (BaZicUiProgram)parser.Parse(inputCode, xamlCode, optimize: true).Program; var interpreter = new BaZicInterpreter(bazicProgram); await interpreter.StartDebugAsync(true); var exception = interpreter.Error.Exception; Assert.AreEqual("The variable 'Button1' does not exist or is not accessible.", exception.Message); }
public async Task ProgramInterpreterInvokeExternMethod4() { var parser = new BaZicParser(); var inputCode = @"EXTERN FUNCTION Main(args[]) END FUNCTION EXTERN FUNCTION Method1(arg) RETURN arg END FUNCTION"; using (var interpreter = new BaZicInterpreter(parser.Parse(inputCode, false).Program)) { var tempFile = Path.Combine(Path.GetTempPath(), "BaZic_Bin", Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + ".exe"); var errors = await interpreter.Build(); Assert.IsNull(errors); var result = await interpreter.InvokeMethod(true, "Method1", true, 123); Assert.AreEqual(123, result); Assert.AreEqual(BaZicInterpreterState.Idle, interpreter.State); } }
public async Task ProgramInterpreterInvokeExternMethod3() { var parser = new BaZicParser(); var inputCode = @"EXTERN FUNCTION Main(args[]) AWAIT MethodAsync(345, 5.0) END FUNCTION EXTERN FUNCTION Method1(arg) RETURN arg END FUNCTION ASYNC FUNCTION MethodAsync(value, timeToWait) VARIABLE var1 = AWAIT System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(timeToWait)) RETURN value END FUNCTION"; using (var interpreter = new BaZicInterpreter(parser.Parse(inputCode, false).Program)) { var t = interpreter.StartDebugAsync(true); var result = await interpreter.InvokeMethod(true, "Method1", true, 123); Assert.AreEqual(123, result); // Idle is expected because InvokeMethod waits that the main // thread (used by Main()) is free before running. So the async // function is complete before reaching this assert. Assert.AreEqual(BaZicInterpreterState.Idle, interpreter.State); await interpreter.Stop(); Assert.AreEqual(BaZicInterpreterState.Stopped, interpreter.State); } }
public async Task ProgramInterpreterInvokeExternMethod7() { var parser = new BaZicParser(); var inputCode = @"EXTERN FUNCTION Main(args[]) END FUNCTION EXTERN ASYNC FUNCTION Method1(arg) VARIABLE var1 = AWAIT System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(3.0)) RETURN arg END FUNCTION"; using (var interpreter = new BaZicInterpreter(parser.Parse(inputCode, false).Program)) { var errors = await interpreter.Build(); Assert.IsNull(errors); var t = interpreter.StartReleaseAsync(true); var result = (Task)interpreter.InvokeMethod(true, "Method1", true, 123); Assert.AreEqual(TaskStatus.WaitingForActivation, result.Status); await Task.Delay(5000); Assert.AreEqual(TaskStatus.RanToCompletion, result.Status); Assert.AreEqual(123, ((dynamic)result).Result); Assert.AreEqual(BaZicInterpreterState.Idle, interpreter.State); await interpreter.Stop(); Assert.AreEqual(BaZicInterpreterState.Stopped, interpreter.State); } }
public async Task ProgramInterpreterInvokeExternMethod5() { var parser = new BaZicParser(); var inputCode = @"EXTERN FUNCTION Main(args[]) END FUNCTION FUNCTION Method1(arg) RETURN arg END FUNCTION"; using (var interpreter = new BaZicInterpreter(parser.Parse(inputCode, false).Program)) { var tempFile = Path.Combine(Path.GetTempPath(), "BaZic_Bin", Path.GetFileNameWithoutExtension(Path.GetTempFileName()) + ".exe"); var errors = await interpreter.Build(); Assert.IsNull(errors); var result = await interpreter.InvokeMethod(true, "Method1", true, 123); Assert.AreEqual(null, result); Assert.AreEqual("Unexpected and unmanaged error has been detected : The method 'Method1' does not exist in the type 'BaZicProgramReleaseMode.Program'.", interpreter.Error.Exception.Message); Assert.AreEqual(BaZicInterpreterState.StoppedWithError, interpreter.State); } }
public async Task InvokeMethodInterpreterRecursivityStackoverflowAsync() { var parser = new BaZicParser(); var inputCode = @"EXTERN FUNCTION Main(args[]) FirstMethod(1000) # A Stackoverflow must never happen if FirstMethod is ASYNC. END FUNCTION ASYNC FUNCTION FirstMethod(num) IF num > 1 THEN RETURN FirstMethod(num - 1) END IF RETURN num END FUNCTION"; var interpreter = new BaZicInterpreter(parser.Parse(inputCode, false).Program); await interpreter.StartDebugAsync(true); var expected1 = "[Log] End of the execution of the method 'FirstMethod'. Returned value : 0 (System.Int32)"; var result = interpreter.GetStateChangedHistoryString(); Assert.IsTrue(result.Contains(expected1)); Assert.AreEqual(null, interpreter.ProgramResult); await TestUtilities.TestAllRunningMode(null, inputCode); }
public void BaZicOptimizerMethodInliningStatement() { var parser = new BaZicParser(); var codeGenerator = new BaZicCodeGenerator(); var inputCode = @"EXTERN FUNCTION Main(args[]) Method1() Method1() END FUNCTION FUNCTION Method1() VARIABLE x = 1 x = 2 RETURN END FUNCTION"; var program = parser.Parse(inputCode, true); var result = codeGenerator.Generate(program.Program); var expectedResult = @"# BaZic code generated automatically EXTERN FUNCTION Main(args[]) VARIABLE RET_A _A: VARIABLE x = 1 x = 2 GOTO _B _B: VARIABLE RET_C _C: VARIABLE x = 1 x = 2 GOTO _D _D: END FUNCTION FUNCTION Method1() VARIABLE x = 1 x = 2 RETURN END FUNCTION"; var variable1Decl = (VariableDeclaration)program.Program.Methods.Last().Statements.First(); var variable1Ref = (VariableReferenceExpression)((AssignStatement)program.Program.Methods.Last().Statements[1]).LeftExpression; var variable2Decl = (VariableDeclaration)program.Program.Methods.First().Statements[2]; var variable2Ref = (VariableReferenceExpression)((AssignStatement)program.Program.Methods.First().Statements[3]).LeftExpression; var variable3Decl = (VariableDeclaration)program.Program.Methods.First().Statements[8]; var variable3Ref = (VariableReferenceExpression)((AssignStatement)program.Program.Methods.First().Statements[9]).LeftExpression; Assert.AreEqual(variable1Decl.Id, variable1Ref.VariableDeclarationID); Assert.AreNotEqual(variable1Decl.Id, variable2Decl.Id); Assert.AreNotEqual(variable1Decl.Id, variable2Ref.VariableDeclarationID); Assert.AreEqual(variable2Decl.Id, variable2Ref.VariableDeclarationID); Assert.AreNotEqual(variable2Decl.Id, variable3Decl.Id); Assert.AreNotEqual(variable2Decl.Id, variable3Ref.VariableDeclarationID); Assert.AreEqual(variable3Decl.Id, variable3Ref.VariableDeclarationID); Assert.AreEqual(expectedResult, result); }
public async Task ProgramInterpreterTestEntryPointMethod() { var parser = new BaZicParser(); var inputCode = @"FUNCTION Method1() END FUNCTION"; using (var interpreter = new BaZicInterpreter(parser.Parse(inputCode, false).Program)) { await interpreter.StartDebugAsync(true); Assert.AreEqual(BaZicInterpreterState.Idle, interpreter.State); } inputCode = @"EXTERN FUNCTION Main(args[]) END FUNCTION EXTERN FUNCTION Main(args[]) END FUNCTION"; using (var interpreter = new BaZicInterpreter(parser.Parse(inputCode, true).Program)) { await interpreter.StartDebugAsync(true); Assert.IsInstanceOfType(interpreter.Error.Exception, typeof(SeveralEntryPointMethodException)); } }
public void BaZicParserExpressionGroupSeparatorNested() { var parser = new BaZicParser(); var inputCode = "VARIABLE var1 = ((1))"; var program = parser.Parse(inputCode); Assert.AreEqual(1, ((PrimitiveExpression)program.Program.GlobalVariables.Single().DefaultValue).Value); }
public void BaZicParserPrimitiveExpressionArray() { var parser = new BaZicParser(); var inputCode = @"VARIABLE var1[] = NEW [""Hello"", NEW [""Foo"", ""Bar"", ""Buz""]]"; var program = parser.Parse(inputCode); Assert.AreEqual(2, ((ArrayCreationExpression)program.Program.GlobalVariables.Single().DefaultValue).Values.Count); }
public void BaZicParserPrimitiveExpressionFalse() { var parser = new BaZicParser(); var inputCode = "VARIABLE var1 = False"; var program = parser.Parse(inputCode); Assert.AreEqual(false, ((PrimitiveExpression)program.Program.GlobalVariables.Single().DefaultValue).Value); }
public void BaZicParserPrimitiveExpressionNull() { var parser = new BaZicParser(); var inputCode = "VARIABLE var1 = NULL"; var program = parser.Parse(inputCode); Assert.IsNull(((PrimitiveExpression)program.Program.GlobalVariables.Single().DefaultValue).Value); }
public async Task PropertyReferenceInterpreter() { var parser = new BaZicParser(); var inputCode = @"EXTERN FUNCTION Main(args[]) VARIABLE var1 = ""Hello"".Length END FUNCTION"; var interpreter = new BaZicInterpreter(parser.Parse(inputCode, true).Program); await interpreter.StartDebugAsync(true); var expectedLogs = @"[State] Ready [State] Preparing [Log] Reference assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' loaded in the application domain. [Log] Reference assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' loaded in the application domain. [Log] Reference assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' loaded in the application domain. [Log] Reference assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' loaded in the application domain. [Log] Reference assembly 'Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' loaded in the application domain. [Log] Reference assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' loaded in the application domain. [Log] Reference assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' loaded in the application domain. [Log] Reference assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' loaded in the application domain. [Log] Declaring global variables. [Log] Program's entry point detected. [State] Running [Log] Preparing to invoke the method 'Main'. [Log] Executing the argument values of the method. [Log] Executing an expression of type 'ArrayCreationExpression'. [Log] The expression returned the value 'BaZicProgramReleaseMode.ObservableDictionary' (BaZicProgramReleaseMode.ObservableDictionary (length: 0)). [Log] Invoking the synchronous method 'Main'. [Log] Variable 'args' declared. Default value : {Null} [Log] Variable 'args' value set to : BaZicProgramReleaseMode.ObservableDictionary (BaZicProgramReleaseMode.ObservableDictionary (length: 0)) [Log] Registering labels. [Log] Executing a statement of type 'VariableDeclaration'. [Log] Executing an expression of type 'PropertyReferenceExpression'. [Log] Getting the property ''Hello' (type:System.String).Length'. [Log] Executing an expression of type 'PrimitiveExpression'. [Log] The expression returned the value 'Hello' (System.String). [Log] The expression returned the value '5' (System.Int32). [Log] Variable 'var1' declared. Default value : 5 (System.Int32) [Log] End of the execution of the method 'Main'. Returned value : ({Null}) [State] Idle "; Assert.AreEqual(expectedLogs, interpreter.GetStateChangedHistoryString()); inputCode = @"EXTERN FUNCTION Main(args[]) VARIABLE var1 = ""Hello"".length END FUNCTION"; interpreter = new BaZicInterpreter(parser.Parse(inputCode, true).Program); await interpreter.StartDebugAsync(true); Assert.AreEqual("Unable to access to the property 'length' of the type 'System.String'.", interpreter.StateChangedHistory.Last().Error.Exception.InnerException.Message); }
public void BaZicParserPrimitiveExpressionNestedQuotes() { var parser = new BaZicParser(); var inputCode = @"VARIABLE var1 = ""Hel\""l\r\no"""; var program = parser.Parse(inputCode); Assert.AreEqual(@"Hel""l o", ((PrimitiveExpression)program.Program.GlobalVariables.Single().DefaultValue).Value); }
public void BaZicParserPrimitiveExpressionStringSeveralLines() { var parser = new BaZicParser(); var inputCode = @"VARIABLE var1 = ""Hello World"""; var program = parser.Parse(inputCode); Assert.AreEqual("Hello\r\nWorld", ((PrimitiveExpression)program.Program.GlobalVariables.Single().DefaultValue).Value); }
public void BaZicParserOperatorsExpressionLessOrEqual() { var parser = new BaZicParser(); var inputCode = "VARIABLE var1 = 1 <= 2"; var program = parser.Parse(inputCode); var value = (BinaryOperatorExpression)program.Program.GlobalVariables.Single().DefaultValue; Assert.AreEqual(BinaryOperatorType.LessThanOrEqual, value.Operator); }
public void BaZicParserVariableDeclaration5() { var parser = new BaZicParser(); var inputCode = "VARIABLE variable_name"; var result = parser.Parse(inputCode); Assert.AreEqual("variable_name", result.Program.GlobalVariables.Single().Name.Identifier); }
public void BaZicParserOperatorsExpressionOr() { var parser = new BaZicParser(); var inputCode = "VARIABLE var1 = TRUE OR FALSE"; var program = parser.Parse(inputCode); var value = (BinaryOperatorExpression)program.Program.GlobalVariables.Single().DefaultValue; Assert.AreEqual(BinaryOperatorType.LogicalOr, value.Operator); }
public void BaZicParserVariableDeclaration25() { var parser = new BaZicParser(); var inputCode = @"VARIABLE var1[] = NEW [ ""Hello World"" ]"; var result = parser.Parse(inputCode); Assert.AreEqual(typeof(ArrayCreationExpression), result.Program.GlobalVariables.Single().DefaultValue.GetType()); }
public async Task ProgramInterpreterInvokeExternMethodUI12() { var parser = new BaZicParser(); var inputCode = @" VARIABLE globVar = 1 EXTERN FUNCTION Main(args[]) END FUNCTION EXTERN FUNCTION Method1() DO WHILE TRUE LOOP END FUNCTION"; var xamlCode = @" <Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" Name=""Window1""> <StackPanel> <Button Name=""Button1"" Content=""Hello""/> </StackPanel> </Window>"; using (var interpreter = new BaZicInterpreter(inputCode, xamlCode)) { var t = interpreter.StartDebugAsync(true); t = interpreter.InvokeMethod(true, "Method1", true); await Task.Delay(3000); Assert.AreEqual(BaZicInterpreterState.Running, interpreter.State); await interpreter.Stop(); Assert.AreEqual(BaZicInterpreterState.Stopped, interpreter.State); } using (var interpreter = new BaZicInterpreter(inputCode, xamlCode)) { var errors = await interpreter.Build(); Assert.IsNull(errors); var t = interpreter.StartReleaseAsync(true); t = interpreter.InvokeMethod(true, "Method1", true); await Task.Delay(10000); Assert.AreEqual(BaZicInterpreterState.Running, interpreter.State); await interpreter.Stop(); Assert.AreEqual(BaZicInterpreterState.Stopped, interpreter.State); } }
public void BaZicParserVariableDeclaration4() { var parser = new BaZicParser(); var inputCode = "VARIABLE var1 [] # Comment"; var result = parser.Parse(inputCode); Assert.AreEqual(1, result.Program.GlobalVariables.Count); Assert.IsTrue(result.Program.GlobalVariables.First().IsArray); }
public async Task VariableReferenceInterpreter() { var parser = new BaZicParser(); var inputCode = @"EXTERN FUNCTION Main(args[]) VARIABLE var1 = 1 VARIABLE var2 = var1 RETURN var2 END FUNCTION"; var interpreter = new BaZicInterpreter(parser.Parse(inputCode, true).Program); await interpreter.StartDebugAsync(true); var expectedLogs = @"[State] Ready [State] Preparing [Log] Reference assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' loaded in the application domain. [Log] Reference assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' loaded in the application domain. [Log] Reference assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' loaded in the application domain. [Log] Reference assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' loaded in the application domain. [Log] Reference assembly 'Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' loaded in the application domain. [Log] Reference assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' loaded in the application domain. [Log] Reference assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' loaded in the application domain. [Log] Reference assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' loaded in the application domain. [Log] Declaring global variables. [Log] Program's entry point detected. [State] Running [Log] Preparing to invoke the method 'Main'. [Log] Executing the argument values of the method. [Log] Executing an expression of type 'ArrayCreationExpression'. [Log] The expression returned the value 'BaZicProgramReleaseMode.ObservableDictionary' (BaZicProgramReleaseMode.ObservableDictionary (length: 0)). [Log] Invoking the synchronous method 'Main'. [Log] Variable 'args' declared. Default value : {Null} [Log] Variable 'args' value set to : BaZicProgramReleaseMode.ObservableDictionary (BaZicProgramReleaseMode.ObservableDictionary (length: 0)) [Log] Registering labels. [Log] Executing a statement of type 'VariableDeclaration'. [Log] Executing an expression of type 'PrimitiveExpression'. [Log] The expression returned the value '1' (System.Int32). [Log] Variable 'var1' declared. Default value : 1 (System.Int32) [Log] Executing a statement of type 'VariableDeclaration'. [Log] Executing an expression of type 'VariableReferenceExpression'. [Log] The expression returned the value '1' (System.Int32). [Log] Variable 'var2' declared. Default value : 1 (System.Int32) [Log] Executing a statement of type 'ReturnStatement'. [Log] Executing an expression of type 'VariableReferenceExpression'. [Log] The expression returned the value '1' (System.Int32). [Log] Return : 1 (System.Int32) [Log] A Return statement or Break statement or Exception has been detected or thrown. Exiting the current block of statements. [Log] End of the execution of the method 'Main'. Returned value : 1 (System.Int32) [State] Idle "; Assert.AreEqual(expectedLogs, interpreter.GetStateChangedHistoryString()); await TestUtilities.TestAllRunningMode("1", inputCode); }
public void BaZicParserOperatorsExpressionNot() { var parser = new BaZicParser(); var inputCode = "VARIABLE var1 = NOT 1 = 2"; var program = parser.Parse(inputCode); var notValue = (NotOperatorExpression)program.Program.GlobalVariables.Single().DefaultValue; var value = (BinaryOperatorExpression)notValue.Expression; Assert.AreEqual(BinaryOperatorType.Equality, value.Operator); }
public void BaZicParserPrimaryExpressionBadReference() { var parser = new BaZicParser(); var inputCode = @" FUNCTION Method() VARIABLE var1 = This END FUNCTION"; var program = parser.Parse(inputCode); Assert.AreEqual("The name 'This' does not exist in the current context.", program.Issues.InnerException.Message); }
public void BaZicParserMethodDeclaration10() { var parser = new BaZicParser(); var inputCode = @"FUNCTION Method1() END FUNCTION"; var program = parser.Parse(inputCode); var exception = (BaZicParserException)program.Issues.InnerExceptions.Single(); Assert.AreEqual("Invalid statement. New line expected.", exception.Message); }
public void BaZicParserOperatorsExpression() { var parser = new BaZicParser(); var inputCode = "VARIABLE var1 = 1 + 2"; var program = parser.Parse(inputCode); var value = (BinaryOperatorExpression)program.Program.GlobalVariables.Single().DefaultValue; Assert.AreEqual(1, ((PrimitiveExpression)value.LeftExpression).Value); Assert.AreEqual(2, ((PrimitiveExpression)value.RightExpression).Value); Assert.AreEqual(BinaryOperatorType.Addition, value.Operator); }
public void BaZicParserProgram() { var parser = new BaZicParser(); var inputCode = @" EXTERN FUNCTION Main(args[]) MyFunction(1, 2, NULL) END FUNCTION VARIABLE myVar[] = NEW [""value1"", ""val2""] FUNCTION MyFunction(arg1, arg2, arg3[]) DO VARIABLE x = 1 + 2 * (3 + 4 + 5) x = myVar[0] x = ""hello"" + x.ToString() x = 1.ToString() BREAK LOOP WHILE myVar = arg1 OR(arg1 = arg2 AND arg2 = arg3[0]) arg3 = NEW System.DateTime() RETURN RecursivityFunction(100) END FUNCTION ASYNC FUNCTION RecursivityFunction(num) IF num > 1 THEN num = AWAIT(RecursivityFunction(num – 1)) TRY num.ToString() # this is a comment CATCH THROW NEW System.Exception(EXCEPTION.Message) END TRY ELSE IF NOT num = 1 THEN # another comment END IF END IF RETURN num END FUNCTION "; var program = parser.Parse(inputCode); var variableDecl = (VariableDeclaration)((IterationStatement)program.Program.Methods[1].Statements.First()).Statements.First(); Assert.AreEqual("x", variableDecl.Name.Identifier); Assert.AreEqual(12, variableDecl.Line); Assert.AreEqual(17, variableDecl.Column); Assert.AreEqual(0, program.Issues.InnerExceptions.Count); }
public void BaZicParserPrimaryExpressionBarReferenceOrNamespace() { var parser = new BaZicParser(); var inputCode = @" FUNCTION Method() VARIABLE var1 = var2.Property END FUNCTION"; var program = parser.Parse(inputCode); Assert.AreEqual("The name 'var2' does not look like a valid namespace or variable.", program.Issues.InnerException.Message); }
/// <summary> /// Initializes a new instance of the <see cref="BaZicInterpreterCore"/> class. /// </summary> /// <param name="middleware">The middleware</param> /// <param name="assemblySandbox">The assembly sandbox.</param> /// <param name="inputCode">The BaZic code to interpret.</param> /// <param name="xamlCode">The XAML code to interpret that represents the user interface.</param> /// <param name="resourceFilePaths">Paths to the resources files (like PNG or JPG) required for the XAML code.</param> /// <param name="optimize">(optional) Defines whether the generated syntax tree must be optimized for the interpreter or not.</param> private BaZicInterpreterCore(BaZicInterpreterMiddleware middleware, AssemblySandbox assemblySandbox, string inputCode, string xamlCode, IEnumerable <string> resourceFilePaths, bool optimize = false) : this(middleware, assemblySandbox) { var parser = new BaZicParser(); var parsingResult = parser.Parse(inputCode, xamlCode, resourceFilePaths, optimize); if (parsingResult.Issues.InnerExceptions.OfType <BaZicParserException>().Count(issue => issue.Level == BaZicParserExceptionLevel.Error) != 0 || (!parsingResult.Issues.InnerExceptions.OfType <BaZicParserException>().Any() && parsingResult.Issues.InnerExceptions.Count > 0)) { throw parsingResult.Issues; } Program = parsingResult.Program; }