Adding Language Support 3: Function Tagging

Home Forums Multi-Edit User/Developer Additional Language/Compiler Support Adding Language Support 3: Function Tagging

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #2169

    Adding Language Support 3: Function Tagging

    To implement Function Tagging we need to add a macro in our language support file named <language-prefix>FindTag. For example, for AWK we need to add a macro in our Awk.s file named AwkFindTag. Attached is our updated Awk.s file containing our AwkFindTag macro. This macro can be used as a template for your own *FindTag macro.

    Below are notes on what you’ll need to change to convert this AwkFindTag macro into your own *FindTag macro.

    First you need to come up with a regular expression which will match everything you want to tag.

    The regular expression can contain Multi-Edit search aliases. [To see the aliases, open the Multi-Edit search dialog (e.g.SEARCH -> FIND) and click the ‘Alias’ button. All aliases start with < and end with >. Select one and click ‘Edit’ to see the definition. You may also add your own definitions.]

    You may create any supported type of regular expression:
    [code:zvqioa1p]_RegExp – UNIX style regular expression
    _OldExp – Multi-Edit classic style regular expression
    _PerlExp – Perl 5.8 regular expression[/code:zvqioa1p]
    The Find_Text line determines what type of regular expression is assumed. Here _RegExp is used, indicating a UNIX style regular expression:
    [code:zvqioa1p]while ( Found = Find_Text( FindStr, 0, SrchDir | _regExp ) ) {[/code:zvqioa1p]
    See the Multi-Edit documentation for more information on regular expressions.
    (RegexBuddy is a useful tool to help analyze and create regular expressions ([url:zvqioa1p][/url:zvqioa1p]). Note RegexBuddy makes Perl style regular expressions.)

    Here’s a simple UNIX style regular expression example which we’ll use for AWK. This regular expression matches all lines starting with the word "function":
    [code:zvqioa1p]FindStr = "^<b0>(function)<b1><a>";[/code:zvqioa1p][list:zvqioa1p][*:zvqioa1p]^ – beginning of line[/*:m:zvqioa1p]
    [*:zvqioa1p]<b0> – followed by zero or more whitespace characters (blanks,tabs)[/*:m:zvqioa1p]
    [*:zvqioa1p](function) – followed by the word "function"[/*:m:zvqioa1p]
    [*:zvqioa1p]<b1> – followed by one or more whitespace characters (blanks,tabs)[/*:m:zvqioa1p]
    [*:zvqioa1p]<a> – followed by an alphabetic character (the first letter of the function name)[/*:m:zvqioa1p][/list:u:zvqioa1p]
    Here’s a more complex example used for CMAC:
    [code:zvqioa1p]FindStr = "^<b0>" +
    "(macro_file<b1><vc><b0>;@)|" +
    "((macro)|(void)<b1><vc><b0>[^’\",]@[^;])|" +
    "((int)|(str)|(void)|(real)<b1><vc><b0>\\(<b0>[^;=]@[^;]@)" +
    You can see more examples by looking at all the *FindTag macros in the Multi-Edit src directory.

    2. Modify the following line:
    [code:zvqioa1p] str FindStr = "<TagAwk>";[/code:zvqioa1p]
    Change "Awk" to your language prefix. This line allows the user to easily supply her own regular expression to use instead of the one you provided. For Awk she can create her own alias <TagAwk>.

    3. Parse off the Object and TagId
    When the code finds a line containing a tag, we need to parse off the Object and the TagId.

    Object = function type. e.g. (int)|(str)|(void)|(real)
    TagId = the actual function name

    In the following example, str is the Object (function type), and AwkFindTag is the TagId (function name):
    [code:zvqioa1p]str AwkFindTag(
    int Tag = Parse_Int( "/TAG=", MParm_Str ),
    int SrchFwd = Parse_Int( "/F=", MParm_Str ),
    str ParmStr = MParm_Str
    ) trans2

    We also need to set TStr to a copy of the current line.

    Here is the code segment in AwkFindTag that does this. You’ll need to modify this as needed for your language.
    TStr = Copy( Get_Line( ), C_Col, 255 );
    Object = Get_Word( _c_whitespace );
    Forward_Till_Not( _c_whitespace );
    TagId = Get_Word( _c_whitespace + "({" );

    Adding this tag support macro for your language also allows the following keys/commands to work:[list:zvqioa1p][*:zvqioa1p]Goto Next Function[/*:m:zvqioa1p]
    [*:zvqioa1p]Goto Previous Function[/*:m:zvqioa1p]
    [*:zvqioa1p]Goto Previous Function (skip nested)[/*:m:zvqioa1p]
    [*:zvqioa1p]Show Current Function Name[/*:m:zvqioa1p][/list:u:zvqioa1p]

    Related Articles:

    (Additions to this Adding Language Support series are occasionally made as I have time.)

    Clay Martin

    Do you mean a unicode font set? Currently Multi-Edit’s unicode support is spotty, but we plan to change that for the next release.


    Hello there, I love your phorum . Is there something I can do to receive updates like a subscription or some thing? I am sorry I’m not acquainted with RSS?

    Clay Martin

    If you are not able to use rss, you can post against an interesting topic and if someone else posts, you will get an email.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.