James D. Goodrich, Jr.
4:37 AM 8/20/2008
Determining and Marking Comments Becomes More Efficient
The old method:
Function doComments(g() As core.group) As core.group() Dim cc As Long Dim com() As core.group Dim gc As Long Dim i As Long gc = UBound(g) 'First pass: Find and tag comments. For i = 1 To gc If isComStart(g(i)) Then 'The current group starts the comment 'Get the comment com = getComment(getGroups(g, i, gc - (i - 1))) cc = UBound(com) 'If the current group is the strict beginning of a comment If cc = 1 Then 'Prepare the groups for the comment group ReDim Preserve g(i) 'Update count gc = UBound(g) 'Save the comment, the type should be preserved g(gc) = combGroups(com) 'The current group has program data as well as the beginning of a comment Else ReDim Preserve g(i + 1) gc = UBound(g) g(i) = com(1) g(gc) = com(2) End If 'Since the group data has been modified, we must break out Exit For End If Next i doComments = g End Function Function isComStart(g As core.group) As Boolean Dim f() As core.finding Dim fc As Long isComStart = False f = findb(g.b, symbols.btick) fc = UBound(f) 'If the group is two in length If g.c = 2 Then 'If there are two back-ticks (`) If fc = 2 Then isComStart = True End If 'If the group is longer than two ElseIf g.c > 2 Then 'If there is at least two back-ticks If fc >= 2 Then isComStart = True End If End If End Function Function getGroups(g() As core.group, s As Long, n As Long) As core.group() Dim gg() As core.group Dim i As Long ReDim gg(n) For i = 0 To n - 1 gg(i + 1) = g(s + i) Next i getGroups = gg Erase gg End Function Function getComment(g() As core.group) As core.group() Dim c As Long Dim f() As finding Dim fc As Long Dim gc() As core.group Dim sc() As core.group Dim z() As core.group If isComBlock(g(1)) Then ReDim gc(1) gc(1) = combGroups(g) gc(1).t = interComment Else 'The comment is tacked on the end of a statement ReDim gc(2) 'Find the comment f = findb(g(1).b, symbols.btick) fc = UBound(f) c = UBound(g) 'The comment starts after the second back tick 'Ex: if(n=a)``stupid moment; Ex: if(n=a)```Even dumber comment sc = splitGroup(g(1), f(1).loc) 'Split group: sc(1) is the non-comment portion; sc(2) is beginning of comment 'Save first part gc(1) = sc(1) gc(1).t = basicOther 'Temporarily save comment z = getGroups(g, 2, c - 1) 'Insert second part z = insertGroup(sc(2), 1, z) 'Save second part gc(2) = combGroups(z) gc(2).t = interComment Erase f Erase sc Erase z End If getComment = gc Erase gc End Function
The above code is not even half of what it took to correctly identify comments found in source code.

However, by using a sequence (.s[tart] and .n[umber of elements]) and analyzing the data before applying groups, it was much easier to update the meta-data with the comment marking.
Function markComment(l As core.line) As Boolean Dim i As Long Dim c As Long With l.seq For i = 1 To .n If data.datum(.s + (i - 1)) = symbols.btick Then c = i: Exit For Next i If c > 0 Then For i = c To .n meta2.metum(.s + (i - 1)) = Categories.iCmmnt Next i End If End With End Function