[MonoDevelop] Ideas for enforcing an XML schema? (syntax highlighting)
Michael Hutchinson
m.j.hutchinson at gmail.com
Fri Apr 13 15:46:57 UTC 2012
On 10 April 2012 17:36, Joshua Granick <bulkmail at joshuagranick.com> wrote:
> 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?
I'm not very familiar with this, but it might be better to have a
"semantic syntax mode" like C# does, which could perform more advanced
highlighting based on a schema.
Or alternatively, how about extending the existing XML background
parser - which generates underlines for syntax errors - to use the
code completion schema to underline invalid elements/attributes?
--
Michael Hutchinson
http://mjhutchinson.com
More information about the Monodevelop-list
mailing list