示例#1
0
 public void EvaluateFile(LangFileBuilderBase fileBuilder, Dictionary <string, string> extraParams)
 {
     fileBuilder.WriteFile();
 }
示例#2
0
 public FileContextEvaluator(LangFileBuilderBase fileBuilder) : base("File")
 {
     _fileBuilder = fileBuilder;
 }
示例#3
0
        private void InterpretContent(XmlNode contentNode, ContextEvaluatorBase contextEvaluator)
        {
            foreach (XmlNode parentNode in contentNode.ChildNodes)
            {
                Dictionary <string, string> extraParams;
                switch (parentNode.Name)
                {
                case "Files":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        LangFileBuilderBase fileBuilder = TryCastUtil.TryCast <ICreateFileBuilder>(_langFactory).CreateFileBuilder();
                        fileBuilder.CreateFile(_outDir + GetAttributeOrDefault(node, "name", ""));

                        extraParams = InterpretIdentifier(node, () =>
                        {
                            return(new FileContextEvaluator(fileBuilder));
                        });

                        TryCastUtil.TryCast <IEvaluateFile>(contextEvaluator).EvaluateFile(fileBuilder, extraParams);
                    }
                    break;

                case "Variables":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        var variableObj = new VariableObj(
                            ParseDataType(GetAttributeOrDefault(node, "type", "")),
                            GetAttributeOrDefault(node, "name", "")
                            );

                        extraParams = InterpretIdentifier(node, null);

                        TryCastUtil.TryCast <IEvaluateVariable>(contextEvaluator).EvaluateVariable(variableObj, extraParams);
                    }
                    break;

                case "Functions":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        var functionObj = new FunctionObj(
                            ParseDataType(GetAttributeOrDefault(node, "returnType", "")),
                            GetAttributeOrDefault(node, "name", "")
                            );
                        functionObj.FuncParams = ParseFuncParams(GetAttributeOrDefault(node, "params", ""));

                        extraParams = InterpretIdentifier(node, null);

                        TryCastUtil.TryCast <IEvaluateFunction>(contextEvaluator).EvaluateFunction(functionObj, extraParams);
                    }
                    break;

                case "Properties":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        var propertyObj = new VariableObj(
                            ParseDataType(GetAttributeOrDefault(node, "type", "")),
                            GetAttributeOrDefault(node, "name", "")
                            );

                        extraParams = InterpretIdentifier(node, null);

                        TryCastUtil.TryCast <IEvaluateProperty>(contextEvaluator).EvaluateProperty(propertyObj, extraParams);
                    }
                    break;

                case "Classes":
                case "InnerClasses":
                    foreach (XmlNode node in parentNode.ChildNodes)
                    {
                        LangClassBuilderBase classBuilder = TryCastUtil.TryCast <ICreateClassBuilder>(_langFactory).CreateClassBuilder();

                        classBuilder.CreateClass(GetAttributeOrDefault(node, "name", ""));

                        extraParams = InterpretIdentifier(node, () =>
                        {
                            return(new ClassContextEvaluator(classBuilder));
                        });

                        TryCastUtil.TryCast <IEvaluateClass>(contextEvaluator).EvaluateClass(classBuilder, extraParams);
                    }
                    break;

                case "Constructor":
                    List <VariableObj> constructorParams = ParseFuncParams(GetAttributeOrDefault(parentNode, "params", ""));

                    extraParams = InterpretIdentifier(parentNode, null);

                    TryCastUtil.TryCast <IEvaluateConstructor>(contextEvaluator).EvaluateConstructor(constructorParams, extraParams);
                    break;

                default:
                    /* Note: this should be impossible since an invalid identifier would be caught by the
                     * schema validation, but we should still throw an exception just in case */
                    throw new InterpreterParseException($"Identifier \"{parentNode.Name}\" not recognized.");
                }
            }
        }