class: Tools::TagList
authorClaus Gittinger <cg@exept.de>
Sat, 10 May 2014 15:23:19 +0200
changeset 14345 af295cf3d7a3
parent 14344 68ca14353fd5
child 14346 687b49e574c6
class: Tools::TagList added:10 methods changed:8 methods category of:
Tools__TagList.st
--- a/Tools__TagList.st	Sat May 10 12:48:12 2014 +0200
+++ b/Tools__TagList.st	Sat May 10 15:23:19 2014 +0200
@@ -94,6 +94,7 @@
     TagsSuffixes at:#'text/lisp-arc'            put:#( 'arc' ).
     TagsSuffixes at:#'text/scheme'              put:#( 'scm' 'ss' 'brg').
     TagsSuffixes at:#'text/oz'                  put:#( 'oz').
+    TagsSuffixes at:#'text/lua'                 put:#( 'lua').
     TagsSuffixes at:#'text/smalltalk'           put:#( 'st' ).
     TagsSuffixes at:#'text/tcl'                 put:#( 'tcl' ).
     TagsSuffixes at:#'text/ruby'                put:#( 'rb' ).
@@ -201,6 +202,12 @@
     ^ self tagsSuffixes at:#'text/java'
 !
 
+luaSuffixes
+    "returns a list of supported lua-suffixes
+    "
+    ^ self tagsSuffixes at:#'text/lua'
+!
+
 makeFilePatterns
     "returns a list of makefile match patterns
     "
@@ -341,6 +348,10 @@
     "Modified: / 21-10-2011 / 09:31:30 / cg"
 !
 
+isLuaSuffix:suffix
+    ^ self isSuffix:suffix in:self luaSuffixes
+!
+
 isMakefileName:fileName
     |lcName|
 
@@ -2472,6 +2483,37 @@
 
 !TagList methodsFor:'tag generation - helpers'!
 
+linewiseNaiveTagsInFile:aFilePath using:parseLineBlock
+    "common helper for naive linewise parsing tags"
+
+    |targets line lineNr s tagOrTagCollection|
+
+    Tag autoload.
+
+    targets := OrderedCollection new.
+    s := aFilePath asFilename readStream.
+    s notNil ifTrue:[
+        s := LineNumberReadStream readingFrom:s.
+        [s atEnd] whileFalse:[
+            lineNr := s lineNumber.
+            line := s nextLine.
+
+            tagOrTagCollection := parseLineBlock value:line value:lineNr.
+            tagOrTagCollection notNil ifTrue:[
+                tagOrTagCollection isCollection ifTrue:[
+                    targets addAll:tagOrTagCollection
+                ] ifFalse:[
+                    targets add:tagOrTagCollection
+                ].
+            ].
+        ].
+        s close
+    ].
+    ^ targets
+
+    "Modified: / 08-05-2011 / 10:12:29 / cg"
+!
+
 plainTextBetweenHTMLElement:startElement andElementWithTag:endTag
     "applied to an <h1>-tag element, passing '/h1' as endTag,
      this retrieves the plain text of the headline. Used by the tag list."
@@ -2813,6 +2855,10 @@
         "/ dart tags - simulated
         ^ self dartTagsInFile:pathName
     ].
+    (self class isLuaSuffix:suffix) ifTrue:[
+        "/ lua tags - simulated
+        ^ self luaTagsInFile:pathName
+    ].
 
     (self class isHTMLSuffix:suffix) ifTrue:[
         "/ html tags - simulated
@@ -3228,97 +3274,199 @@
         ;;; moretext     documentation
     "
 
-    |targets line lineNr s tag|
-
-    Tag autoload.
-
-    targets := OrderedCollection new.
-    s := aFilePath asFilename readStream.
-    s notNil ifTrue:[
-        s := LineNumberReadStream readingFrom:s.
-        [s atEnd] whileFalse:[
-            lineNr := s lineNumber.
-            line := s nextLine.
-
-            tag := self lispTagFromLine:line lineNr:lineNr.
-            tag notNil ifTrue:[
-                targets add:tag
-            ].
-        ].
-        s close
-    ].
-    ^ targets
+    ^ self
+        linewiseNaiveTagsInFile:aFilePath 
+        using:[:line :lineNr |
+                self lispTagFromLine:line lineNr:lineNr
+              ]
 
     "Modified: / 08-05-2011 / 10:12:29 / cg"
 !
 
+luaTagFromLine:line lineNr:lineNr
+    "lua tags:
+     naive, q&d scan for lines starting with (not syntax-aware):
+        local function ...
+    "
+
+    |l nm words def isLocal|
+
+    l := line withoutSeparators.
+
+    (l startsWith:'--') ifTrue:[^ nil].     "/ comment  
+
+    words := l splitByAny:(' (),',Character tab).
+    words size >= 2 ifFalse:[^ nil].
+
+    (isLocal := words first = 'local') ifTrue:[ words := words copyFrom:2 ].
+    words size <= 2 ifTrue:[ ^ nil ]. 
+    def := words first.
+    nm := words second.
+
+    def = 'function' ifTrue:[
+        (showOnly notNil and:[showOnly ~~ #functions]) ifTrue:[^ nil].
+        hideFunctions == true ifTrue:[ ^ nil ].
+        ^ Tag::TFunction 
+                        label:nm 
+                        pattern:nil
+                        type:nil
+                        lineNumber:lineNr.
+    ].
+
+    isLocal ifTrue:[
+        (words includes:'=') ifTrue:[
+            words := words copyTo:(words indexOf:'=')-1
+        ].
+        ^ words 
+            collect:[:eachVar |
+                Tag::TVariable 
+                            label:eachVar 
+                            pattern:nil
+                            type:nil
+                            lineNumber:lineNr.
+            ]
+            as:Array.
+    ].
+
+    ^ nil
+!
+
+luaTagsInFile:aFilePath
+    "lua tags:
+     naive, q&d scan for lines starting with (not syntax-aware):
+        local function ...
+    "
+
+    ^ self
+        linewiseNaiveTagsInFile:aFilePath 
+        using:[:line :lineNr |
+                self luaTagFromLine:line lineNr:lineNr
+              ]
+!
+
+ozTagFromLine:line lineNr:lineNr
+    "oz tags:
+     naive, q&d scan for lines starting with:
+        fun { name ...
+    "
+
+    |l nm lineStream kwLen skipBrace type hideHolder|
+
+    l := line withoutSeparators.
+
+    kwLen := nil.
+    skipBrace := false.
+
+    (l startsWith:'class') ifTrue:[
+        kwLen := 5.
+        type := Tag::TClass.
+        hideHolder := hideOzClasses.
+    ].
+    (l startsWith:'meth') ifTrue:[
+        kwLen := 4.
+        type := Tag::TMethod.
+        hideHolder := hideOzMethods.
+    ].
+    (l startsWith:'fun') ifTrue:[
+        kwLen := 3.
+        skipBrace := true.
+        type := Tag::TFunction.
+        hideHolder := hideOzFunctions.
+    ].
+    (l startsWith:'proc') ifTrue:[
+        kwLen := 4.
+        skipBrace := true.
+        type := Tag::TFunction.
+        hideHolder := hideOzFunctions.
+    ].
+    hideHolder value ~~ true ifTrue:[
+        kwLen notNil ifTrue:[
+            lineStream := l readStream.
+            lineStream skip:kwLen; skipSeparators.
+
+            (skipBrace not or:[lineStream peek = ${ ]) ifTrue:[
+                skipBrace ifTrue:[lineStream skip:1; skipSeparators].  
+                nm := lineStream upToMatching:[:ch | (ch isLetterOrDigit or:['_' includes:ch]) not].
+                (nm notEmpty and:[nm first isLetter or:[nm first = $_]]) ifTrue:[    
+                    ^ type 
+                                    label:nm 
+                                    pattern:nil
+                                    type:nil
+                                    lineNumber:lineNr.
+                ]
+            ]
+        ].
+    ].
+    ^ nil
+!
+
 ozTagsInFile:aFilePath
     "oz tags:
      naive, q&d scan for lines starting with:
         fun { name ...
     "
 
-    |targets line l lineNr nm s tag lineStream kwLen skipBrace type hideHolder|
-
-    Tag autoload.
-
-    targets := OrderedCollection new.
-    s := aFilePath asFilename readStream.
-    s notNil ifTrue:[
-        s := LineNumberReadStream readingFrom:s.
-        [s atEnd] whileFalse:[
-            lineNr := s lineNumber.
-            line := s nextLine.
-            l := line withoutSeparators.
-
-            kwLen := nil.
-            skipBrace := false.
-
-            (l startsWith:'class') ifTrue:[
-                kwLen := 5.
-                type := Tag::TClass.
-                hideHolder := hideOzClasses.
-            ].
-            (l startsWith:'meth') ifTrue:[
-                kwLen := 4.
-                type := Tag::TMethod.
-                hideHolder := hideOzMethods.
+    ^ self
+        linewiseNaiveTagsInFile:aFilePath 
+        using:[:line :lineNr |
+                self ozTagFromLine:line lineNr:lineNr
+              ]
+!
+
+phpTagFromLine:line lineNr:lineNr
+    "php tags:
+     naive, q&d scan for lines starting with:
+        var ...
+        class ...
+        function ...
+    "
+
+    |l nm lineStream|
+
+    l := line withoutSeparators.
+
+    (l startsWith:'var ') ifTrue:[
+        lineStream := (l copyFrom:4) readStream.
+        lineStream skipSeparators.
+        lineStream peek == $$ ifTrue:[
+            lineStream next.
+            nm := lineStream 
+                    nextMatching:[:c | c isLetter] 
+                    thenMatching:[:c | c isLetterOrDigit or:[c == $_]].
+            ^ (Tag::TVariable 
+                        label:nm 
+                        pattern:nil
+                        type:nil
+                        lineNumber:lineNr).
+        ]
+    ] ifFalse:[
+        (l startsWith:'class ') ifTrue:[
+            lineStream := (l copyFrom:6) readStream.
+            lineStream skipSeparators.
+            nm := lineStream 
+                    nextMatching:[:c | c isLetter] 
+                    thenMatching:[:c | c isLetterOrDigit or:[c == $_]].
+            ^ (Tag::TClass 
+                            label:nm 
+                            pattern:nil
+                            type:nil
+                            lineNumber:lineNr).
+        ] ifFalse:[
+            (l startsWith:'function ') ifTrue:[
+                lineStream := (l copyFrom:9) readStream.
+                lineStream skipSeparators.
+                nm := lineStream 
+                        nextMatching:[:c | c isLetter] 
+                        thenMatching:[:c | c isLetterOrDigit or:[c == $_]].
+                 ^ (Tag::TFunction
+                                label:nm 
+                                pattern:nil
+                                type:nil
+                                lineNumber:lineNr).
             ].
-            (l startsWith:'fun') ifTrue:[
-                kwLen := 3.
-                skipBrace := true.
-                type := Tag::TFunction.
-                hideHolder := hideOzFunctions.
-            ].
-            (l startsWith:'proc') ifTrue:[
-                kwLen := 4.
-                skipBrace := true.
-                type := Tag::TFunction.
-                hideHolder := hideOzFunctions.
-            ].
-            hideHolder value ~~ true ifTrue:[
-                kwLen notNil ifTrue:[
-                    lineStream := l readStream.
-                    lineStream skip:kwLen; skipSeparators.
-
-                    (skipBrace not or:[lineStream peek = ${ ]) ifTrue:[
-                        skipBrace ifTrue:[lineStream skip:1; skipSeparators].  
-                        nm := lineStream upToMatching:[:ch | (ch isLetterOrDigit or:['_' includes:ch]) not].
-                        (nm notEmpty and:[nm first isLetter or:[nm first = $_]]) ifTrue:[    
-                            tag := type 
-                                            label:nm 
-                                            pattern:nil
-                                            type:nil
-                                            lineNumber:lineNr.
-                            targets add:tag.
-                        ]
-                    ]
-                ].
-            ]
         ].
-        s close
     ].
-    ^ targets
+    ^ nil
 !
 
 phpTagsInFile:aFilePath
@@ -3329,64 +3477,34 @@
         function ...
     "
 
-    |targets line l lineNr nm s lineStream|
-
-    Tag autoload.
-
-    targets := OrderedCollection new.
-    s := aFilePath asFilename readStream.
-    s notNil ifTrue:[
-        s := LineNumberReadStream readingFrom:s.
-        [s atEnd] whileFalse:[
-            lineNr := s lineNumber.
-            line := s nextLine.
-            l := line withoutSeparators.
-
-            (l startsWith:'var ') ifTrue:[
-                lineStream := (l copyFrom:4) readStream.
-                lineStream skipSeparators.
-                lineStream peek == $$ ifTrue:[
-                    lineStream next.
-                    nm := lineStream 
-                            nextMatching:[:c | c isLetter] 
-                            thenMatching:[:c | c isLetterOrDigit or:[c == $_]].
-                    targets add:(Tag::TVariable 
-                                label:nm 
-                                pattern:nil
-                                type:nil
-                                lineNumber:lineNr).
-                ]
-            ] ifFalse:[
-                (l startsWith:'class ') ifTrue:[
-                    lineStream := (l copyFrom:6) readStream.
-                    lineStream skipSeparators.
-                    nm := lineStream 
-                            nextMatching:[:c | c isLetter] 
-                            thenMatching:[:c | c isLetterOrDigit or:[c == $_]].
-                    targets add:(Tag::TClass 
-                                    label:nm 
-                                    pattern:nil
-                                    type:nil
-                                    lineNumber:lineNr).
-                ] ifFalse:[
-                    (l startsWith:'function ') ifTrue:[
-                        lineStream := (l copyFrom:9) readStream.
-                        lineStream skipSeparators.
-                        nm := lineStream 
-                                nextMatching:[:c | c isLetter] 
-                                thenMatching:[:c | c isLetterOrDigit or:[c == $_]].
-                        targets add:(Tag::TFunction
-                                        label:nm 
-                                        pattern:nil
-                                        type:nil
-                                        lineNumber:lineNr).
-                    ].
-                ].
-            ].
-        ].
-        s close
+    ^ self
+        linewiseNaiveTagsInFile:aFilePath 
+        using:[:line :lineNr |
+                self phpTagFromLine:line lineNr:lineNr
+              ]
+!
+
+prologTagFromLine:line lineNr:lineNr
+    "prolog tags:
+     naive, q&d scan for lines matching:
+        <anything> :-
+    "
+
+    |l nm|
+
+    l := line withoutSeparators.
+
+    (l includesString:':-') ifTrue:[
+        (l startsWith:':-') ifFalse:[
+            nm := l copyTo:(l indexOfSubCollection:':-').
+            ^ (Tag::TPrologClause 
+                            label:nm 
+                            pattern:nil
+                            type:nil
+                            lineNumber:lineNr).
+        ]
     ].
-    ^ targets
+    ^ nil
 !
 
 prologTagsInFile:aFilePath
@@ -3395,38 +3513,11 @@
         <anything> :-
     "
 
-    |targets line l lineNr nm s|
-
-    Tag autoload.
-
-    targets := OrderedCollection new.
-    s := aFilePath asFilename readStream.
-    s notNil ifTrue:[
-        s := LineNumberReadStream readingFrom:s.
-        [s atEnd] whileFalse:[
-            lineNr := s lineNumber.
-            line := s nextLine.
-            l := line withoutSeparators.
-
-            (l includesString:':-') ifTrue:[
-                (l startsWith:':-') ifFalse:[
-                    nm := l copyTo:(l indexOfSubCollection:':-').
-                    targets add:(Tag::TPrologClause 
-                                    label:nm 
-                                    pattern:nil
-                                    type:nil
-                                    lineNumber:lineNr).
-                ]
-            ]
-        ].
-        s close
-    ].
-    ^ targets
-
-
-
-
-
+    ^ self
+        linewiseNaiveTagsInFile:aFilePath 
+        using:[:line :lineNr |
+                self prologTagFromLine:line lineNr:lineNr
+              ]
 !
 
 pythonTagsInFile:aFilePath
@@ -3523,48 +3614,51 @@
     "Modified: / 08-05-2011 / 10:39:10 / cg"
 !
 
+rubyTagFromLine:line lineNr:lineNr
+    "ruby tags:
+     naive, q&d scan for lines matching:
+        def any
+    "
+
+    |l nm|
+
+    l := line withoutSeparators.
+
+    (l startsWith:'def ') ifTrue:[
+        nm := l copyFrom:5.
+        ^ (Tag::TFunction 
+                        label:nm 
+                        pattern:nil
+                        type:nil
+                        lineNumber:lineNr).
+    ] ifFalse:[
+        (l startsWith:'class ') ifTrue:[
+            hideClasses == true ifFalse:[
+                nm := l copyFrom:6.
+                ^ (Tag::TClass 
+                                label:nm 
+                                pattern:nil
+                                type:nil
+                                lineNumber:lineNr).
+            ]
+        ].
+    ].
+    ^ nil
+
+    "Modified: / 08-05-2011 / 10:38:44 / cg"
+!
+
 rubyTagsInFile:aFilePath
     "ruby tags:
      naive, q&d scan for lines matching:
         def any
     "
 
-    |targets line l lineNr nm s|
-
-    Tag autoload.
-
-    targets := OrderedCollection new.
-    s := aFilePath asFilename readStream.
-    s notNil ifTrue:[
-        s := LineNumberReadStream readingFrom:s.
-        [s atEnd] whileFalse:[
-            lineNr := s lineNumber.
-            line := s nextLine.
-            l := line withoutSeparators.
-
-            (l startsWith:'def ') ifTrue:[
-                nm := l copyFrom:5.
-                targets add:(Tag::TFunction 
-                                label:nm 
-                                pattern:nil
-                                type:nil
-                                lineNumber:lineNr).
-            ] ifFalse:[
-                (l startsWith:'class ') ifTrue:[
-                    hideClasses == true ifFalse:[
-                        nm := l copyFrom:6.
-                        targets add:(Tag::TClass 
-                                        label:nm 
-                                        pattern:nil
-                                        type:nil
-                                        lineNumber:lineNr).
-                    ]
-                ].
-            ].
-        ].
-        s close
-    ].
-    ^ targets
+    ^ self
+        linewiseNaiveTagsInFile:aFilePath 
+        using:[:line :lineNr |
+                self rubyTagFromLine:line lineNr:lineNr
+              ]
 
     "Modified: / 08-05-2011 / 10:38:44 / cg"
 !
@@ -3649,58 +3743,59 @@
     "Created: / 05-01-2012 / 10:56:26 / cg"
 !
 
+tclTagFromLine:line lineNr:lineNr
+    "tcl tags:
+     naive, q&d scan for lines matching:
+        proc any
+    "
+
+    |l nm words|
+
+    l := line withoutSeparators.
+
+    (l startsWith:'proc ') ifTrue:[
+        nm := l withoutPrefix:'proc '.
+        ^(Tag::TFunction 
+                        label:nm 
+                        pattern:nil
+                        type:nil
+                        lineNumber:lineNr).
+    ] ifFalse:[ (l startsWith:'tixWidgetClass ') ifTrue:[
+        nm := l copyFrom:'tixWidgetClass ' size + 1.
+        (nm endsWith:'{') ifTrue:[
+            nm := (nm copyButLast:1) withoutSeparators.
+        ].
+        ^(Tag::TClass 
+                        label:nm 
+                        pattern:nil
+                        type:nil
+                        lineNumber:lineNr).
+    ] ifFalse:[ (l startsWith:'set ') ifTrue:[
+        hideVariables value ~~ true ifTrue:[
+            words := l asCollectionOfWords.
+            words size >= 2 ifTrue:[
+                nm := words second.
+                ^(Tag::TVariable 
+                                label:nm 
+                                pattern:nil
+                                type:nil
+                                lineNumber:lineNr).
+        ]
+    ]]]].
+    ^ nil
+!
+
 tclTagsInFile:aFilePath
     "tcl tags:
      naive, q&d scan for lines matching:
         proc any
     "
 
-    |targets line l lineNr nm s words|
-
-    Tag autoload.
-
-    targets := OrderedCollection new.
-    s := aFilePath asFilename readStream.
-    s notNil ifTrue:[
-        s := LineNumberReadStream readingFrom:s.
-        [s atEnd] whileFalse:[
-            lineNr := s lineNumber.
-            line := s nextLine.
-            l := line withoutSeparators.
-
-            (l startsWith:'proc ') ifTrue:[
-                nm := l withoutPrefix:'proc '.
-                targets add:(Tag::TFunction 
-                                label:nm 
-                                pattern:nil
-                                type:nil
-                                lineNumber:lineNr).
-            ] ifFalse:[ (l startsWith:'tixWidgetClass ') ifTrue:[
-                nm := l copyFrom:'tixWidgetClass ' size + 1.
-                (nm endsWith:'{') ifTrue:[
-                    nm := (nm copyButLast:1) withoutSeparators.
-                ].
-                targets add:(Tag::TClass 
-                                label:nm 
-                                pattern:nil
-                                type:nil
-                                lineNumber:lineNr).
-            ] ifFalse:[ (l startsWith:'set ') ifTrue:[
-                hideVariables value ~~ true ifTrue:[
-                    words := l asCollectionOfWords.
-                    words size >= 2 ifTrue:[
-                        nm := words second.
-                        targets add:(Tag::TVariable 
-                                        label:nm 
-                                        pattern:nil
-                                        type:nil
-                                        lineNumber:lineNr).
-                ]
-            ]]]].
-        ].
-        s close
-    ].
-    ^ targets
+    ^ self
+        linewiseNaiveTagsInFile:aFilePath 
+        using:[:line :lineNr |
+                self tclTagFromLine:line lineNr:lineNr
+              ]
 !
 
 yaccTagsInFile:aFilePath
@@ -3751,14 +3846,14 @@
 !TagList class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__TagList.st,v 1.41 2014-05-10 10:48:12 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__TagList.st,v 1.42 2014-05-10 13:23:19 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__TagList.st,v 1.41 2014-05-10 10:48:12 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__TagList.st,v 1.42 2014-05-10 13:23:19 cg Exp $'
 !
 
 version_SVN
-    ^ '$Id: Tools__TagList.st,v 1.41 2014-05-10 10:48:12 cg Exp $'
+    ^ '$Id: Tools__TagList.st,v 1.42 2014-05-10 13:23:19 cg Exp $'
 ! !