[MonoDevelop] Ideas for enforcing an XML schema? (syntax highlighting)

Joshua Granick bulkmail at joshuagranick.com
Tue Apr 10 21:36:02 UTC 2012


Hi!

I'm working on a custom syntax mode for an XML-based file format.

It would be great to be able to highlight when you've used valid nodes and  
attributes. The normal XML syntax mode will highlight any node name or  
attribute, but I'd like to be more specific.

In the original, it looks like this:

	<Span color = "text.markup" rule = "InTag">
		<Begin><</Begin>
		<End>></End>
	</Span>
	
	<Rule name = "InTag">
		<Span color = "string" rule="InLiteral">
			<Begin>"</Begin>
			<Exit><</Exit>
			<End>"</End>
		</Span>
		
		<Span color = "string" rule="InLiteral">
			<Begin>'</Begin>
			<Exit><</Exit>
			<End>'</End>
		</Span>
		
		<!-- attributes -->
		<Match color =  
"keyword.type">[A-Za-z0-9_]+(:[A-Za-z0-9_]+)?[\s\n\r]*=</Match>
	</Rule>


I've sort of been able to make it work, but it feels like there must be a  
more elegant way to handle it?


	<Span color="text.markup" rule="InMetaNode">
		<Begin><meta</Begin>
		<End>></End>
	</Span>
	<Rule name="InMetaNode">
		<Span color = "string" rule="InLiteral">
			<Begin>"</Begin>
			<Exit><</Exit>
			<End>"</End>
		</Span>
		<Span color = "string" rule="InLiteral">
			<Begin>'</Begin>
			<Exit><</Exit>
			<End>'</End>
		</Span>
		<Keywords color="keyword.type">
			<Word>if</Word>
			<Word>unless</Word>
			<Word>title</Word>
			<Word>description</Word>
			<Word>package</Word>
			<Word>version</Word>
			<Word>company</Word>
		</Keywords>	
	</Rule>


The problem is that the string rules are duplicated across every single  
custom node I define. I'm also not able to use a nice "Oops! Wrong  
attribute or node name!" color (like black plain text) because invalid  
attributes and node names currently have the same color as (in this case)  
the "<meta" and "=" throughout the tag.

Is it possible to stack rules, or using the standard "InTag" rule, is  
there any way to check for the first keyword, then to allow separate sets  
of keywords from that point on inside the node?

Thank you!


More information about the Monodevelop-list mailing list