FunctionList Parsers: Additions & Suggestions

Rob Kodey
2013-07-02
2014-10-01
1 2 > >> (Page 1 of 2)
  • Rob Kodey
    Rob Kodey
    2013-07-02

    Perhaps a thread for those of us starting to tinker with the FunctionList parsers?
    Offer up suggestions, additions, etc...

    I tweaked the JavaScript parser as shown below. Seems to work nicely...
    1) In addition to "function myFunc()", support the "object" format like "myFunc:function()"
    2) Simplified the nameExpr to simply pull out the first "word", excluding the word "function"

    <parser id="js_function" displayName="Javascript">
      <function mainExpr="(([\w.]+[\s]*[:=][\n\s]*function)|(function[\s]+[\w.]+))[\s]*\([^\)\(]*\)[\n\s]*\{" displayMode="$className->$functionName">
        <functionName>
          <nameExpr expr="(function[\s]+)?\K[\w.]+"/>
        </functionName>
        <className>
          <nameExpr expr="[\w]+(?=[\s]*::)"/>
        </className>
      </function>
    </parser>
    
     
    Last edit: Rob Kodey 2013-07-09
  • Rob Kodey
    Rob Kodey
    2013-07-03

    Perl

    <association langID = "21" id="perl_function"/>
    
    <parser id="perl_function" displayName="Perl">
      <function mainExpr="sub[\s]+[\w]+[\s]*\([^\)\(]*\)[\n\s]*\{" displayMode="$className->$functionName">
        <functionName>
          <nameExpr expr="(sub[\s]+)?\K[\w]+"/>
        </functionName>
        <className>
          <nameExpr expr="[\w]+(?=[\s]*::)"/>
        </className>
      </function>
    </parser>
    
     
  • Rob Kodey
    Rob Kodey
    2013-07-09

    Edit: Updated the Javascript parser above.

     
  • stepher
    stepher
    2013-07-12

    I would like to put in a feature request for FunctionList.

    Essentially, I'd like to see the features of the original plug-in version or, at least, an option to choose between sorts - alphabetical and sequence/program flow. The List or Tree options are very nice visually, but not as big a concern for me.

    In the mean time, I "retrograded" back to V6.3.3 so I can use the plug-in version. I've never had any problems or stability issues with it.

    Thanks & cheers....Steph

     
  • Deadooshka
    Deadooshka
    2013-07-15

    PHP

    <association langID="1" id="php_class"/>
    
    <parser id="php_class" displayName="PHP Class" commentExpr="\/\*[\s\S]*?\*\/|(?:\/\/|\#)[^\r\n]*">
        <classRange mainExpr="\s(?:(?:class|interface)\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?:\s+(?:extends|implements)\s+(?:[a-zA-Z_\x7f-\xff\\][a-zA-Z0-9_\x7f-\xff\\]*(?:\s*\,\s*)?)+)?|trait\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\{" openSymbole = "\{" closeSymbole = "\}" displayMode="node">
            <className>
                <nameExpr expr="(?:interface|class|trait)\s+\K[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
            </className>
            <function mainExpr="\sfunction\s+(?:\&amp;\s*)?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\s*\([\S\s]*?\)\s*[\{\;]">
                <functionName>
                    <funcNameExpr expr="function\s+(?:\&amp;\s*)?\K[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
                </functionName>
            </function>
        </classRange>
    
        <function mainExpr="\sfunction\s+(?:\&amp;\s*)?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\s*\([\s\S]*?\)\s*\{" displayMode="$functionName">
            <functionName>
                <nameExpr expr="function\s+(?:\&amp;\s*)?\K[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
            </functionName>
            <className></className>
        </function>
    </parser>
    

    It is not always correctly parses classes, commented functions outside of classes, and PHP-code in strings. I think it is not a regexp problem.

     
    Last edit: Deadooshka 2013-12-22
    • Deadooshka
      Deadooshka
      2014-05-02

      <association langID="1" id="php_class"/>
      
      <parser id="php_class" displayName="PHP Class" commentExpr="\/\*.*?\*\/|(?:\/\/|\#)[^\r\n]*|&apos;.*?(?&lt;![^\\]\\)&apos;|&quot;.*?(?&lt;![^\\]\\\\\\|[^\\]\\)&quot;|&lt;&lt;&lt;[&apos;&quot;]?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)[&apos;&quot;]?(\r\n|\r|\n).*?\2\1">
      
          <classRange mainExpr="\s(?:(?:class|interface)\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?:\s+(?:extends|implements)\s+(?:[a-zA-Z_\x7f-\xff\\][a-zA-Z0-9_\x7f-\xff\\]*(?:\s*\,\s*)?)+)?|trait\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\{" openSymbole = "\{" closeSymbole = "\}" displayMode="node">
              <className>
                  <nameExpr expr="(?:interface|class|trait)\s+\K[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
              </className>
              <function mainExpr="\sfunction\s+(?:\&amp;\s*)?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\s*\(.*?\)\s*[\{\;]">
                  <functionName>
                      <funcNameExpr expr="function\s+(?:\&amp;\s*)?\K[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
                  </functionName>
              </function>
          </classRange>
      
          <function mainExpr="\sfunction\s+(?:\&amp;\s*)?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\s*\(.*?\)\s*\{" displayMode="$functionName">
              <functionName>
                  <nameExpr expr="function\s+(?:\&amp;\s*)?\K[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
              </functionName>
              <className></className>
          </function>
      
      </parser>
      

      added string definitions in commentExpr to avoid some plugin bugs

       
      Last edit: Deadooshka 2014-05-21
  • MegaJar
    MegaJar
    2013-08-01

    I'm trying to write a Java parser, but I can't seem to make it work. No matter what I try, the list only shows the file name, nothing more.

    As a test, I tried making a very simple dummy parser, meant to handle one specific Java file. I don't expect it to be able to parse any given Java class, just this specific one. The Java class is:

    public class MyClass {
        public String myFunc() {
            return "";
        }
    }
    

    And the dummy parser is:

    <association langID="6" id="java_class"/>
    
    <parser id="java_class" displayName="Java Class" commentExpr="((/\*.*?\*)/|(//.*?$))">
        <classRange
            mainExpr="^public class [\w]+ \{"
            openSymbole = "\{"
            closeSymbole = "\}"
            displayMode="node">
            <className>
                <nameExpr expr="public class [\w]+" />
                <nameExpr expr="class [\w]+" />
                <nameExpr expr="[\w]+" />
            </className>
            <function
                mainExpr="^[\t ]*public [\w]+ [\w]+\(\) \{">
                <functionName>
                    <functionNameExpr expr="public [\w]+ [\w]+\(\) \{" />
                    <functionNameExpr expr="public [\w]+ [\w]+\(\)" />
                    <functionNameExpr expr="[\w]+ [\w]+\(\) \{" />
                    <functionNameExpr expr="[\w]+ [\w]+\(\)" />
                    <functionNameExpr expr="[\w]+\(\) \{" />
                    <functionNameExpr expr="[\w]+\(\)" />
                </functionName>
            </function>
        </classRange>
    </parser>
    



    You'd think that, with three class expressions and six function expressions, that ONE of them would get a hit. But no -- the list pane still just shows the file name, MyClass.java; it doesn't recognize the class or the function.

    Any idea what I'm doing wrong?

     
    Last edit: MegaJar 2013-08-01
  • Thomas Wagner
    Thomas Wagner
    2013-08-02

    Hi,
    I'm looking for the FunctionList parsers-code für VB and VBScript.
    Could you help me please?

    praetor

     
  • Felix Nagel
    Felix Nagel
    2013-08-11

    The Java-Script parser works much better than the default one, for example with jQuery UI Widgets.

    PHP parser works nice so far (just dont forget to add the needed association tag)! Thanks for the effort!

     
    Last edit: Felix Nagel 2013-08-11
  • cchris
    cchris
    2013-08-17

    About the Java parser: te supplied commentExpr looks weird to me. Just paste the one for C++ in its stead.

    CChris

     
  • David Benedeki
    David Benedeki
    2013-08-24

    Hello all,
    Thanks all for the contibutions. Here's mine - somehwat different PHP parser.

                <association langID="1" id="php_function"/>
    
                <parser id="php_function" displayName="PHP source" commentExpr="((/\*.*?\*)/|(//.*?$))">
                    <classRange mainExpr="^[\t ]*(((class|interface)[\t ]+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*[\t ]+((extends|implements)[\t ]+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)?)|(trait[\t ]+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))\s*\{"
                        openSymbole="\{"
                        closeSymbole="\}"
                        displayMode="node">
                        <className>
                            <nameExpr expr="(class[\t ]+|interface[\t ]+|trait[\t ]+)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
                            <nameExpr expr="[\t ]+[\w]+"/>
                            <nameExpr expr="[\w]+"/>
                        </className>
                        <function mainExpr="^[\t ]*(public[\t ]+|protected[\t ]+|private[\t ]+)?(static[\t ]+)?function[\s]+&?[\t ]*([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{">
                            <functionName>
                                <funcNameExpr expr="function[\s]+&?[\t ]*[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"/>
                                <funcNameExpr expr="[\s]+&?[\w]+"/>
                                <funcNameExpr expr="[^&\s]+"/>
                            </functionName>
                        </function>
                    </classRange>
                    <function mainExpr="^[\t ]*function[\s]+&?[\t ]*([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\([^\)\(]*\)|\([^\)\(]*\))[\n\s]*\{"
                        displayMode="$className->$functionName">
                        <functionName>
                            <nameExpr expr="(?!(if|while|for))[\w_]+[\s]*\("/>
                            <nameExpr expr="(?!(if|while|for))[\w_]+"/>
                        </functionName>
                    </function>
                </parser>
    
     
  • Don HO
    Don HO
    2013-08-29

    @Rob Kodey:

    Thank you. js and perl parsers will be included in the next version.

    Don

     
    • Rob Kodey
      Rob Kodey
      2013-11-05

      Cool! I see the perl parser one made it in 6.5.1, but I think the JavaScript parser is still the original - FYI.

       
  • Don HO
    Don HO
    2013-08-29

    Regarding php parser, could any php guru give me a hint: which one is more complete?
    Deadooshka's one or David Benedeki's one?

    Don

     
  • Menno Vogels
    Menno Vogels
    2013-11-07

    My take on some of the parsers:


    XML parser

      <!-- Author: Menno Vogels; Version: 1.0.1.0 -->
      <parser 
          id="xml_node" 
          displayName="XML Node" 
          commentExpr="&lt;!--([^\-]|-(?!-&gt;))*--&gt;" >
        <function
            mainExpr="&lt;(?!\?[Xx][Mm][Ll])[\w\?]+(?:[\t \r\n]+\w+[\t ]*=[\t ]*(?&lt;QUOTEGROUP&gt;['&quot;])[^\&lt;QUOTEGROUP&gt;]*?\&lt;QUOTEGROUP&gt;)*"
            displayMode="$functionName" >
          <functionName>
            <nameExpr expr="[^&lt;\s]*" />
          </functionName>
        </function>
      </parser>
    

    Batch parser

      <!-- Author: Menno Vogels; Version: 2.1.0.0 -->
      <parser 
          id="batch_label" 
          displayName="BAT Label" 
          commentExpr="(?m-s:(?::{2}.*?$)|(?:(?i:REM)([\t ].*?)?$))" >
        <function
            mainExpr="(?m-s:^[\t ]*:[\w.]+\b)"
            displayMode="$functionName" >
          <functionName>
            <nameExpr expr="[^\t :]*" />
          </functionName>
        </function>
      </parser>
    

    INI parser

      <!-- Author: Menno Vogels; Version: 1.1.0.0 -->
      <parser 
          id="ini_section" 
          displayName="INI Section" 
          commentExpr="[#;].*?$" >
        <function
            mainExpr="^\[[\w.:; @(){}\-\\]+\]"
            displayMode="$functionName">
          <functionName>
            <nameExpr expr="[^[\]]+" />
          </functionName>
        </function>
      </parser>
    

    Menno

    EDIT:
    2013-12-??: added headers and author+version comment.
    2013-12-05: updated INI parser.
    2013-12-11: updated XML & Batch parsers.

     
    Last edit: Menno Vogels 2013-12-11
  • Felix Nagel
    Felix Nagel
    2013-11-15

    Since 6.5.1 update the PHP parser (which worked much better compared to the default) by Deadooshka causes stability issues and prevents some files (class with extend and implements, long class names) from processed and opened.

    Any plans to improve the PHP default parser or any idea how to fix Deadooshka's one?

     
  • Menno Vogels
    Menno Vogels
    2013-11-17


    Assembly parser

      <!-- Author: Menno Vogels; Version: 2.0.0.0 -->
      <parser 
          id="ASM_function" 
          displayName="Assembly" 
          commentExpr="(?&lt;=;).*?" >
        <function 
            mainExpr="^[\t ]*[A-Za-z_$][\w$]*:" 
            displayMode="$functionName" >
          <functionName>
            <nameExpr expr="[A-Za-z_$][\w$]*(?=:)" />
          </functionName>
        </function>
      </parser>
    

    'AssemblerParserTest.asm' contents

    ; line comment
    label1:
        instruction
    
    ; more line comment
    label3:                    ; trailing line comment
        instruction
        instruction
    
    label2:                    ; deliberate changed order with label3
        instruction
        instruction
    
        label4:
            instruction
    
    5label:                     ; invalid label(s)
    label-8:                    ;  :
    _label6:                    ;   valid label(s)
    label_7:                    ;    :
        instruction
        instruction
    
    ; end of file
    

    FunctionList panel contents

    [-] AssemblerParserTest.asm
        +-- label1
        +-- label3
        +-- label2
        +-- label4
        +-- _label6
        +-- label_7
    

    FunctionList panel sorted contents

    [-] AssemblerParserTest.asm
        +-- _label6
        +-- label_7
        +-- label1
        +-- label2
        +-- label3
        +-- label4
    

    EDIT
    2013-12-03: newest parser, added headers and author+version comment.

     
    Last edit: Menno Vogels 2013-12-02
  • Menno Vogels
    Menno Vogels
    2013-12-02


    Ruby parser

      <!-- Author: Menno Vogels; Version: 1.0.0.0 -->
      <parser
          id="ruby_function"
          displayName="Ruby"
          commentExpr="(?s:#.*?[\r\n]|(?-i:(?&lt;=^|[\r\n])=begin).*?(?-i:[\r\n]=end(?=[\r\n]|$)))" >
        <function
            mainExpr="(?s:\b(?-i:def)[\t ]+(?!(?-i:alias|and|BEGIN|begin|break|case|class|def|defined\?|do|else|elsif|END|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield|__FILE__|__LINE__))(?:[A-Za-z_]\w*[?!=]?(?:[\t ]*\([^)]*\))?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?)[\t ]*\([^)]*\)).+?(?-i:end))"
            displayMode="$functionName" >
          <functionName>
            <nameExpr expr="(?s:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?(?:[\t ]*\()?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?)[\t ]*\())" />
            <nameExpr expr="(?m:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?))(?=(?:\b|[\t ]*\()|.*$))" />
            <nameExpr expr="[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?))" />
            <nameExpr expr="(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?))" />
          </functionName>
        </function>
      </parser>
    

    Visual Basic parser

      <!-- Author: Menno Vogels; Version: 1.0.0.0 -->
      <parser 
          id="vb_function" 
          displayName="Visual Basic (.NET|Script|for Applications)"  
          commentExpr="(?m:((?&lt;=&apos;).*?$)|((?i:REM)([\t ].*?)?$))"> 
        <classRange
            mainExpr="(?s:(?&lt;SCOPE&gt;(?i:CLASS|TYPE)).*?(?i:END[\t ]\k&lt;SCOPE&gt;))"
            displayMode="node" >
          <className>
            <nameExpr expr="(?i:CLASS|TYPE)[\t ]+(?:[A-Za-z_][\w]*\b)(?:.*?[\r\n])" />
            <nameExpr expr="[\t ]+(?:[A-Za-z_][\w]*\b)" />
            <nameExpr expr="[A-Za-z_][\w]*" />
          </className>
          <function
              mainExpr="(?m:^[\t ]*(?i:(?:(?:PRIVATE|PUBLIC)[\t ]+)?(?:STATIC[\t ]+)?(?:SUB|FUNCTION|PROPERTY)).*?(?:\(|$))" >
            <functionName>
              <funcNameExpr expr="(?i:(?:(?:PRIVATE|PUBLIC)[\t ]+)?(?:STATIC[\t ]+)?(?:SUB|FUNCTION|PROPERTY)).*?(?:\(|$)"/>
              <funcNameExpr expr="(?i:(?:SUB|FUNCTION|PROPERTY)).*?(?:\(|$)"/>
              <funcNameExpr expr="[A-Za-z_][\w]*(?=[\t ]*\()"/>
            </functionName>
          </function>
        </classRange>
        <function 
            mainExpr="^[\t ]*(?i:(?:(?:PRIVATE|PUBLIC)[\t ]+)?(?:STATIC[\t ]+)?(?:SUB|FUNCTION|PROPERTY)).*?(?:\(|$)" 
            displayMode="$functionName">
          <functionName>
            <nameExpr expr="(?i:(?:(?:PRIVATE|PUBLIC)[\t ]+)?(?:STATIC[\t ]+)?(?:SUB|FUNCTION|PROPERTY)).*?(?:\(|$)"/>
            <nameExpr expr="(?i:(?:SUB|FUNCTION|PROPERTY)).*?(?:\(|$)"/>
            <nameExpr expr="[A-Za-z_][\w]*(?=[\t ]*\()"/>
          </functionName>
        </function>
      </parser>
    

    EDIT: moved updated assembly parser to original post.

     
    Last edit: Menno Vogels 2013-12-02
1 2 > >> (Page 1 of 2)

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks