Adding Language Support 4.2: Auto Construct Matching

Home Forums Multi-Edit User/Developer Additional Language/Compiler Support Adding Language Support 4.2: Auto Construct Matching

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2181
    deleyd
    Participant

    Adding Language Support 4.2: Auto Construct Matching

    We’ll now add the ability that when you type a closing parenthesis ")" Multi-Edit will automatically temporarily highlight the range to the corresponding open parenthesis. And we’ll do the same for a closing brace "]" and a closing bracket "}".

    First we need to make a dialog such as this:

    This dialog is found as follows:

      [*:1q1p0kxp]TOOLS -> CUSTOMIZE -> General(left side) -> LANGUAGES[/*:m:1q1p0kxp]
      [*:1q1p0kxp]Select "DBASE", click ‘Edit'[/*:m:1q1p0kxp]
      [*:1q1p0kxp]In the resulting "Language Setup" dialog, click ‘Formatting/Config’ (at lower right corner of dialog)[/*:m:1q1p0kxp][/list:o:1q1p0kxp]The checkboxes are:[list:1q1p0kxp][*:1q1p0kxp]Match language structure highlight — Temporarily highlight the range between the matching constructs when you ask Multi-Edit to find the matching construct.[/*:m:1q1p0kxp]
      [*:1q1p0kxp]Parenthesis closure highlight — Temporarily highlight the range between the corresponding open/close parenthesis () when you type a closing parenthesis.[/*:m:1q1p0kxp]
      [*:1q1p0kxp]Brace closure highlight — Temporarily highlight the range between the corresponding open/close braces [] when you type a closing brace.[/*:m:1q1p0kxp]
      [*:1q1p0kxp]Bracket closure highlight — Temporarily highlight the range between the corresponding open/close brackets {} when you type a closing bracket.[/*:m:1q1p0kxp][/list:u:1q1p0kxp]Note: The full range is highlighted only if it will all fit on the screen.

      Not all languages have a Properties Setup dialog. In the "Language Setup" dialog, on the right hand side in the Macros area, if the Config: field is blank, then there is no Properties Setup dialog for that language.

      Some languages have a Properties Setup dialog with more options. For example, have a look at the Properties Setup dialog for CMAC:

      [*:1q1p0kxp]TOOLS -> CUSTOMIZE -> General(left side) -> LANGUAGES [/*:m:1q1p0kxp][*:1q1p0kxp]Select "CMAC", click ‘Edit’ [/*:m:1q1p0kxp][*:1q1p0kxp]In the resulting "Language Setup" dialog, click ‘Formatting/Config’ (at lower right corner of dialog)[/*:m:1q1p0kxp][/list:o:1q1p0kxp]

      <lang>SetProperties Macro
      We need to create a Properties Setup macro called <lang>SetProperties, where <lang> is the prefix for the language. For Awk, we will create a macro named AwkSetProperties.

      Since Dbase already has what we want, we’ll just copy the DbaSetProperties macro from Dbase.s, change all references from Dba to Awk, and add the resulting AwkSetProperties macro to our Awk.s file.

      We also need to add some #include statements:
      [code:1q1p0kxp]#include c.sh //defines _c_whitespace as space, tab, or virtual space
      #include Dialog.sh
      #include DbTools.sh
      #include Language.sh
      #include MeTags.sh
      #include RegExp.sh
      [/code:1q1p0kxp]

      And we need to add this structure used to hold the results of our AwkSetProperites dialog. (This is just copied from Dbase.s, with all references to Dba changed to Awk.)
      [code:1q1p0kxp]// Awk language properties structure
      structure TAwkProperties {
      str Language;
      int Options;
      }
      #define _awk_prop_Options "/O="

      // Options flag constants
      #define _awk_opt_MatchHi 0x00000001
      #define _awk_opt_ParenHi 0x00000002
      #define _awk_opt_BraceHi 0x00000004
      #define _awk_opt_BracketHi 0x00000008

      // Dialog field constants
      #define id_MatchHiCB 1100
      #define id_ParenHiCB 1101
      #define id_BraceHiCB 1102
      #define id_BracketHiCB 1103
      [/code:1q1p0kxp]

      <lang>GetProperties Macro
      We also need to add a <lang>GetProperties macro (again where <lang> is the prefix for your language). We’ll just copy the DbaGetProperties macro from Dbase.s, change all references from Dba to Awk, and add the resulting AwkGetProperties macro to our Awk.s file.

      <lang>Init Macro
      Finally, we need to add some code to our <lang>Init macro. Recall in a previous lesson we created an AwkInit macro which did nothing. Now we’ll replace that AwkInit macro with DbaInit from Dbase.s and change all references from Dba to Awk.

      This code sets up the closing parenthesis key so it highlights the matching left parenthesis key if you checked the box for "Parenthesis closure highlight" in the Properties dialog above. The code then does the same for the closing bracket and brace.

      Awk4-2.s
      Our resulting Awk.s file is attached. Notice the order of the macros in the file. We want macros which get called go above macros which call them, so we don’t have to prototype them. Here I am just duplicating the standard order found in Dbase.s and all the other language specific support files.

      The macros we have added are:

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.