Esempio n. 1
0
        public void Parse_Normal()
        {
            XmlDocument xml = new XmlDocument();

            xml.LoadXml(@"<?xml version='1.0' encoding='UTF-8'?>
				<language name='test' extensions='*.test'>
				    <highlighting>
				        <list name='keywords0'>
				            <item>word0</item>
				            <item> word1</item>
				        </list>
				        <contexts>
				            <context attribute='a0' lineEndContext='#stay' name='Normal'>
				                <keyword attribute='a1' context='#stay' String='keywords0'/>
				            </context>
							<context attribute='a2' lineEndContext='#stay' name='IncludeContext'>
								<StringDetect attribute='a3' context='##outer/Context' String='include'/>
							</context>
				        </contexts>
				        <itemDatas>
				            <itemData name='a0' defStyleNum='dsNormal'/>
				            <itemData name='a1' defStyleNum='dsKeyword'/>
				            <itemData name='a2' defStyleNum='dsDataType'/>
				            <itemData name='a3' defStyleNum='dsChar'/>
				        </itemDatas>
				    </highlighting>
				    <general>
						<keywords casesensitive='1'/>
					</general>
				</language>"                );
            Raw language = Raw.Parse(xml);

            Assert.AreEqual(
                "<language>" +
                "<highlighting>" +
                "<list name='keywords0'><item>word0</item><item>word1</item></list>" +
                "<contexts>" +
                "<context name='Normal' attribute='a0' lineEndContext='#stay'>" +
                "<keyword attribute='a1' context='#stay' String='keywords0'/>" +
                "</context>" +
                "<context name='IncludeContext' attribute='a2' lineEndContext='#stay'>" +
                "<StringDetect attribute='a3' context='##outer/Context' String='include'/>" +
                "</context>" +
                "</contexts>" +
                "<itemDatas>" +
                "<itemData name='a0' defStyleNum='dsNormal'/>" +
                "<itemData name='a1' defStyleNum='dsKeyword'/>" +
                "<itemData name='a2' defStyleNum='dsDataType'/>" +
                "<itemData name='a3' defStyleNum='dsChar'/>" +
                "</itemDatas>" +
                "</highlighting>" +
                "<general>" +
                "<keywords casesensitive='1'/>" +
                "</general>" +
                "</language>",
                language.ToString()
                );
        }
Esempio n. 2
0
            public static Fragment Parse(String type, JToken json)
            {
                switch (type)
                {
                case "StructuredText":
                    return(StructuredText.Parse(json));

                case "Image":
                    return(Image.Parse(json));

                case "Link.web":
                    return(WebLink.Parse(json));

                case "Link.document":
                    return(DocumentLink.Parse(json));

                case "Link.file":
                    return(FileLink.Parse(json));

                case "Link.image":
                    return(ImageLink.Parse(json));

                case "Text":
                    return(Text.Parse(json));

                case "Select":
                    return(Text.Parse(json));

                case "Date":
                    return(Date.Parse(json));

                case "Timestamp":
                    return(Timestamp.Parse(json));

                case "Number":
                    return(Number.Parse(json));

                case "Color":
                    return(Color.Parse(json));

                case "Embed":
                    return(Embed.Parse(json));

                case "GeoPoint":
                    return(GeoPoint.Parse(json));

                case "Group":
                    return(Group.Parse(json));

                case "SliceZone":
                    return(SliceZone.Parse(json));

                default:
                    return(json != null?Raw.Parse(json) : null);
                }
            }
    override protected Raw NewRaw(string type)
    {
        string file = scanner.GetSyntaxFileByName(type);

        if (string.IsNullOrEmpty(file))
        {
            if (mainForm.Dialogs != null)
            {
                mainForm.Dialogs.ShowInfo("Syntax highlighting", "Missing syntax: " + type);
            }
            return(null);
        }
        XmlDocument xml = xmlLoader.Load(file, false);
        Raw         raw = Raw.Parse(xml);

        Raw.PrefixContexts(raw, type);
        Raw.InlineIncludeRules(raw, this);
        return(raw);
    }
Esempio n. 4
0
        public void Parse_IncludeRulesInOtherFiles()
        {
            XmlDocument xml = new XmlDocument();

            xml.LoadXml(@"<?xml version='1.0' encoding='UTF-8'?>
				<language name='test' extensions='*.test'>
				    <highlighting>
				        <list name='keywords0'>
				            <item>word0</item>
				            <item>word1</item>
				        </list>
				        <contexts>
				            <context attribute='a0' lineEndContext='#stay' name='Normal'>
				                <keyword attribute='a1' context='#stay' String='keywords0'/>
								<IncludeRules context='IncludeContext'/>
								<IncludeRules context='##Outer'/>
				            </context>
							<context attribute='a2' lineEndContext='#stay' name='IncludeContext'>
								<StringDetect attribute='a3' context='#stay' String='include'/>
							</context>
				        </contexts>
				        <itemDatas>
				            <itemData name='a0' defStyleNum='dsNormal'/>
				            <itemData name='a1' defStyleNum='dsKeyword'/>
				            <itemData name='a2' defStyleNum='dsDataType'/>
				            <itemData name='a3' defStyleNum='dsChar'/>
				        </itemDatas>
				    </highlighting>
				</language>"                );

            XmlDocument outerXml = new XmlDocument();

            outerXml.LoadXml(@"<?xml version='1.0' encoding='UTF-8'?>
				<language name='test' extensions='*.test'>
				    <highlighting>
				        <list name='keywords2'>
				            <item>word0</item>
				        </list>
				        <contexts>
				            <context attribute='a0' lineEndContext='#stay' name='OuterNormal'>
								<IncludeRules context='OuterIncludeContext'/>
				            </context>
							<context attribute='a4' lineEndContext='#stay' name='OuterIncludeContext'>
								<StringDetect attribute='a0' context='#stay' String='include'/>
							</context>
				        </contexts>
				        <itemDatas>
				            <itemData name='a0' defStyleNum='dsNormal'/>
				            <itemData name='a4' defStyleNum='dsKeyword'/>
				        </itemDatas>
				    </highlighting>
				</language>"                );

            TestHighlighterSet highlighterSet = new TestHighlighterSet();
            Raw outerRaw = Raw.Parse(outerXml);

            Raw.InlineIncludeRules(outerRaw, highlighterSet);
            highlighterSet.SetData("Outer", outerRaw);
            Raw raw = Raw.Parse(xml);

            Raw.InlineIncludeRules(raw, highlighterSet);
            Assert.AreEqual("<language>" +
                            "<highlighting>" +
                            "<list name='keywords0'>" +
                            "<item>word0</item>" +
                            "<item>word1</item>" +
                            "</list>" +
                            "<list name='keywords2'>" +
                            "<item>word0</item>" +
                            "</list>" +
                            "<contexts>" +
                            "<context name='Normal' attribute='a0' lineEndContext='#stay'>" +
                            "<keyword attribute='a1' context='#stay' String='keywords0'/>" +
                            "<StringDetect attribute='a3' context='#stay' String='include'/>" +
                            "<StringDetect attribute='a0' context='#stay' String='include'/>" +
                            "</context>" +
                            "<context name='IncludeContext' attribute='a2' lineEndContext='#stay'>" +
                            "<StringDetect attribute='a3' context='#stay' String='include'/>" +
                            "</context>" +

                            "<context name='OuterNormal' attribute='a0' lineEndContext='#stay'>" +
                            "<StringDetect attribute='a0' context='#stay' String='include'/>" +
                            "</context>" +
                            "<context name='OuterIncludeContext' attribute='a4' lineEndContext='#stay'>" +
                            "<StringDetect attribute='a0' context='#stay' String='include'/>" +
                            "</context>" +

                            "</contexts>" +
                            "<itemDatas>" +
                            "<itemData name='a0' defStyleNum='dsNormal'/>" +
                            "<itemData name='a1' defStyleNum='dsKeyword'/>" +
                            "<itemData name='a2' defStyleNum='dsDataType'/>" +
                            "<itemData name='a3' defStyleNum='dsChar'/>" +

                            "<itemData name='a4' defStyleNum='dsKeyword'/>" +
                            "</itemDatas>" +
                            "</highlighting>" +
                            "<general>" +
                            "<keywords/>" +
                            "</general>" +
                            "</language>", raw.ToString());
        }
Esempio n. 5
0
        public void PrefixContexts()
        {
            XmlDocument xml = new XmlDocument();

            xml.LoadXml(@"<?xml version='1.0' encoding='UTF-8'?>
				<language name='test' extensions='*.test'>
				    <highlighting>
				        <list name='keywords0'>
				            <item>word0</item>
				            <item>word1</item>
				        </list>
				        <contexts>
				            <context attribute='a0' lineEndContext='#stay' name='Normal'>
				                <keyword attribute='a1' context='#stay' String='keywords0'/>
								<IncludeRules context='IncludeContext'/>
								<IncludeRules context='##Syntax file'/>
				            </context>
							<context attribute='a2' lineEndContext='#stay' name='IncludeContext'>
								<StringDetect attribute='a3' context='#pop!State name1' String='include'/>
							</context>
							<context attribute='a2' lineEndContext='State name2' name='State name1'>
								<StringDetect attribute='a3' context='#pop!State name1' String='include'/>
							</context>
				        </contexts>
				        <itemDatas>
				            <itemData name='a0' defStyleNum='dsNormal'/>
				            <itemData name='a1' defStyleNum='dsKeyword'/>
				            <itemData name='a2' defStyleNum='dsDataType'/>
				            <itemData name='a3' defStyleNum='dsChar'/>
				        </itemDatas>
				    </highlighting>
				</language>"                );
            Raw raw = Raw.Parse(xml);

            Raw.PrefixContexts(raw, "prefix_");
            Assert.AreEqual("<language>" +
                            "<highlighting>" +
                            "<list name='prefix_keywords0'>" +
                            "<item>word0</item>" +
                            "<item>word1</item>" +
                            "</list>" +
                            "<contexts>" +
                            "<context name='prefix_Normal' attribute='prefix_a0' lineEndContext='#stay'>" +
                            "<keyword attribute='prefix_a1' context='#stay' String='prefix_keywords0'/>" +
                            "<IncludeRules context='prefix_IncludeContext'/>" +
                            "<IncludeRules context='##Syntax file'/>" +
                            "</context>" +
                            "<context name='prefix_IncludeContext' attribute='prefix_a2' lineEndContext='#stay'>" +
                            "<StringDetect attribute='prefix_a3' context='#pop!prefix_State name1' String='include'/>" +
                            "</context>" +
                            "<context name='prefix_State name1' attribute='prefix_a2' lineEndContext='prefix_State name2'>" +
                            "<StringDetect attribute='prefix_a3' context='#pop!prefix_State name1' String='include'/>" +
                            "</context>" +
                            "</contexts>" +
                            "<itemDatas>" +
                            "<itemData name='prefix_a0' defStyleNum='dsNormal'/>" +
                            "<itemData name='prefix_a1' defStyleNum='dsKeyword'/>" +
                            "<itemData name='prefix_a2' defStyleNum='dsDataType'/>" +
                            "<itemData name='prefix_a3' defStyleNum='dsChar'/>" +
                            "</itemDatas>" +
                            "</highlighting>" +
                            "<general>" +
                            "<keywords/>" +
                            "</general>" +
                            "</language>", raw.ToString());
        }