Exemple #1
0
    protected override string GetCompileUnitSourceContent(CompileUnit unit, out string className)
    {
      className = unit.TemplateSource.InferClassName();

      var cmp = getJSCompiler();
      cmp.IncludeTemplateSource(unit.TemplateSource);
      cmp.Compile();
      return cmp.First().CompiledSource;
    }
        protected override void DoCompileTemplateSource(CompileUnit unit)
        {
            var icname = unit.TemplateSource.InferClassName();
            var text   = getSource(unit);

            var blockCount = 0;
            var result     = transpile(text, "\"\\*{3}(.*?)\\*{3}\"", true, ref blockCount);

            result = transpile(result, @"\/\*{3}(.*?)\*{3}\/", false, ref blockCount);
            unit.CompiledSource = evaluateIds(result);
        }
Exemple #3
0
        protected override void DoCompileTemplateSource(CompileUnit unit)
        {
            var icname             = unit.TemplateSource.InferClassName();
            var rawSourceToProcess = processUnitRelativeFileIncludePragmas(unit);

            var ctxUnit = FactoryUtils.MakeAndConfigure <LJSUnitTranspilationContext>(m_TranspilerConfig,
                                                                                      typeof(LJSUnitTranspilationContext),
                                                                                      new [] { unit.TemplateSource.GetName(64) });

            string transpiledUnitSource;

            transpiledUnitSource = transpileFragment(ctxUnit, rawSourceToProcess, RX_BLOCK_FRAGMENT); //  /***  content ***/

            unit.CompiledSource = transpiledUnitSource;
        }
Exemple #4
0
        //evaluates CompileUnit include pragmas - putting them all together in one string the pattern:
        // /***@ relative-file-path ***/  gets expanded into file content
        private string processUnitRelativeFileIncludePragmas(CompileUnit unit)
        {
            var source = unit.TemplateSource.GetSourceContent().ToString().Trim();
            var path   = string.Empty;

            try
            {
                return(RX_FILE_INCLUDE.Replace(source, m => {
                    path = m.Groups[1].AsString().Trim();
                    return unit.TemplateSource.GetRelativeContent(path).AsString();
                }));
            }
            catch (Exception error)
            {
                throw new TemplateParseException(StringConsts.TEMPLATE_JS_COMPILER_INCLUDE_ERROR.Args(path, error.Message), error);
            }
        }
        private string getSource(CompileUnit unit)
        {
            var source = unit.TemplateSource.GetSourceContent().ToString().Trim();
            var r      = new Regex(@"\/\*{3}\@(.*?)\*{3}\/", RegexOptions.Singleline); //Include files, /***@ path ***/
            var path   = string.Empty;

            try
            {
                return(r.Replace(source, m => {
                    path = m.Groups[1].AsString().Trim();
                    return unit.TemplateSource.GetRelativeContent(path).AsString();
                }));
            }
            catch (Exception error)
            {
                throw new TemplateParseException(StringConsts.TEMPLATE_JS_COMPILER_INCLUDE_ERROR.Args(path, error.Message), error);
            }
        }
        protected override void DoCompileTemplateSource(CompileUnit unit)
        {
            var text   = unit.TemplateSource.GetSourceContent().ToString().Trim();
            var icname = unit.TemplateSource.InferClassName();


            Configuration conf = new MemoryConfiguration();

            var confLineCount = 0;

            if (text.StartsWith(CONFIG_START))
            {
                var i = text.IndexOf(CONFIG_END);
                if (i < CONFIG_START.Length)
                {
                    throw new TemplateParseException(StringConsts.TEMPLATE_CS_COMPILER_CONFIG_CLOSE_TAG_ERROR);
                }

                var confText = text.Substring(CONFIG_START.Length, i - CONFIG_START.Length);

                confLineCount = confText.Count(c => c == '\n');

                //cut configuration out of template
                text = text.Substring(i + CONFIG_END.Length);

                try
                {
                    conf = XMLConfiguration.CreateFromXML("<config>" + confText + "</config>");
                }
                catch (Exception error)
                {
                    throw new TemplateParseException(StringConsts.TEMPLATE_CS_COMPILER_CONFIG_ERROR + error.Message, error);
                }
            }
            else  //20140103 DKh add Laconic support
            if (text.StartsWith(LACONFIG_START))
            {
                var i = text.IndexOf(LACONFIG_END);
                if (i < LACONFIG_START.Length)
                {
                    throw new TemplateParseException(StringConsts.TEMPLATE_CS_COMPILER_CONFIG_CLOSE_TAG_ERROR);
                }

                var confText = text.Substring(LACONFIG_START.Length, i - LACONFIG_START.Length);

                confLineCount = confText.Count(c => c == '\n');

                //cut configuration out of template
                text = text.Substring(i + LACONFIG_END.Length);

                try
                {
                    conf = LaconicConfiguration.CreateFromString("config{" + confText + "}");
                }
                catch (Exception error)
                {
                    throw new TemplateParseException(StringConsts.TEMPLATE_CS_COMPILER_CONFIG_ERROR + error.Message, error);
                }
            }



            var compilerNode = conf.Root[CONFIG_COMPILER_SECTION];

            //add referenced assemblies
            foreach (var anode in compilerNode.Children.Where(cn => cn.IsSameName(CONFIG_REF_ASSEMBLY_SECTION)))
            {
                this.ReferenceAssembly(anode.AttrByName(CONFIG_REF_ASSEMBLY_NAME_ATTR).Value);
            }

            //add usings
            var usings = new HashSet <string>();

            RegisterDefaultUsings(usings);

            foreach (var unode in compilerNode.Children.Where(cn => cn.IsSameName(CONFIG_USING_SECTION)))
            {
                usings.Add(unode.AttrByName(CONFIG_USING_NS_ATTR).Value);
            }

            //add attributes
            var attributes = new List <string>();

            foreach (var anode in compilerNode.Children.Where(cn => cn.IsSameName(CONFIG_ATTRIBUTE_SECTION)))
            {
                attributes.Add(anode.AttrByName(CONFIG_ATTRIBUTE_DECL_ATTR).Value);
            }

            unit.CompiledSource = new FSM()
            {
                Compiler          = this,
                Unit              = unit,
                InferredClassName = icname,
                ConfigNode        = conf.Root,
                Source            = text,
                Usings            = usings,
                Attributes        = attributes,
                LineNo            = confLineCount + 1
            }.Build().ToString();
        }
Exemple #7
0
 protected virtual string GetCompileUnitSourceContent(CompileUnit unit, out string className)
 {
     className = unit.TemplateSource.InferClassName();
     return(unit.TemplateSource.GetSourceContent().ToString().Trim());
 }