コード例 #1
0
        protected TALCommand Compile_METAL_DEFINE_PARAM(string argument)
        {
            // Compile a define-param command, resulting argument is:
            // Argument: [(paramType, paramName, paramPath),...]

            // Break up the list of defines first
            List<DefineInfo> commandArgs = new List<DefineInfo>();
            // We only want to match semi-colons that are not escaped
            foreach (string defStmt in Constants.METAL_DEFINE_PARAM_REGEX.Split(argument))
            {
                //  remove any leading space and un-escape any semi-colons
                string defineStmt = defStmt.TrimStart().Replace(";;", ";");
                // Break each defineStmt into pieces "[local|global] varName expression"
                List<string> stmtBits = new List<string>(defineStmt.Split(new char[] { ' ' }));
                string varType;
                string varName;
                string expression;
                if (stmtBits.Count < 3)
                {
                    // Error, badly formed define-param command
                    string msg = string.Format("Badly formed define-param command '{0}'.  Define commands must be of the form: 'varType varName expression[;varType varName expression]'", argument);
                    throw new TemplateParseException(this.currentStartTag, msg);
                }
                varType = stmtBits[0];
                varName = stmtBits[1];
                expression = string.Join(" ", stmtBits.GetRange(2, stmtBits.Count - 2).ToArray());

                DefineInfo di = new DefineInfo();
                di.defAction = DefineAction.Local;
                di.varType = varType;
                di.varName = varName;
                di.varPath = expression;
                commandArgs.Add(di);
            }

            TALCommand ci = new TALCommand();
            ci.Tag = this.currentStartTag;
            ci.ID = Constants.METAL_DEFINE_PARAM;
            ci.Attributes = new List<object>();
            ci.Attributes.Add(commandArgs);
            return ci;
        }
コード例 #2
0
        protected TALCommand Compile_METAL_FILL_PARAM(string argument)
        {
            // Compile a fill-param command, resulting argument is:
            // Argument: [(paramName, paramPath),...]

            // Break up the list of defines first
            List<DefineInfo> commandArgs = new List<DefineInfo>();
            // We only want to match semi-colons that are not escaped
            foreach (string defStmt in Constants.METAL_FILL_PARAM_REGEX.Split(argument))
            {
                //  remove any leading space and un-escape any semi-colons
                string defineStmt = defStmt.TrimStart().Replace(";;", ";");
                // Break each defineStmt into pieces "[local|global] varName expression"
                List<string> stmtBits = new List<string>(defineStmt.Split(new char[] { ' ' }));
                string varName;
                string expression;
                if (stmtBits.Count < 2)
                {
                    // Error, badly formed fill-param command
                    string msg = string.Format("Badly formed fill-param command '{0}'.  Fill-param commands must be of the form: 'varName expression[;varName expression]'", argument);
                    throw new TemplateParseException(this.currentStartTag, msg);
                }
                varName = stmtBits[0];
                expression = string.Join(" ", stmtBits.GetRange(1, stmtBits.Count - 1).ToArray());

                DefineInfo di = new DefineInfo();
                di.defAction = DefineAction.Local;
                di.varName = varName;
                di.varPath = expression;
                commandArgs.Add(di);
            }

            // Determine what use-macro statement this belongs to by working through the list backwards
            int? ourMacroLocation = null;
            int location = this.tagStack.Count - 1;
            while (ourMacroLocation == null)
            {
                int macroLocation = this.tagStack[location].UseMacroLocation;
                if (macroLocation != -1)
                {
                    ourMacroLocation = macroLocation;
                }
                else
                {
                    location -= 1;
                    if (location < 0)
                    {
                        string msg = string.Format("metal:fill-param must be used inside a metal:use-macro call");
                        throw new TemplateParseException(this.currentStartTag, msg);
                    }
                }
            }

            // Get the use-macro command we are going to adjust
            TALCommand cmnd = this.commandList[(int)ourMacroLocation];
            string macroName = (string)cmnd.Attributes[0];
            Dictionary<string, TALSubProgram> slotMap = (Dictionary<string, TALSubProgram>)cmnd.Attributes[1];
            List<DefineInfo> paramMap = (List<DefineInfo>)cmnd.Attributes[2];
            int endSymbol = (int)cmnd.Attributes[3];

            // Append param definitions to list
            paramMap.AddRange(commandArgs);

            // Update the command
            TALCommand ci = new TALCommand();
            ci.Tag = cmnd.Tag;
            ci.ID = cmnd.ID;
            ci.Attributes = new List<object>();
            ci.Attributes.Add(macroName);
            ci.Attributes.Add(slotMap);
            ci.Attributes.Add(paramMap);
            ci.Attributes.Add(endSymbol);
            this.commandList[(int)ourMacroLocation] = ci;
            return null;
        }
コード例 #3
0
        protected TALCommand Compile_TAL_DEFINE(string argument)
        {
            // Compile a define command, resulting argument is:
            // [(DefineAction (global, local, set), variableName, variablePath),...]
            // Break up the list of defines first
            List<DefineInfo> commandArgs = new List<DefineInfo>();
            // We only want to match semi-colons that are not escaped
            foreach (string defStmt in Constants.TAL_DEFINE_REGEX.Split(argument))
            {
                //  remove any leading space and un-escape any semi-colons
                string defineStmt = defStmt.TrimStart().Replace(";;", ";");
                // Break each defineStmt into pieces "[local|global] varName expression"
                List<string> stmtBits = new List<string>(defineStmt.Split(new char[] { ' ' }));
                DefineAction defAction = DefineAction.Local;
                string varName;
                string expression;
                if (stmtBits.Count < 2)
                {
                    // Error, badly formed define command
                    string msg = string.Format("Badly formed define command '{0}'.  Define commands must be of the form: '[local|global] varName expression[;[local|global] varName expression]'", argument);
                    throw new TemplateParseException(this.currentStartTag, msg);
                }
                // Assume to start with that >2 elements means a local|global flag
                if (stmtBits.Count > 2)
                {
                    if (stmtBits[0] == "global")
                    {
                        defAction = DefineAction.Global;
                        varName = stmtBits[1];
                        expression = string.Join(" ", stmtBits.GetRange(2, stmtBits.Count - 2).ToArray());
                    }
                    else if (stmtBits[0] == "local")
                    {
                        varName = stmtBits[1];
                        expression = string.Join(" ", stmtBits.GetRange(2, stmtBits.Count - 2).ToArray());
                    }
                    else if (stmtBits[0] == "set")
                    {
                        defAction = DefineAction.SetLocal;
                        varName = stmtBits[1];
                        expression = string.Join(" ", stmtBits.GetRange(2, stmtBits.Count - 2).ToArray());
                    }
                    else
                    {
                        // Must be a space in the expression that caused the >3 thing
                        varName = stmtBits[0];
                        expression = string.Join(" ", stmtBits.GetRange(1, stmtBits.Count - 1).ToArray());
                    }
                }
                else
                {
                    // Only two bits
                    varName = stmtBits[0];
                    expression = string.Join(" ", stmtBits.GetRange(1, stmtBits.Count - 1).ToArray());
                }

                DefineInfo di = new DefineInfo();
                di.defAction = defAction;
                di.varName = varName;
                di.varPath = expression;
                commandArgs.Add(di);
            }

            TALCommand ci = new TALCommand();
            ci.Tag = this.currentStartTag;
            ci.ID = Constants.TAL_DEFINE;
            ci.Attributes = new List<object>();
            ci.Attributes.Add(commandArgs);
            return ci;
        }