NAnt Wordfile - XML Syntax

Syntax highlighting, code folding, brace matching, code indenting, and function list

NAnt Wordfile - XML Syntax

Postby THEMike » Fri Dec 01, 2006 8:48 am

Hi,

I'm trying to set up a word file for the NAnt build file xml format.

I want to have it behave as XML in ultraedit, but, to also be different to XML in it's highlighting and keywords etc.

Now, IIRC, the recent changes to syntax highlighting in Ultraedit prevent you having more than one XML_LANG or HTML_LANG, so I can't do this?

I'm afraid I haven't (Yet) had time to do any experimenting with this, can anyone offer any advice as to a generic approach, or provide a full latest nant build file that recognises all the nant tasks?
User avatar
THEMike
Basic User
Basic User
 
Posts: 15
Joined: Mon Nov 01, 2004 12:00 am
Location: UK

Re: Different wordfiles for different XML files

Postby Mofi » Fri Dec 01, 2006 11:16 am

First more than 1 XML_LANG should be possible with a File Names = definition.

But better is to use a project/workspace where you can add your XML files which need a different XML highlighting definition and use a project specific wordfile - a second wordfile which contains a different XML highlighting definition. Whenever you load this project/workspace, the XML files are highlighted with this alternate wordfile. When you close the project/workspace the main wordfile becomes active again.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4040
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: NAnt Wordfile - XML Syntax

Postby THEMike » Tue Dec 05, 2006 2:46 pm

Ok here is a clip of word file:

Code: Select all
/L12"NAnt" XML_LANG Noquote Block Comment On = <!-- Block Comment Off = --> File Extensions = build
/Delimiters = ~@$%^&*()+=|\{};"'<> ,
/Function String = "name=*">"
/Open Brace Strings =  "{" "(" "[" "<"
/Close Brace Strings = "}" ")" "]" ">"
/C1"Elements" STYLE_ELEMENT
<code </code


However, the element <code> does not highlight (but <code name="fish">blah</code> does highlight the first code but not the closing code...

Suggestions?
User avatar
THEMike
Basic User
Basic User
 
Posts: 15
Joined: Mon Nov 01, 2004 12:00 am
Location: UK

Re: NAnt Wordfile - XML Syntax

Postby Mofi » Wed Dec 06, 2006 7:57 am

Look at the default wordfile.txt at language HTML (for example LI). There you will see that you have to specify all possible variants of an element which are according to your example:

<code> <code </code>
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4040
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: NAnt Wordfile - XML Syntax

Postby THEMike » Wed Dec 06, 2006 12:33 pm

hmm that is somewhat unfortunate.

Thanks for the help, I now have a NAnt buildfile that builds an ultraedit wordfile for NAnt buildfiles based on your specific NAnt configuration.

Recursively lovely.
User avatar
THEMike
Basic User
Basic User
 
Posts: 15
Joined: Mon Nov 01, 2004 12:00 am
Location: UK

Re: NAnt Wordfile - XML Syntax

Postby PaoloFCantoni » Wed Dec 06, 2006 5:09 pm

That should be interesting.

If it's not too long, can you post it here or provide a link/

TIA,
Paolo
User avatar
PaoloFCantoni
Power User
Power User
 
Posts: 113
Joined: Sun May 01, 2005 11:00 pm
Location: Perth, Western Australia

Re: NAnt Wordfile - XML Syntax

Postby THEMike » Fri Mar 16, 2007 2:23 pm

Sorry, meant to post this some time back, I've tried to attach but I get:

Code: Select all
Upload Error: Could not upload Attachment to ./uploads/forums/wordfile.rar.


So here is the code itself (128 lines, not too big)

Code: Select all
<?xml version="1.0"?>
<project name="Ultraedit Wordfile Builder" default="buildwordfile">
    <property name="wordfile.txt" value="wordfile.nant.txt" overwrite="false" />

    <target name="buildwordfile">
      <script language="C#" prefix="ue">
        <imports>
          <import namespace="System.Collections.Generic"/>
          <import namespace="System.IO"/>
          <import namespace="System.Text"/>
          <import namespace="System.Xml" />
        </imports>
        <code>
            <![CDATA[
              [TaskName("wordfile")]
              public class WordfileTask : Task {
                #region Private Instance Fields
                    private string _wordfile="wordfile.txt";
                    private string _xsd="nant.xsd";
                    private string _message;

                    private SortedDictionary<String, String> elements = new SortedDictionary<String, String>();
                    private SortedDictionary<String, String> attributes = new SortedDictionary<String, String>();
                #endregion Private Instance Fields

                #region Private methods
                private void parseXSD()
                {
                  XmlDocument d = new XmlDocument();
                  d.Load(_xsd);
                  XmlNamespaceManager ns = new XmlNamespaceManager(d.NameTable);
                  ns.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
                  Console.WriteLine("boo");
                  XmlNodeList l = d.DocumentElement.SelectNodes("//xs:element", ns);
                  foreach(XmlNode n in l)
                  {
                      if (!elements.ContainsKey(n.Attributes["name"].Value.ToString()))
                      {
                          elements.Add(n.Attributes["name"].Value.ToString(), n.Attributes["name"].Value.ToString());
                      }
                  }
                  l = d.DocumentElement.SelectNodes("//xs:attribute", ns);
                  foreach (XmlNode n in l)
                  {
                      if (!attributes.ContainsKey(n.Attributes["name"].Value.ToString()))
                      {
                          attributes.Add(n.Attributes["name"].Value.ToString(), n.Attributes["name"].Value.ToString());
                      }
                  }
                }

                private void writeWordfile()
                {
                  StreamWriter s = new StreamWriter("wordfile.txt");
                  s.WriteLine("/L13\"NAnt\" XML_LANG Noquote Block Comment On = <!-- Block Comment Off = --> File Extensions = build");
                  s.WriteLine("/Delimiters = ~@$%^&*()+=|\\{};\"'<> ,");
                  s.WriteLine("/Function String = \"name=*\">\"");
                  s.WriteLine("/Open Brace Strings =  \"{\" \"(\" \"[\" \"<\"");
                  s.WriteLine("/Close Brace Strings = \"}\" \")\" \"]\" \">\"");
                  s.Write("/C1\"Elements\" STYLE_ELEMENT");
                  char c = '\0';
                  foreach(KeyValuePair<String,String> st in elements)
                  {
                      if (st.Value.IndexOf(c) != 0)
                      {
                          c = st.Value.ToCharArray()[0];
                          s.WriteLine("");
                      }
                      s.Write("<" + st.Value + " </" + st.Value + " <" + st.Value + "> </" + st.Value + "> ");
                  }
                  s.WriteLine("\n// />");
                  s.WriteLine(">");
                  s.WriteLine("<");
                  s.WriteLine("<%");
                  s.WriteLine("%>");
                  s.WriteLine("?>");
                  s.WriteLine("<? <?xml");
                  s.WriteLine("]]>");
                  s.WriteLine("<![CDATA[");
                  s.Write("/C2\"Attributes\" STYLE_ATTRIBUTE");
                  s.Flush();
                  foreach (KeyValuePair<String, String> st in attributes)
                  {
                      if (st.Value.IndexOf(c) != 0)
                      {
                          c = st.Value.ToCharArray()[0];
                          s.WriteLine("");
                          s.Flush();
                      }
                      s.Write(st.Value + "= ");
                  }
                  s.Close();

                }

                #endregion Private methods

                #region Public Instance Properties

                [TaskAttribute("wordfilePath", Required=true)]
                public string FileName {
                  get { return _wordfile; }
                  set { _wordfile = value; }
                }

                [TaskAttribute("xsdPath", Required=true)]
                public string XsdPath {
                  get { return _xsd; }
                  set { _xsd = value; }
                }

                #endregion Public Instance Properties

                #region Override implementation of Task

                protected override void ExecuteTask() {
                  parseXSD();
                  writeWordfile();
                }
                #endregion Override implementation of Task
              }
            ]]>
        </code>
      </script>
      <nantschema output="NAnt.xsd"/>
      <wordfile wordfilePath="wordfile.txt" xsdPath="NAnt.xsd" />
    </target>
</project>
User avatar
THEMike
Basic User
Basic User
 
Posts: 15
Joined: Mon Nov 01, 2004 12:00 am
Location: UK

Re: NAnt Wordfile - XML Syntax

Postby PaoloFCantoni » Sat Mar 17, 2007 6:33 am

Thanx, (forgotten I'd asked for it :) )

Lookz Kool!

Paolo
User avatar
PaoloFCantoni
Power User
Power User
 
Posts: 113
Joined: Sun May 01, 2005 11:00 pm
Location: Perth, Western Australia


Return to Syntax Highlighting