Tapatalk

Function list with group for switch() statements and their cases

Function list with group for switch() statements and their cases

2
NewbieNewbie
2

    Jun 09, 2010#1

    I am trying to create a function list entry for PHP files. I would like to detect switch() statements and list each case involved. Here is a sample of the syntax:

    Code: Select all

    switch ($myvar) {
      case 1: 
        // code for $myvar=1 goes here
        break;
      case 2:
      case 3:
        // code for $myvar=2 or $myvar=3 goes here
        break;
      case 'string':
        // code for $myvar='string' goes here
        break;
      default:
        // this may or may not be here, and I do not want it listed
        break;
    }
    I have been able to detect the switch() line, but none of my attempts at detecting the case lines as a subgroup have worked. I'm certain I am doing this wrong, and the help section is of little use until it is properly updated. Can anyone point me in right direction?

    6,685587
    Grand MasterGrand Master
    6,685587

      Jun 09, 2010#2

      I do not really understand why many users want now something in the function list for program source files which are not functions.

      However, copy and paste following lines into your wordfile for PHP below last /TGEnd line and you should see the switch statements with their cases in the function list.

      Code: Select all

      /TGBegin "Switches"
      /TGFindStr = "%[ ^t]++switch[ ^t]++( ++^(*^))"
      /TGBegin "Cases"
      /TGFindStr = "[ ^t]+case[ ^t]+^(*^):"
      /TGFindBStart = "{"
      /TGFindBEnd = "}"
      /TGEnd
      /TGEnd
      The regular expression syntax here is UltraEdit as used for default php.uew.

      To edit the correct wordfile, open a PHP file, set cursor inside a PHP section, open Advanced - Configuration - Editor Display - Syntax Highlighting and you will see the wordfile used to highlight PHP files respectively PHP sections in HTML/XHTML files having just the extension PHP. Click on button Open to open this wordfile and close the configuration dialog with button Cancel. After pasting above lines into the wordfile and saving it, set focus the PHP file and if necessary press key F8 (by default assigned to Search - Function List) to update the function list.

      BTW: The regular expressions above work also for C/C++, Javascript and similar programming languages with using the UltraEdit regular expression engine for function list in the appropriate wordfile.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Jun 13, 2010#3

        Mofi wrote:I do not really understand why many users want now something in the function list for program source files which are not functions.
        With the new editing capabilities for the function list, it is not so much just a function list anymore. It can be configured to pick up easy-to-find bookmarks of all types, automatically. For example, in this particular case, I'm writing an AJAX handler for an application. It will be handling calls from many different sections of my application, and each case indicates a different handler. Instead of bookmarking each case manually, the function list can update automatically as I add/change/delete them. I also use a specific comment tag to mark areas of my application for further development or future edits. The function list makes it incredibly easy to keep track of these comments without having to rely on a manual grep of the file. Innovation is the result of using established technology in new and unexpected ways.
        Mofi wrote:copy and paste following lines into your wordfile
        That worked. My mistake was putting the BStart and BEnd ('{' and '}') on the switch, not the case...a little counterintuitive, but I'll work with it. My version also picks up the 'switch'/'case' keyword, but it is encouraging to find I was on the right track. :) There are some issues with recursion, though. In the scenario of a case containing another switch, the child switch's cases appear in the parent's switch's list, and again in the child switch's listing. There's not much to be done about it, I think, unless the function list can account for proper tab spacing.

        Thanks much for your assistance.