tim laqua dot com Thoughts and Code from Tim Laqua

8Mar/096

Notepad++ User Defined Language file for MDX Syntax Highlighting

Following up on my previous post for GeSHi MDX Syntax Highlighting, here is a version for Notepad++. The only real issue I ran in to here is that the Nodepad++ User Language Definition system only allows two sets of boundary open/boundry close characters. One has to be square brackets - [...] - for MDX, and the other here would be a string delimiter. This means only one string delimiter can be used at a time (because the square brackets took up the first slot) and I went with single quotes. If you use double-quotes in your MDX rather than single quotes, you may want to switch the Delimiters element from:

            <Keywords name="Delimiters">[&apos;0]&apos;0</Keywords>

to:

            <Keywords name="Delimiters">[&quot;0]&quot;0</Keywords>

If you don't have any existing user defined languages, you can simply download the following file and put it in the appropriate location. The appropriate location will vary depending on if you're using %APPDATA% or not. If you are using %APPDATA%, the location will be %APPDATA%\Notepad++

If you're not using %APPDATA%, the location is the Program Files folder for Notepad++ - usually something like C:\Program Files\Notepad++.

Download: userDefineLang.xml

If you already have existing user defined languages, you will need to edit your current userDefineLang.xml file and add the following UserLang node to your file (NodepadPlus is the root node - you only want to add in the UserLang node):

<NotepadPlus>
    <UserLang name="MDX" ext="mdx">
        <Settings>
            <Global caseIgnored="yes" />
            <TreatAsSymbol comment="no" commentLine="no" />
            <Prefix words1="yes" words2="yes" words3="yes" words4="yes" />
        </Settings>
        <KeywordLists>
            <Keywords name="Delimiters">[&apos;0]&apos;0</Keywords>
            <Keywords name="Folder+">SELECT</Keywords>
            <Keywords name="Folder-">FROM</Keywords>
            <Keywords name="Operators">- ( ) * , . / : ; { | } + &lt; = &gt;</Keywords>
            <Keywords name="Comment">1/* 2*/ 0// 0--</Keywords>
            <Keywords name="Words1">WHERE COLUMNS ROWS NON EMPTY AS ON CALCULATE CASE EXISTING FREEZE IF SCOPE ALTER CUBE CREATE ACTION CELL CALCULATION GLOBAL WITH MEMBER SESSION SET SUBCUBE DROP SUBCUBE REFRESH CALL CLEAR CALCULATIONS DRILLTHROUGH UPDATE SetToArray This Leaves Current Item Root StrToTuple Error Hierarchy Dimension Dimensions Level Levels IsAncestor IsEmpty IsGeneration IsLeaf IsSibling CalculationPassValue CoalesceEmpty Generate IIf LookupCube MemberToStr Name Properties SetToStr TupleToStr UniqueName UserName</Keywords>
            <Keywords name="Words2">Aggregate Avg CalculationCurrentPass CalculationPassValue CoalesceEmpty Correlation Count Covariance CovarianceN DistinctCount IIf LinRegIntercept LinRegPoint LinRegR2 LinRegSlope LookupCube Max Median Min Ordinal Predict Rank RollupChildren Stddev StddevP StrToValue Sum Value Var Variance VarianceP VarP&#x0009;&#x0009;</Keywords>
            <Keywords name="Words3">AllCalculatedMembers AllMembers Ancestors Ascendants Axis BottomCount BottomPercent BottomSum Children Crossjoin CurrentOrdinal Descendants Distinct DrilldownLevel DrilldownLevelBottom DrilldownLevelTop DrilldownMember DrilldownMemberBottom DrilldownMemberTop DrillupLevel DrillupMember Except Exists Extract Filter Generate Head Hierarchize Intersect LastPeriods Members Mtd NameToSet NonEmptyCrossjoin Order PeriodsToDate Qtd Siblings StripCalculatedMembers StrToSet Subset Tail ToggleDrillState TopCount TopPercent TopSum Union Unorder VisualTotals Wtd Ytd</Keywords>
            <Keywords name="Words4">Ancestor ClosingPeriod Cousin CurrentMember DataMember DefaultMember FirstChild FirstSibling Item Lag LastChild LastSibling Lead LinkMember NextMember OpeningPeriod ParallelPeriod Parent PrevMember StrToMember UnknownMember ValidMeasure</Keywords>
        </KeywordLists>
        <Styles>
            <WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" fontName="Courier New" fontStyle="0" />
            <WordsStyle name="FOLDEROPEN" styleID="12" fgColor="0000FF" bgColor="FFFFFF" fontName="Courier New" fontStyle="1" />
            <WordsStyle name="FOLDERCLOSE" styleID="13" fgColor="0000FF" bgColor="FFFFFF" fontName="Courier New" fontStyle="1" />
            <WordsStyle name="KEYWORD1" styleID="5" fgColor="0000FF" bgColor="FFFFFF" fontName="Courier New" fontStyle="1" />
            <WordsStyle name="KEYWORD2" styleID="6" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="KEYWORD3" styleID="7" fgColor="804000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="KEYWORD4" styleID="8" fgColor="804000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="COMMENT" styleID="1" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="COMMENT LINE" styleID="2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="NUMBER" styleID="4" fgColor="800040" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="OPERATOR" styleID="10" fgColor="000000" bgColor="FFFFFF" fontName="Courier New" fontStyle="1" />
            <WordsStyle name="DELIMINER1" styleID="14" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="DELIMINER2" styleID="15" fgColor="6C6C6C" bgColor="FFFFFF" fontName="Courier New" fontStyle="1" />
            <WordsStyle name="DELIMINER3" styleID="16" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
        </Styles>
    </UserLang>
</NotepadPlus>
Comments (6) Trackbacks (0)
  1. Thank you for sharing this information. I am trying to implement a very similar syntax highlighting with Notepad++ but I get a strange error. My code is almost exactly like yours, but here’s what happens:

    Using forward slash as an operator makes the forward slash NOT WORK as the start of a comment. My configuration is just like yours, but the comments don’t work. Every use of the forward slash is interpreted as an operator.

    Does this happen in your Notepad++?

    • Can you include a link to your UserLang node and a sample of whatever language this is for?

      • The language is called LassoScript or Lasso, it’s a proprietary middleware for tying together web pages, databases, and so on, and has its own scripting syntax. Here are some short pieces of code that shows the problem:

        // This should be a comment
        /* This should also be a comment */

        // Simple conditional statement
        if($condition == ‘true’;
        ‘Do this thing’;
        /if;

        // Simple looping contstruct
        loop(3);
        ‘Do this three times’;
        /loop;

        The forward slash is used for comments, but also to signify a closing tag. This causes a problem for Notepad++.

        Here are some links to sample files. One is a code sample. One is my Notepad++ syntax file. It is not filled in with all the possible keywords, since I have just started to get it going. The last file is a small screencap of what my Notepad++ does with those two files mentioned. The links below are temporary, I hope this doesn’t mess up your web page.

        http://members.cox.net/mikeoscrope/temp/userDefineLang.xml
        http://members.cox.net/mikeoscrope/temp/99_bottles_of_root_beer.lasso
        http://members.cox.net/mikeoscrope/temp/notepad++_result.png

        http://en.wikipedia.org/wiki/Lasso_programming_language

        • Yeah, just define the closing tags as keywords and take the / out of operators. The following node works for your example for the if and loop blocks.
          <KeywordLists>
          <Keywords name="Delimiters">&apos;00&apos;00</Keywords>
          <Keywords name="Folder+"></Keywords>
          <Keywords name="Folder-"></Keywords>
          <Keywords name="Operators">- ! &amp; ( ) , ; ? [ ] | + &lt; = &gt;</Keywords>
          <Keywords name="Comment">1/* 2*/ 0//</Keywords>
          <Keywords name="Words1">var local include return map array pair true false fail abort email_send action_param valid_email string_replaceregexp redirect_url loop_count</Keywords>
          <Keywords name="Words2">$ #</Keywords>
          <Keywords name="Words3">if /if else protect iterate loop /loop define_tag handle_error</Keywords>
          <Keywords name="Words4">trim size substring insert find input removeall</Keywords>
          </KeywordLists>

          • Yeah that works. There are not that many tags that have to be closed, so it won’t clutter things too much. It’s probably the best solution, so thanks for the feedback.

            What confuses me though is that in your example above you show the exact same setup. You have a forward slash as an operator, and also as the start of two kinds of comments. Does this cause problems for you? Just curious if mine’s different.

  2. Great file…..thanks so much.


Leave a comment

No trackbacks yet.