Beispiel #1
0
        private static string Parse(ICodeStruct script)
        {
            StringBuilder text = new StringBuilder();

            text.AppendLine(script.Parse());
            return(text.ToString());
        }
Beispiel #2
0
        private void setCode(ICodeStruct internalScript)
        {
            CodeBlocks.Clear();
            EditorScript = internalScript == null? "" : internalScript.Parse(null, 0);
            List <AssignationModel> listBlock = ModelsToScriptHelper.
                                                TransformScriptToModels(managedScript, new RelayCommand <object>(DeleteNode));

            foreach (AssignationModel item in listBlock)
            {
                CodeBlocks.Add(item);
            }
        }
Beispiel #3
0
        public void GoodScriptTest()
        {
            //Arrange
            Script script = new Script();

            //Act
            script.Analyse(File.ReadAllText("usa.txt"));
            //Test code value
            CodeValue value       = script.FindValue("tag");
            string    valueString = value.Parse();
            //Test Assignation
            Assignation assign       = script.FindAssignation("modifier");
            string      assignString = assign.Parse();
            //Test Extraction
            ICodeStruct extracted       = script.Extract("default");
            string      extractedString = extracted.Parse();
            //Test find all focuses
            List <ICodeStruct> assigns = script.FindAllValuesOfType <CodeBlock>("focus");
            //Test try parse
            string tag = script.TryParse(script, "tag");

            //Assert
            Assert.IsTrue(script.Code.Any());
            Assert.IsFalse(script.Logger.hasErrors());
            Assert.IsTrue(valueString == "USA");
            Assert.IsTrue(!string.IsNullOrEmpty(assignString));
            Assert.IsTrue(extractedString.Contains("yes"));
            //Should not find a tag after extraction
            Assert.IsNull(script.FindValue("default"));
            Assert.IsTrue(assigns.Any());
            Assert.IsTrue(tag == "USA");
            //Test broken parse
            Assert.IsNull(script.TryParse(script, "default", null, false));
            script.TryParse(script, "default");
            Assert.IsTrue(script.Logger.hasErrors());
        }
        private static AssignationModel BlockToModel(ICodeStruct currentBlock, RelayCommand <object> deleteCommand)
        {
            //Should never loop inside something other than an assignation, check type
            Assignation assignation = currentBlock as Assignation;

            if (assignation != null)
            {
                Assignation block = assignation;
                //Check if simply empty, consider an empty block
                if (block.Value == null)
                {
                    //Simple assignation, return corresponding model
                    return(new AssignationModel
                    {
                        BackgroundColor = BLOCKS_COLORS[0],
                        BorderColor = BLOCKS_COLORS[1],
                        Color = BLOCKS_COLORS[2],
                        IsNotEditable = false,
                        CanHaveChild = true,
                        Code = Regex.Replace(block.Assignee, @"\t|\n|\r|\s", "") + " "
                               + block.Operator + " {}",
                        LocalizationKey = getAssignationName(block.Assignee),
                        DeleteNodeCommand = deleteCommand
                    });
                }
                //check if a code value
                CodeValue value = block.Value as CodeValue;
                if (value != null)
                {
                    //Simple assignation, return corresponding model
                    return(new AssignationModel()
                    {
                        BackgroundColor = ASSIGNATIONS_COLORS[0],
                        BorderColor = ASSIGNATIONS_COLORS[1],
                        Color = ASSIGNATIONS_COLORS[2],
                        IsNotEditable = false,
                        CanHaveChild = false,
                        Code = Regex.Replace(block.Assignee, @"\t|\n|\r|\s", "") + " " + block.Operator
                               + " " + Regex.Replace(value.Value, @"\t|\n|\r|\s", ""),
                        LocalizationKey = "Scripter_Assignation_Custom",
                        DeleteNodeCommand = deleteCommand
                    });
                    //Ignore childs even if there is some
                }
                //Otherwise, the child is a codeblock
                CodeBlock codeBlock = block.Value as CodeBlock;
                if (codeBlock != null)
                {
                    AssignationModel newAssignation = new AssignationModel()
                    {
                        BackgroundColor = getColorArray(block.Assignee)[0],
                        BorderColor     = getColorArray(block.Assignee)[1],
                        Color           = getColorArray(block.Assignee)[2],
                        IsNotEditable   = false,
                        CanHaveChild    = true,
                        Code            = Regex.Replace(block.Assignee, @"\t|\n|\r|\s", "") +
                                          " " + block.Operator + " {}",
                        LocalizationKey   = getAssignationName(block.Assignee),
                        DeleteNodeCommand = deleteCommand
                    };
                    foreach (ICodeStruct code in codeBlock.Code)
                    {
                        newAssignation.Childrens.Add(BlockToModel(code, deleteCommand));
                    }
                    return(newAssignation);
                }
                //Error, return nothing.
                return(null);
            }
            //If the current block is a code Value (Corrsponding to block = { Value }
            if (currentBlock is CodeValue)
            {
                //Print the value
                return(new AssignationModel()
                {
                    BackgroundColor = ASSIGNATIONS_COLORS[0],
                    BorderColor = ASSIGNATIONS_COLORS[1],
                    Color = ASSIGNATIONS_COLORS[2],
                    IsNotEditable = false,
                    CanHaveChild = false,
                    Code = Regex.Replace(currentBlock.Parse(), @"\t|\n|\r|\s", ""),
                    LocalizationKey = "Scripter_Assignation_Custom",
                    DeleteNodeCommand = deleteCommand
                });
            }
            return(null);
        }