コード例 #1
0
    string ParseDefaultStringInstruction(ScriptboundObject.Instruction instruction, object[] parameters, bool highlight)
    {
        if (instruction.parameters[0].type != ScriptboundObject.Instruction.ParamType.STRING)
        {
            return("");
        }
        var result = parameters[0].ToString();

        if (instruction.injectibles == null || instruction.injectibles.Count <= 0)
        {
            return(result);
        }
        var count = instruction.injectibles.Count;

        for (var i = count - 1; i >= 0; i--)
        {
            var injectible = instruction.injectibles[i];
            var index      = injectible.index;
            var obj        = injectible.obj;
            var obj_str    = "[[" + ObjectToString(obj) + "]]";
            if (highlight)
            {
                obj_str = "<b>" + obj_str + "</b>";
            }
            result = result.Insert(index, obj_str);
        }

        return(result);
    }
コード例 #2
0
    private void ParseInstruction(string instruction_str, ScriptboundObject clone, Dictionary <string, MethodInfo> methods)
    {
        if (instruction_str.Length <= 0)
        {
            return;                              //if line is empty then no need to do anything
        }
        instruction_str = instruction_str.Trim(' ');
        instruction_str = instruction_str.Trim((char)13);

        //calculate tabCount
        var tabCount = 0;

        for (var i = 0; i < instruction_str.Length; i++)
        {
            if (instruction_str[i] != '\t')
            {
                tabCount = i; break;
            }
        }

        //trim instruction from tabs
        instruction_str = instruction_str.Trim('\t');

        //break the instruction into two parts
        var(controls, contents) = BreakInstruction(instruction_str);

        ScriptboundObject.Instruction instructionObj = new ScriptboundObject.Instruction();
        instructionObj.indent = tabCount;


        if (string.IsNullOrEmpty(contents) && SINGULAR_CONTROLS.Contains(controls))
        {
            if (controls == "else")
            {
                instructionObj.controlElse = true;
            }
        }
        else
        {
            try
            {
                var method = BreakInstructionControl(controls, instructionObj, clone, methods);
                if (contents != null)
                {
                    contents = TrimContentIndent(contents, tabCount);
                }
                BreakInstructionContents(contents, instructionObj, clone, method);
            }
            catch (ParsingException e)
            {
                if (defaultStringMethod != null)
                {
                    var attr_injectible = methodReflections[defaultStringMethod].GetCustomAttribute <ScriptboundObject.StringInjectible>();
                    instructionObj.instructionName = defaultStringMethod;
                    instructionObj.parameters      = new List <ScriptboundObject.Instruction.Parameter>();
                    instructionObj.injectibles     = new List <ScriptboundObject.Instruction.Injectible>();
                    ExstractSingleStringInstruction(TrimContentIndent(instruction_str, tabCount), instructionObj, clone, attr_injectible);
                }
                else
                {
                    throw e;
                }
            }
        }
        clone.scriptInstructions.Add(instructionObj);
    }