Problem with regular expression for functions in PowerBasic wordfile

Problem with regular expression for functions in PowerBasic wordfile

15
Basic UserBasic User
15

    Nov 01, 2014#1

    I use the Powerbasic wordfile and I find that if have a comment which includes the word 'sub' and an open bracket character somewhere in that line, that comment line shows up in the function list. for example, if I write

    For X& = 1 to 10
    'This comment will show up in the function list because I used the word sub and then used this ( open bracket.
    next x

    It's a bit annoying and I'm wondering if there is an easy fix? I understand the Regex would have to be altered, but I'm certainly no expert on Regex's, but figured somebody here might be able to assist. I also find that if I have an actual Sub, it won't recognise it unless I also put brackets after it, even when there are no parameters. I'm used to that and put them in my code, but it is a bit annoying if I'm getting code from elsewhere.

    6,682583
    Grand MasterGrand Master
    6,682583

      Nov 01, 2014#2

      Do you mean the user-contributed wordfile pbasic.uew? It contains a very simple UltraEdit regular expression string to find subroutines and functions.

      Code: Select all

      /Function String = "%*^{Sub^}^{Function^}*("
      This simple UE regular expression searches from beginning of a line for any character except carriage return or line-feed zero or more times containing either word sub or function and again any character except CR and LF 0 or more times in line containing also an opening parenthesis. The entire string found is displayed in the function list.

      I do not know anything about PowerBasic, but I'm quite sure that this UE regexp is a little bit too general.

      Is there somewhere an online documentation about PowerBasic syntax for subroutines and functions?

      It would be definitely no problem for me to improve the function string expression after reading the documentation about syntax for PowerBasic subroutines and functions.
      Best regards from an UC/UE/UES for Windows user from Austria

      15
      Basic UserBasic User
      15

        Nov 01, 2014#3

        Thanks Mofi, yes Pbasic.uew. Whilst I understand the basics (no pun intended) of Regex, I'm certainly no expert on the Syntax, so it's a bit tricky for me. I tried merging some things from the VB wordfile and QuickBasic wordfile, but it didn't work as intended. The ' character CHR$(39) or 27h is used to show a Comment, so anything past that up to the end of line CRLF is intended as a comment and should be excluded from being parsed further by the Regex. The keyword REM is also used exactly the same, though I prefer the apostrophe '.

        PowerBasic is an incredibly powerful and fast language. Most programmers look down on any BASIC, but PB is very different and right up there in terms of power, speed and executable size, you can even intermix inline Assembler. It has a Console Compiler version (PBCC) which is great for quick and dirty stuff and the full GUI version (PBWIN). The two use the same syntax for everything that they are able to do (obviously PB Win does more, so has more commands). The built-in string functions especially are extremely useful and super fast. It's a pity the guy who wrote it (who also wrote Turbo Basic and sold it to Borland) passed away a year or so ago. I love the language, but it has a terrible IDE, 20 years out of date (he obviously concentrated on the language, not the IDE!), so I write my programs using UE and then swap to PBCC or PBWin to do the compiling - I'd likely be better off with Ultra Studio, but that's another matter! For PB Win I use Firefly GUI designer, which has a much better IDE than PB's, though I still use UE for the heavy coding parts.

        The PowerBasic Help files have been replicated online here (PBCC) http://www.powerbasic.com/support/help/pbcc/index.htm and here (PBWin) http://www.powerbasic.com/support/help/pbwin/index.htm I'm not aware of a specific list of commands, though they are all there on those pages, just not in a set list. The SUB and FUNCTION are the commands that get messed up, but as a comment line, it should be ignoring them anyway! It also displays the "DECLARE xxx SUB / Function" in the F8 list, but that's not really much of an issue. I can't expect you do to anything, but whatever you can do would be appreciated.

        The examples for the REM statement is -
        x% = 10 : REM This is a comment
        y% = 20 ' This is another form of comment
        ! MOV EAX,"ABCD" ; An Inline Assembler comment (The ! at the start means it's an inline assembler line)

        Thanks for anything you may be able to offer :)

        6,682583
        Grand MasterGrand Master
        6,682583

          Nov 02, 2014#4

          Okay, I have read documentation for sub and function as well as for variables because of single/double character type.

          Please replace single line

          Code: Select all

          /Function String = "%*^{Sub^}^{Function^}*("
          by the 2 lines (can be displayed with more than 2 lines by the browser)

          Code: Select all

          /Regexp Type = Perl
          /Function String = "^[\t ]*(?:THREAD[\t ]+)?(?:SUB|FUNCTION)[\t ]+([a-z][a-z0-9]*)(?:&&|##|@@|[!#$%&?@])?(?:[\t ]+ALIAS[\t ]+".*?")?(?:[\t ]*(\((?:(?!')(?!\<REM\>).)*\)))?"
          This Perl regular expression finds subroutines and functions and display in function list
          • the name of the sub/function and
          • the parameters of the sub/function in parentheses if it has parameters at all.
          There is always a single space between name of sub/function and opening parenthesis independent on what is written in source file.

          The alias name, the descriptors, keyword THREAD for a thread function, and the return type of a function are not displayed in function list view.

          I have used the subs/functions found on the documentation pages for subs/functions for testing this regular expression.

          It is of course possible to define what is displayed in the function list view. So if you want to see more than just sub/function name and the parameters, let me know.

          Let me also know if you want to use a flat or a hierarchical function list. The expression above is for a flat function list.

          BTW: It is not possible with UltraEdit regular expression to do what I have done with Perl regular expression above. That is far beyond what the legacy UltraEdit regexp engine supports. Especially parameters with parentheses inside the parameters list bounded by parentheses is impossible to handle even with multiple UltraEdit regular expressions.
          Best regards from an UC/UE/UES for Windows user from Austria

          15
          Basic UserBasic User
          15

            Nov 02, 2014#5

            Wow, thanks Mofi. I'll try that and let you know how it goes. I think a flat list would suit me fine, I just found it annoying than I couldn't mention the word 'Sub' in a comment that had a ( , without it showing up in the Function list. I previously didn't know what 'flavour' of Regex that UE used, or that I could use Perl Regex's so (relatively) easily with the latest versions, so that could be quite useful for future use. I have been thinking about getting JGSoft's Regex Buddy and Regex Magic for some time, so I might see if work will fork out for it, now that I know I can use Perl Regex's that Regex Buddy and Magic support.