Example #1
0
        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);
        }
Example #2
0
        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;
        }
Example #3
0
        private IBSharpConfig GetConfig()
        {
            var config = new BSharpConfig {
                SingleSource     = true,
                UseInterpolation = true,
                IgnoreElements   = Project.IgnoreElements.SmartSplit().ToArray(),
                Global           = Project.Global,
                DefaultNamespace = Project.DefaultNamespace,
                Conditions       = Project.Conditions
            };

            if (null != Project.Definition)
            {
                config.DefaultNamespace = Project.Definition.ChooseAttr("defaultNamespace", "DefaultNamespace");
            }
            if (null != Project && null != Project.SrcClass)
            {
                config.KeepLexInfo = Project.SrcClass.Compiled.Attr("KeepLexInfo").ToBool();
            }

            config.SetParent(Project);



            return(config);
        }
        private IBSharpConfig GetConfig() {
            var config = new BSharpConfig {
                SingleSource = true,
                UseInterpolation = true,
				IgnoreElements = Project.IgnoreElements.SmartSplit().ToArray(),
				Global = Project.Global,
            };

            config.SetParent(Project);

            return config;
        }
Example #5
0
        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);
        }
Example #6
0
        protected BSharpContext Compile(string code, object globals = null, IDictionary <string, string> conditions = null, BSharpConfig _cfg = null)
        {
            var cfg = new BSharpConfig();

            cfg.Conditions = conditions;
            if (null != globals)
            {
                cfg.Global = new Scope(globals.ToDict())
                {
                    UseInheritance = false
                };
            }
            if (null != _cfg)
            {
                _cfg.SetParent(cfg);
                cfg = _cfg;
            }
            return((BSharpContext)BSharpCompiler.Compile(code, cfg));
        }
Example #7
0
        public void BugNotNormalReportCompilation()
        {
            var code = @"
class report abstract  prototype=report
	basedir='c:/mnt/reporthub'
		
class bankreport abstract
	import report
	outdir = '${basedir}/~{commonkey}/raw/~{objname}/'
	outfile = '${reportname}${ext}.html'
	period = '${tp.period:1}'
	year = '${tp.year:2014}'

generator
	import bankreport
	dataset
		item out_valuta=RUB 
	dataset 
		item obj=445
	
	dataset
		item template=balans2011_corp_bank	reportname = 'Бухгалтерский баланс (Форма №1)'

";
            var cfg  = new BSharpConfig {
                Global = new Scope()
            };

            cfg.Global["tp.year"]   = "2013";
            cfg.Global["tp.period"] = "2";
            var ctx = BSharpCompiler.Compile(code, cfg);

            foreach (var e in ctx.GetErrors(ErrorLevel.Warning))
            {
                Console.WriteLine(e.ToLogString());
            }
            Assert.AreEqual(0, ctx.GetErrors(ErrorLevel.Warning).Count());
            Assert.AreEqual(1, ctx.Get(BSharpContextDataType.Working).Count());
            var cls = ctx.Get(BSharpContextDataType.Working).First();

            Assert.AreEqual("2013", cls.Compiled.Attr("year"));
            Assert.AreEqual("2", cls.Compiled.Attr("period"));
        }
Example #8
0
        private IBSharpConfig GetConfig() {
            var config = new BSharpConfig {
                SingleSource = true,
                UseInterpolation = true,
				IgnoreElements = Project.IgnoreElements.SmartSplit().ToArray(),
				Global = Project.Global,
			    DefaultNamespace = Project.DefaultNamespace,
                Conditions = Project.Conditions
            };
            if (null != Project.Definition)
            {
                config.DefaultNamespace = Project.Definition.ChooseAttr("defaultNamespace", "DefaultNamespace");
            }
			if (null != Project && null != Project.SrcClass){
				config.KeepLexInfo = Project.SrcClass.Compiled.Attr("KeepLexInfo").ToBool();
			}

            config.SetParent(Project);



            return config;
        }