Simple Syntax Highlighting

Simple Syntax Highlighting

mam2005

    Jul 07, 2005#1

    I am using UltraEdit to edit some data files. To make editing for others easier I would like to leverage syntax highlighting. The data files have tags throughout the data. The tags are formatted like [A] or [PF *] and so on. I want to sytanx highlight [ to ]. I have been trying to edit the wordfile.txt file to create a new language entry called data. I know I am missing something simple and could use some help.

    Just some additional information. Here is an example of the data I am working with:
    [LN]Allmendinger [N]Chad [A]675 117 Av SW [C]Mnng [Z]58642 [P] 863 3333

    I am just looking to have the [LN], [N], [A], [C], [Z], and [P] be turned blue and leave the rest of the text black. So far all I can get to work is having the [ and the one or two letters turning blue. I cannot get the ] to turn blue with the rest of the tag.

    61
    Advanced UserAdvanced User
    61

      Jul 07, 2005#2

      A shot in the dark ... have you tried defining "[" and "]" as block comment delimiters?

      6,675585
      Grand MasterGrand Master
      6,675585

        Jul 08, 2005#3

        Use this

        /L20"Data files" Nocase Noquote File Extensions = DAT
        /Delimiters = ! " %&'()*+,-./:;<=>?@[\]^{|}~
        /Marker Characters = "[]"
        /C1"Tags"
        []


        or this

        /L20"Data files" Nocase Noquote Block Comment On = [ Block Comment Off = ] File Extensions = DAT
        /Delimiters = ! " %&'()*+,-./:;<=>?@[\]^{|}~
        Best regards from an UC/UE/UES for Windows user from Austria

        mam2005
        mam2005

          Jul 11, 2005#4

          Sorry for the slow reply to your solution. That worked just great.
          Thank you.

          2
          NewbieNewbie
          2

            Mar 15, 2006#5

            Sorry to dig up an old thread but since my issue related pretty near exactly to the original question I thought it best to reopen this thread instead of open a new one. I play an online game called Kingdom of Loathing. There is a program called KOLMafia that automates various game activities and has its own scripting language similar to javascript. I've come up with a wordfile entry for this program's scripting language that does almost everything I want it to except for my questions below. First, here is the wordfile entry:

            Code: Select all

            /L10"KOLMafia ASH" Line Comment = // File Extensions = ASH 
            //Marker Characters = "[]"
            /Delimiters = !@%^&*()-+=|/{}[\];" ,	.?
            /Function String = "%^{boolean^}^{float^} [a-zA-Z]*(*)*"
            /Function String 1 = "%^{int^}^{string^} [a-zA-Z]*(*)*"
            /Function String 2 = "%^{void^}^{class^} [a-zA-Z]*(*)*"
            /Function String 3 = "%^{effect^}^{familiar^} [a-zA-Z]*(*)*"
            /Function String 4 = "%^{item^}^{location^} [a-zA-Z]*(*)*"
            /Function String 5 = "%^{skill^}^{stat^} [a-zA-Z]*(*)*"
            /Indent Strings = "{" "else"
            /Unindent Strings = "}" "else"
            /C1"Keywords"
            $class $effect $familiar $item $location $skill $stat $zodiac
            boolean 
            class
            effect else 
            familiar false float
            if import int item
            location
            return
            skill stat string
            true
            void
            while
            zodiac
            /C2"Object References"
            [ 
            ]
            /C3"ASH functions"
            adventure add_item_condition
            boolean_to_string bounty_hunter_wants buy
            can_eat can_drink can_interact class_to_string cli_execute closet_amount council create
            effect_to_string equip equip_familiar
            familiar_to_string float_to_string
            have_bartender have_chef have_effect have_skill
            int_to_string item_amount item_to_string
            location_to_string
            mind_control museum_amount my_adventures my_basestat my_buffedstat my_class my_closetmeat my_familiar my_hp my_inebriety 
            my_level my_maxhp my_maxmp my_meat my_mp my_name my_zodiac
            print put_closet put_shop put_stash
            shop_amount skill_to_string stash_amount stat_to_string storage_amount
            take_closet take_storage trade_bounty_hunter trade_hermit trade_trapper
            unequip use use_skill
            zodiac_to_string
            /C4"Operators"
            !
            %
            &&
            *
            +
            -
            // /
            <
            =
            >
            ||
            /C5"Separators"
            (
            )
            ,
            ;
            {
            }
            [
            ]
            Question 1:
            I'd like to be able to highlight everything in between the [ and ] brackets in a non-comment color. I can get the actual brackets highlighted but not the contained text (which may include spaces). I've tried the first suggestion you posted above but it did not highlight the contents.

            Question 2:
            This particular scripting language has a function syntax of:

            returntype functionname( paramtype1 paramName1, etc..)

            and you can see how I implemented checking for functions, but it only left me options for 12 different prefixes for function return types. Is there any way to string together the ^{prefix1^} expressions or is it limited to just 2 at a time?

            You can grab a copy of the file I'm editing here. The name of the file is Ascension.ash, and its in plain text format. It is not a windows executable file or script.

            By the way, this tool is absolutely the best editor I've ever used. I'm incredibly impressed with how versatile the options are. Keep up the great work!

            6,675585
            Grand MasterGrand Master
            6,675585

              Mar 15, 2006#6

              Hi cjswimmer!

              Question 1:

              1) Move the line

              //Marker Characters = "[]" to the position before the line /Indent Strings = and remove first /. You have added the marker characters definition with // which is 1 / too much. That's the reason why it has not worked.

              2) Convert your

              /C2"Object References"
              [
              ]


              to

              /C2"Object References"
              []

              It's important that the marker characters are defined as string in a color group and not as single characters. This is an exception from the standard rule for keywords.

              3) At /C5"Separators" delete the lines with [ and ].


              Question 2:

              No, more than 2 words for OR expression is not possible. I suggest to define the function string for your functions a bit more flexible like the function strings are for C/C++. Ignore the type names before the function name. In your example file I could see that the functions are called by functioname(..); So a single function string could be used.

              Solution 1:
              /Function String = "%[ ^t]++[a-z]+[ ^t]+^([a-z_]+^)[ ^t]++(*)[~;]"

              % ... start of the line.

              [ ^t]++ ... 0 or more occurences of a space and/or tab. You could also remove this part of the expression because I have not seen a function definition with preceding spaces in your example files.

              [a-z]+ ... a string with a least 1 character which has only letters a-z in any case. Instead of a-z you could also specify only the letters which really exist in all return types.

              [ ^t]+ ... 1 or more occurences of a space and/or tab.

              ^([a-z_]+^) ... the function name which is shown in the function list. You have forgotten the underscore in your expressions.

              [ ^t]++ ... 0 or more occurences of a space and/or tab. You could also remove this part of the expression because I have not seen a function definition with spaces between function name and opening ( in your example files.

              (*) ... a string of any length enclosed in round brackets.

              [~;] ... after closing ) the next character can be any character (space, CR, LF, ...) except a semicolon. If you have never have trailing spaces or a comment following a function definition you could also use a single $ instead of [~;] to specify that the closing ) must be at the end of a line.


              Solution 2:
              /Function String = "%[ ^t]++[a-z]+[ ^t]+^([a-z_]+[ ^t]++(*)^)[~;]"

              Similar to solution 1 but now the function name and also the parameters are displayed in the function list.


              And last you should add Strings = " DisableMLS after Line Comment // in the language definition line.

              A single ' is often used in your examples but do not specify a string. So Strings = " defines only the double quote character as valid string character. DisableMLS disables multi-line string highlighting. In your examples I have not seen a multi-line string definition in your examples so it's better to disable it to not highlight everything from current cursor position to next " in the file if you start to enter a new string with entering ".

              The whole modified language definition. Add the tab character to the delimiters again if you copy this text from your browser because it is replaced by HTML with a single space:

              /L10"KOLMafia ASH" Line Comment = // Strings = " DisableMLS File Extensions = ASH
              /Delimiters = !@%^&*()-+=|/{}[\];" , .?
              /Function String = "%[ ^t]++[a-z]+[ ^t]+^([a-z_]+^)[ ^t]++(*)[~;]"
              /Marker Characters = "[]"
              /Indent Strings = "{" "else"
              /Unindent Strings = "}" "else"
              /C1"Keywords"
              $class $effect $familiar $item $location $skill $stat $zodiac
              boolean
              class
              effect else
              familiar false float
              if import int item
              location
              return
              skill stat string
              true
              void
              while
              zodiac
              /C2"Object References"
              []
              /C3"ASH functions"
              adventure add_item_condition
              boolean_to_string bounty_hunter_wants buy
              can_eat can_drink can_interact class_to_string cli_execute closet_amount council create
              effect_to_string equip equip_familiar
              familiar_to_string float_to_string
              have_bartender have_chef have_effect have_skill
              int_to_string item_amount item_to_string
              location_to_string
              mind_control museum_amount my_adventures my_basestat my_buffedstat my_class my_closetmeat my_familiar my_hp my_inebriety
              my_level my_maxhp my_maxmp my_meat my_mp my_name my_zodiac
              print put_closet put_shop put_stash
              shop_amount skill_to_string stash_amount stat_to_string storage_amount
              take_closet take_storage trade_bounty_hunter trade_hermit trade_trapper
              unequip use use_skill
              zodiac_to_string
              /C4"Operators"
              !
              %
              &&
              *
              +
              -
              // /
              <
              =
              >
              ||
              /C5"Separators"
              (
              )
              ,
              ;
              {
              }
              Best regards from an UC/UE/UES for Windows user from Austria

              2
              NewbieNewbie
              2

                Mar 17, 2006#7

                That worked perfectly! Thanks so much for the quick response and for going above and beyone to actually write out the corrected wordlist file.

                1
                NewbieNewbie
                1

                  Mar 12, 2008#8

                  That was a kick ass write up thanks!