Multiple line comments and Comment Add/Remove for COBOL files

Syntax highlighting, code folding, brace matching, code indenting, and function list

Multiple line comments and Comment Add/Remove for COBOL files

Postby spohnsoftware » Wed Dec 05, 2012 12:28 pm

I have a need to adjust my COBOL wordfile to have the following capabilites: (and a few wish list items)

  1. Our code can have two different comment characters. The first is the standard "*" in column 7. Got that working fine. The second is "%" in column 7 as well. How do I allow for both characters to represent comments and have their lines of code colorized accordingly.
    I figured this one out.

    (Wish list - Would like the line not to be colorized, but have it's font adjusted to a strikethru to better see the commented lines)

  2. We mark our code with issue numbers in columns 1 thru 6. This does not seem to cause an issue except if a COBOL Section has this type of marking, it does not show up in the Function List. Can this be adjusted in the wordfile to ignore columns 1-6???

  3. Is there a list of what commands/syntax is possible in wordfiles?
Thanks.
spohnsoftware
Newbie
 
Posts: 3
Joined: Wed Dec 05, 2012 12:24 pm

Re: Multiple line comments and Comment Add/Remove for COBOL files

Postby Mofi » Thu Dec 06, 2012 8:52 am

In help of UltraEdit there is a page titled Syntax Highlighting (Configuration - Editor Display) which you can find via the help Index or when clicking on button Help on Syntax Highlighting configuration dialog. Also this forum contains the sticky topic Template for syntax highlighting language wordfile with additional information not found in help of UltraEdit. This forum contains also a Readme for the Syntax Highlighting forum announcement answering frequently asked questions and containing links to other useful topics regarding syntax highlighting.

Style strikethrough is not supported by fonts directly like bold, italic, or underline. Applications supporting this style must draw a thin line over the text to support it. Most word processing applications support this style as well as browsers, but most text editors do not support it. UltraEdit also does not support style strikethrough. So you can change only the color of commented text and use bold, italic or underline to even more emphasize a text as comment.

You did not post the first line of the language file you use for COBOL syntax highlighting and also not the function strings. Therefore I cannot really help you with your other questions respectively must shoot into the sky with my next answers.

The extra downloads page contains 2 user contributed wordfiles for COBOL - cobol.uew and cobolhilite.uew. According to your requirements for line comment highlighting the first line should be something like

/L20"Cobol" COBOL_LANG Nocase Line Comment = * Line Comment Valid Columns = [7] Line Comment Alt = % Line Comment Valid Columns Alt = [7] File Extensions = CBL COB CPY

The first line in cobolhilite.uew is definitely not correct which I will report IDM. Just Valid Columns = [7] is not a correct definition and therefore ignored by UltraEdit.

cobol.uew contains the function string definition:

/Function String = "%[ ^t]+^([a-z^-]+^) ^{SECTION^}^{DIVISION^}"

With this UltraEdit regular expression search string words consisting of only letters in any case and hyphen characters are found which are at beginning of a line after 1 or more spaces/tabs and with word SECTION or word DIVISION following after a single space character. If you have in columns 1 to 6 numbers, it would best to use this expression with a small modification:

/Function String = "%[ ^t0-9]+^([a-z^-]+^) ^{SECTION^}^{DIVISION^}"
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Multiple line comments and Comment Add/Remove for COBOL files

Postby spohnsoftware » Thu Dec 06, 2012 12:27 pm

Here is the function expression I got to work (thanks for your assistance):

/Function String = "([-A-Za-z0-9]+[ ]+(section|division)[ ]*\.)"

:)

Now, hopefully one more thing:

The first line of my wordfile is:

/L20"Cobol" COBOL_LANG Line Comment = * Line Comment Valid Columns = [7] Line Comment Alt = % Nocase File Extensions = CBL COB CPY S F F1

This is working fine except one small nit. I can right-click on a line of code and say "Commend Add". This is adding an "*" in column 1 instead of column 7. How can I make the "*" appear in column 7, which is a valid comment in COBOL, not column 1?

Thanks.
spohnsoftware
Newbie
 
Posts: 3
Joined: Wed Dec 05, 2012 12:24 pm

Re: Multiple line comments and Comment Add/Remove for COBOL files

Postby Mofi » Thu Dec 06, 2012 1:53 pm

Your expression for function string is a Perl regular expression. So if that really works, your wordfile must contain additionally the line

/Regexp Type = Perl

Well, the expression is not really wrong, but could be simplified. UltraEdit runs the regular expression search for the list in function list window always with Match Case option not checked. Therefore the expression [A-Za-z] is equal the expression [A-Z] and equal the expression [a-z]. The expression [A-Za-z] is not really wrong, but [a-z] does the same and makes reading in the expression a little bit faster.

The hyphen character - has no special meaning in an expression except when used within a character class definition [...]. In this case it means "from X to Y". Therefore - within [...] in a Perl regular expression must be escaped with a backslash if the hyphen character itself should be added to the character class. You have not done this, but instead added - as first character to the character class. Well, this works because the error handling routines of the Perl regular expression engine detect if a - is the first or last character in a character class definition and interpret the not escaped hyphen character in these 2 cases as character to add to the class. But better would be nevertheless to add the hyphen character escaped with a backslash.

It is not necessary to enclose a space character in square brackets if a multiplier like + or * follows. A character class with just a single character makes just the find a little bit slower.

In your expression their are 2 marking groups defined by the 2 pairs of round brackets. That should be avoided here as the inner pair of round brackets is just for the OR expression. The inner group can be defined with ?: immediately after opening round bracket as a non marking group.

So the Perl regular expression function string can be one of the 2 lines below depending on what you would like to see in function list:

/Function String = "([0-9a-z\-]+ +(?:section|division) *\.)"

/Function String = "([0-9a-z\-]+) +(?:section|division) *\."



I'm wondering that you don't use also Line Comment Valid Columns Alt = [7] in first line. Without this additional definition the character % is interpreted as line comment starting string wherever found in a line.

The command Comment Add inserts the primary line comment string always at beginning of all selected lines or current line if no line selected. And command Comment Remove removes always the first occurrence of the primary line comment string within all selected lines respectively the current line. Special limitations like those of Cobol that the line comment string is valid only in certain columns is not taken into account.

However, it is not very difficult to extend built-in Comment Add and Comment Remove by macros or scripts for Cobol files.

For example you can create the following 4 macros and store them all together in a macro file which is configured at Macro - Set Auto Load to be automatically loaded on startup of UltraEdit. For fast execution of the macros it would make sense to assign hotkeys or chords to the main macros CommentAdd and CommentRemove instead of assigning hotkeys or chords to the 2 built-in commands.

Submacro CobolCmtAdd:

Code: Select all
IfSel
Else
SelectLine
EndIf
UltraEditReOn
Find RegExp SelectText "%^(??????^)"
Replace All "^1*"

Submacro CobolCmtDel:

Code: Select all
IfSel
Else
SelectLine
EndIf
UltraEditReOn
Find RegExp SelectText "%^(??????^)^*"
Replace All "^1"

Macro CommentAdd with hotkey ???

Code: Select all
IfExtIs "CBL"
PlayMacro 1 "CobolCmtAdd"
ExitMacro
EndIf
IfExtIs "COB"
PlayMacro 1 "CobolCmtAdd"
ExitMacro
EndIf
IfExtIs "CPY"
PlayMacro 1 "CobolCmtAdd"
ExitMacro
EndIf
IfExtIs "S"
PlayMacro 1 "CobolCmtAdd"
ExitMacro
EndIf
IfExtIs "F"
PlayMacro 1 "CobolCmtAdd"
ExitMacro
EndIf
IfExtIs "F1"
PlayMacro 1 "CobolCmtAdd"
ExitMacro
EndIf
CommentAdd

Macro CommentRemove with hotkey ???

Code: Select all
IfExtIs "CBL"
PlayMacro 1 "CobolCmtDel"
ExitMacro
EndIf
IfExtIs "COB"
PlayMacro 1 "CobolCmtDel"
ExitMacro
EndIf
IfExtIs "CPY"
PlayMacro 1 "CobolCmtDel"
ExitMacro
EndIf
IfExtIs "S"
PlayMacro 1 "CobolCmtDel"
ExitMacro
EndIf
IfExtIs "F"
PlayMacro 1 "CobolCmtDel"
ExitMacro
EndIf
IfExtIs "F1"
PlayMacro 1 "CobolCmtDel"
ExitMacro
EndIf
CommentRemove

The macros CommentAdd and CommentRemove execute the built-in commands except for files with one of the 5 not case-sensitive file extensions listed in the macros for which the specialized submacros CobolCmtAdd and CobolCmtDel are used to insert respectively remove the character * at column 7.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3937
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Syntax Highlighting