public void ExplicitElementCanOverrideImplicit() { var ctx = BSharpCompiler.Compile(@" class X element a extend=z a 1 b 2 c 3 class Y import X element b override=y "); var cls = ctx["Y"]; var a = cls.AllElements.FirstOrDefault(_ => _.Name == "a"); var b = cls.AllElements.FirstOrDefault(_ => _.Name == "b"); var c = cls.AllElements.FirstOrDefault(_ => _.Name == "c"); Assert.NotNull(a); Assert.NotNull(b); Assert.NotNull(c); Assert.True(c.Implicit); Assert.False(a.Implicit); Assert.False(b.Implicit); Assert.AreEqual(BSharpElementType.Define, c.Type); Assert.AreEqual(BSharpElementType.Extension, a.Type); Assert.AreEqual(BSharpElementType.Override, b.Type); }
public void NestedElementPartials() { var ctx = BSharpCompiler.Compile(@" class A partial x=1 x u a=1 b class A partial y=2 x u b=2 "); Assert.AreEqual(0, ctx.GetErrors().Count()); var cls = ctx["A"]; Assert.AreEqual("1", cls.Compiled.Attr("x")); Assert.AreEqual("2", cls.Compiled.Attr("y")); var xs = cls.Compiled.Elements("x"); Assert.AreEqual(1, xs.Count()); var x = xs.First(); Assert.NotNull(x.Element("b")); Assert.AreEqual("u", x.GetCode()); Assert.AreEqual("1", x.Attr("a")); Assert.AreEqual("2", x.Attr("b")); }
private static XElement CompileWithBSharp(XElement result) { var compileroptions = new BSharpConfig { UseInterpolation = true, SingleSource = true }; var compileresult = BSharpCompiler.Compile(new[] { result }, compileroptions); var newresult = new XElement("bsharp"); foreach (var w in compileresult.Get(BSharpContextDataType.Working)) { var copy = new XElement(w.Compiled); if (null != w.Error) { copy.AddFirst(new XElement("error", new XText(w.Error.ToString()))); } newresult.Add(copy); } var e = new XElement("errors"); foreach (var er in compileresult.GetErrors()) { e.Add(XElement.Parse(new XmlSerializer().Serialize("error", er)).Element("error")); } if (e.HasElements) { newresult.Add(e); } result = newresult; return(result); }
/// <summary> /// </summary> public BSharpJsonCompiler() { _jsonContext = new List <string>(); _bSharpContext = new BSharpContext(); _bSharpCompiler = new BSharpCompiler(); _jsonParser = new JsonParser(); }
/// <summary> /// Установка контекста /// </summary> /// <param name="bSharps">Массив кода на B#</param> public void SetContext(string[] bSharps) { var parsed = bSharps.Select(_ => BxlParser.Parse(_)); var compiled = BSharpCompiler.Compile(parsed); SetContext(compiled); }
public void BaseKeywordSupport() { var code = @" class a abstract e c=1 e2 c=2 e3 c='1:${.c},2:${self.c},3:${self.x},4:${base.x},5:${base.c.x},6:${base.y},7:${self.y}' class c abstract x=1 class d abstract y=2 x=5 a b c=4 x=3 w=${base.c.x} import c import d "; var result = BSharpCompiler.Compile(code); var b = result["b"]; var x = b.Compiled; Console.WriteLine(x.ToString().Replace("\"", "'")); Assert.AreEqual(@"<a code='b' c='4' x='3' w='1' fullcode='b' y='2'> <e c='1'> <e2 c='2'> <e3 c='1:2,2:4,3:3,4:5,5:1,6:2,7:2' /> </e2> </e> </a>".Simplify(SimplifyOptions.Full), x.ToString().Simplify(SimplifyOptions.Full)); }
public void CanUseCacheOnResolutionIntegration() { var xml = BSharpCompiler.Compile(ProductionCode)["tiles"].Compiled; var conf = new HostConfig(xml); var qh = new HostServer(conf); qh.Start(); try { var response = new HttpClient().Call("http://127.0.0.1:14990/map/8/173/76.png"); Assert.AreEqual(200, response.State); Assert.AreEqual("image/png; charset=utf-8", response.ContentType); var png = (Bitmap)Image.FromStream(new MemoryStream(response.Data)); Assert.AreEqual(ImageFormat.Png, png.RawFormat); var pixel = png.GetPixel(70, 40); Assert.AreEqual(174, pixel.R); Assert.AreEqual(209, pixel.G); Assert.AreEqual(160, pixel.B); response = new HttpClient().Call("http://127.0.0.1:14990/map/6/11/26.png"); Assert.AreEqual(200, response.State); Assert.AreEqual("image/png; charset=utf-8", response.ContentType); png = (Bitmap)Image.FromStream(new MemoryStream(response.Data)); Assert.AreEqual(ImageFormat.Png, png.RawFormat); pixel = png.GetPixel(54, 18); Assert.AreEqual(181, pixel.R); Assert.AreEqual(171, pixel.G); Assert.AreEqual(201, pixel.B); } finally { qh.Stop(); } }
public void DetectMetaAndRawClasses(string code, string metamask, string rawmask) { var ctx = BSharpCompiler.Compile(code); var meta = string.Join(", ", ctx.MetaClasses.Values.OrderBy(_ => _.FullName).Select(_ => _.FullName + ":" + _.GetAttributes())); var raw = string.Join(", ", ctx.RawClasses.Values.OrderBy(_ => _.FullName).Select(_ => _.FullName + ":" + _.GetAttributes())); Assert.AreEqual(metamask, meta); Assert.AreEqual(rawmask, raw); }
public void PreventAttributeConflict() { var ctx = BSharpCompiler.Compile(@" class A partial x=1 class A partial x=2 "); Assert.AreEqual(1, ctx.GetErrors(ErrorLevel.Error).Count()); }
public void AssignToSingleClass() { var ctx = BSharpCompiler.Compile(@" namespace A class B "); var cls = ctx["B"]; Assert.AreEqual("A", cls.Namespace); }
public void MergableAsyncCall() { var ctx = new BSharpContext(); var p1 = BSharpCompiler.CompileAsync("class A").ContinueWith(_ => ctx.Merge(_.Result)); var p2 = BSharpCompiler.CompileAsync("class B").ContinueWith(_ => ctx.Merge(_.Result)); var p3 = BSharpCompiler.CompileAsync("class C").ContinueWith(_ => ctx.Merge(_.Result)); Task.WaitAll(p1, p2, p3); Assert.AreEqual(3, ctx.Working.Count); }
/// <summary> /// Выполнение цели /// </summary> /// <param name="context"></param> public override void Execute(IBSharpContext context) { var compiler = new BSharpCompiler(); foreach (var e in Project.CompilerExtensions ) { compiler.Extensions.Add(e); } var cfg = GetConfig(); compiler.Initialize(cfg); compiler.Compile(Project.Sources, context); HandleErrorStream(context); }
public void CanDisableImplicitElements() { var ctx = BSharpCompiler.Compile(@" class X explicit a 1 "); var cls = ctx["X"]; var a = cls.SelfElements.FirstOrDefault(_ => _.Name == "a"); Assert.Null(a); }
public void CanPreventExplicitInAllHierarchy() { var ctx = BSharpCompiler.Compile(@" class X explicit a 1 "); var cls = ctx["X"]; var a = cls.SelfElements.FirstOrDefault(_ => _.Name == "a"); Assert.Null(a); }
public void NotCodedElementsNotCauseElementDefinition() { var ctx = BSharpCompiler.Compile(string.Format(@" class X a ")); var cls = ctx["X"]; var a = cls.SelfElements.FirstOrDefault(_ => _.Name == "a"); Assert.Null(a); }
public int Execute(TaskConsoleParameters args) { var context = BSharpCompiler.CompileDirectory(args.ScriptDirectory, new BSharpConfig { Global = new Scope(args.Global), KeepLexInfo = true }); var cls = context[args.ScriptClass]; if (null == cls) { throw new Exception("cannot find class " + args.ScriptClass); } var container = ContainerFactory.CreateDefault(); container.RegisterAssembly(typeof(TaskProcess).Assembly); var configProvider = new GenericConfiguration(cls.Compiled, context) { Custom = args }; container.Set <IConfigProvider>(configProvider); Loggy.Manager = container.Get <ILoggyManager>(); var defloggy = Loggy.Manager.Get(); defloggy.Level = args.LogLevel; var consoleAppender = defloggy.Appenders.OfType <ConsoleAppender>().FirstOrDefault(); if (null == consoleAppender) { defloggy.Appenders.Add(new ConsoleAppender { Format = args.LogFormat, Level = args.LogLevel, Manager = Loggy.Manager }); } else { consoleAppender.Format = args.LogFormat; consoleAppender.Level = args.LogLevel; } var loggy = Loggy.Manager.Get("bcinst"); var installRequest = new TaskEnvironment { Config = cls.Compiled, Context = context, Log = loggy, Globals = new Scope(args.Global), Targets = args.Targets.ToArray() }; var processor = container.Get <ITaskProcessor>(); processor.Execute(installRequest); return(0); }
//[TestCase(60)] //[TestCase(70)] //[TestCase(80)] //[TestCase(90)] //[TestCase(100)] public void ChartsCompileMultTimesTestForPerformanceControl(int times) { Console.WriteLine(Process.GetCurrentProcess().Threads.Count); for (var i = 0; i < times; i++) { Console.Write(i); BSharpCompiler.CompileDirectory(@"C:\z3projects\assoi\local\Draft\report\content\charts"); Console.Write(":"); Console.Write(Process.GetCurrentProcess().Threads.Count); Console.Write(", "); } }
protected BSharpContext CompileAll(bool single, params string[] code) { var parser = new BxlParser(); var idx = 0; var xmls = code.Select(_ => parser.Parse(_, (idx++) + ".bxl")).ToArray(); var cfg = new BSharpConfig { SingleSource = single, KeepLexInfo = false }; var result = BSharpCompiler.Compile(xmls, cfg); return((BSharpContext)result); }
public void PreventElementBodyConflict() { var ctx = BSharpCompiler.Compile(@" class A partial x 1 a=1 x class A partial x 1 y "); Assert.AreEqual(1, ctx.GetErrors(ErrorLevel.Error).Count()); }
public void CanSetupElement(string prefix) { var ctx = BSharpCompiler.Compile(string.Format(@" class X {0}a 1 ", prefix)); var cls = ctx["X"]; var a = cls.SelfElements.FirstOrDefault(_ => _.Name == "a"); Assert.NotNull(a); Assert.AreEqual(BSharpElementType.Define, a.Type); Assert.True(a.Implicit); }
public void SimplestTestWithFirstNotPartial() { var ctx = BSharpCompiler.Compile(@" class A x=1 class A partial y=2 "); Assert.AreEqual(0, ctx.GetErrors().Count()); var cls = ctx["A"]; Assert.AreEqual("1", cls.Compiled.Attr("x")); Assert.AreEqual("2", cls.Compiled.Attr("y")); }
public void BUG_CannotInheritTwoStatics() { var code = @" class a static a b static " ; var result = BSharpCompiler.Compile(code); foreach (var error in result.GetErrors()) { Console.WriteLine(error.ToLogString()); } Assert.AreEqual(0, result.GetErrors().Count()); }
public void MultipleNamespaces() { var ctx = BSharpCompiler.Compile(@" namespace A class B namespace C class D "); var cls = ctx["B"]; Assert.AreEqual("A", cls.Namespace); cls = ctx["D"]; Assert.AreEqual("C", cls.Namespace); }
public void FlagsAreMerged() { var ctx = BSharpCompiler.Compile(@" class A partial x=1 explicit class A partial y=2 abstract "); var clses = ctx.Get(BSharpContextDataType.SrcPkg); Assert.AreEqual(1, clses.Count()); var cls = clses.First(); Assert.True(cls.Is(BSharpClassAttributes.Abstract)); Assert.True(cls.Is(BSharpClassAttributes.ExplicitElements)); }
public IConfigProvider Load(ConfigurationOptions options = null) { options = options ?? opts ?? new ConfigurationOptions(); #if BRIDGE var compiler = new BSharpCompiler(); var bxl = new BxlParser(); #else var compiler = WellKnownHelper.Create <IBSharpCompiler>(); var bxl = new BxlParser(); #endif SetupGlobals(options, compiler); var context = compiler.Compile(options.FileSet.CollectBxl()); return(new GenericConfiguration(GetConfig(options, context), context)); }
public void BugPreprocessorsAreNotDetectedAsClasses() { var code = @" require preprocessor using preprocess=Qorpent.BSharp.PreprocessScript preprocess a b"; var ctx = BSharpCompiler.Compile(code); foreach (var error in ctx.GetErrors(ErrorLevel.Error)) { Console.WriteLine(error.ToLogString()); } Assert.AreEqual(0, ctx.GetErrors(ErrorLevel.Error).Count()); }
public void CanSetupValidProxyModeFromBSharp() { const string code = @" class myapp proxize /others appid=15 proxize /others2 appid=16 secure=true proxize /others3 url='http://yandex.ru' "; var xml = BSharpCompiler.Compile(code)["myapp"].Compiled; var config = new HostConfig(xml); Assert.AreEqual("appid=15;", config.Proxize["/others"]); Assert.AreEqual("appid=16;secure=true;", config.Proxize["/others2"]); Assert.AreEqual("http://yandex.ru", config.Proxize["/others3"]); }
public void CanUseDataPackage() { var code = @" require data class mytable1 import Qorpent.Db.TableBase "; var result = BSharpCompiler.Compile(new[] { new BxlParser().Parse(code) }, (IBSharpConfig)null); var cls = result.Get("mytable1"); Assert.NotNull(cls); Assert.GreaterOrEqual(cls.Compiled.Elements("datatype").Count(), 5); Console.WriteLine(cls.Compiled); }
private XElement BSharpExecutor(string arg) { var root = new XElement("root"); var context = (BSharpContext)BSharpCompiler.Compile(arg); foreach (IBSharpClass cls in context.Get(BSharpContextDataType.LibPkg)) { root.Add(cls.Compiled); } foreach (BSharpError e in context.GetErrors(ErrorLevel.Warning)) { root.Add(new XElement("bx-error", new XAttribute("level", e.Level), e.GetDigest().ToString())); } return(root); }
public void SimpleAfterBuildPatch() { var code = @" class A x=1 prototype=x class B x=2 prototype=y import A patch for=x y=${x} z=3 build "; var ctx = BSharpCompiler.Compile(code); var a = ctx["A"]; var b = ctx["B"]; Console.WriteLine(a.Compiled.ToString().Replace("\"", "\"\"")); Console.WriteLine(b.Compiled.ToString().Replace("\"", "\"\"")); Assert.AreEqual(@"<class code=""A"" x=""1"" prototype=""x"" fullcode=""A"" z=""3"" />".Trim().LfOnly(), a.Compiled.ToString().Trim().LfOnly()); Assert.AreEqual(@"<class code=""B"" x=""2"" prototype=""y"" fullcode=""B"" />".Trim().LfOnly(), b.Compiled.ToString().Trim().LfOnly()); }
public void CanCheckoutConfigUsingMachineNameToResolve() { const string code = @" class local connection a y class remote machine t use=^local connection b z "; var ctx = BSharpCompiler.Compile(code); var local = ctx["local"].Compiled; var remote = ctx["remote"].Compiled; var config = new HostConfig(remote, ctx, "t"); Assert.AreSame(local, config.Definition); }