Syntax Hightlighting and Semi-Colon Character

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
W E
Posts: 2
Joined: Tue Dec 30, 2003 9:52 am

Syntax Hightlighting and Semi-Colon Character

Post by W E »

I need to highlight the semi-colon character.
When used in a syntax file it is interprated as a comment within that file but I need to highlight it, in some cases it is an operator and other cases it is part of a keyword.
Is there any way to do this?
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Have you tried using \; ?

Or adding the ; to the list of characters in words (Configure - Preferences - Document Classes - Your document class - Syntax)
W E
Posts: 2
Joined: Tue Dec 30, 2003 9:52 am

Semi-colon in Keyword

Post by W E »

No, \; does not seem to help.
Nor does adding ; to the characters in words.

I have /recently/ upgraded the version of Textpad I am using and the semi-colon is accepted in OperatorChars, but there is still the problem with use in Keywords.
vpenacho1
Posts: 4
Joined: Thu Jan 22, 2004 9:42 pm

Double semi-colon as a keyword

Post by vpenacho1 »

I'm working in an assembly language which has the string ";;" as a special meaning at the end of a line. I'd like to highlight the double semi-colon but can't seem to get this to work except as part of a operator list. I'd like to color the semi-colons differently than other operators.

The main problem seems to be that the semi-colon is considered a start of comment indicator in the syntax file.

Any suggestions on how to go about getting this to work?
User avatar
CyberSlug
Posts: 120
Joined: Sat Oct 04, 2003 3:41 am

Post by CyberSlug »

Are there any parts of the syntax file you aren't using?

You could try this:
CharStart = ;
CharEnd = ;


Or you could try:
SingleCommentAlt = ;;

Then set the colors you want in TextPad prefrences. Hope that helps


EDIT: By the way many parts of the syntax file can be blank (and sometimes completly omitted) if you don't need them:
C=1
[Syntax]
Namespace1 = 6
IgnoreCase = Yes
KeyWordLength =
BracketChars =
OperatorChars =
PreprocStart =
SyntaxStart =
SyntaxEnd =
HexPrefix =
CommentStart =
CommentEnd =
CommentStartAlt =
CommentEndAlt =
SingleComment =
SingleCommentCol =
SingleCommentAlt =
SingleCommentColAlt =
SingleCommentEsc =
StringsSpanLines = Yes
StringStart =
StringEnd =
StringAlt =
StringEsc =
CharStart =
CharEnd =
CharEsc =
vpenacho1
Posts: 4
Joined: Thu Jan 22, 2004 9:42 pm

Post by vpenacho1 »

Unfortunately, I need most of the other parts of the file.

The CharStart/End does seem to work but I need that for actual character literals.

The SingleCommentAlt also works but has the bad side effect of making the rest of the line a comment, even when it isn't.

I would really like the double semi-colon to have a different color than other things like strings or comments. I think the only good solution might be to have some way to escape the ; which is the comment character in the syntax files.

BTW, I know I saw this before but I can't find a description of the syntax of the syntax file at www.textpad.com. Is it documented somewhere?
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

From the TextPad Help file, look under "syntax", then "syntax definition files":
Syntax Definition Files
Syntax definition files contain the information TextPad uses to highlight keywords in different colors. A standard set is provided for common programming languages, and contributed files are available from the TextPad web site.

If you want to implement syntax highlighting for a document class that has not been catered for, you must create a file of keywords that you want to be colored, as described below, and save it as "myfile.SYN" in the Syntax folder. Note that double byte character sets cannot be used in syntax definition files.

The first line of the file must be one of the following:

TEXT=1 means that only URLs will be highlighted. All sections of the syntax definition file are ignored, so do not use this type.
C=1 means that full syntax highlighting is available for languages which broadly conform to C syntax. All keywords are in a single namespace, so duplicates are not allowed.
HTML=1 means that full syntax highlighting is available for languages which broadly conform to HTML syntax. Keywords are in two namespaces, with tags in one and their attributes in the other. The Namespace1 parameter controls how many of the six [Keyword] sections are in the first namespace. Having two namespaces allows keywords such as TITLE, which can be both a tag and an attribute, to be colored according to context.
PERL=1 is a variant of C=1, to take account of some peculiarities of Perl syntax.
LaTeX=1 is a variant of C=1, to take account of some peculiarities of LaTeX syntax.
We will introduce other grammars as and when necessary.

The rest looks like an .INI file, with the following sections:

[Syntax]
[Keywords 1]
[Keywords 2]
[Keywords 3]
[Keywords 4]
[Keywords 5]
[Keywords 6]
[Preprocessor keywords]
The [Syntax] section must be first, followed by [Keywords 1]. The other sections are optional. The [Preprocessor keywords] section can only be used when a single character (such as "#") is used to start a statement that is handled by a pre-processor.

Keywords are entered one per line. The split between the keyword sections is arbitrary. You only need to use Keywords 2-6, if you want some keywords in different colors. They are all in the same namespace, unless "HTML=1" is used, when "Namespace1 = n" specifies how many of the keyword sections are in the first namespace, with the remainder in another. This means that the same name can appear in both namespaces when "HTML=1". The pre-processor keywords are always in their own namespace.

You can select the newly created .SYN file using the Preferences command on the Configure menu. It should be displayed in the drop-down list box for Syntax settings, for the new document class you created.

The [Syntax] section must contain the following lines:
Namespace1 = a number in the range 1 to 6, which specifies how many of the keyword sections are in the first namespace. There is only one namespace when "C=1" or "LaTeX=1", so this value must be 6. There are two namespaces when "HTML=1", so this value can be between 1 and 5, and defaults to 1. Change it to 2, say, if you want to be able to display HTML tags in two colors, and split the tag keywords between the [Keywords 1] and [Keywords 2] sections, depending on which color you want them in.
IgnoreCase = "Yes" if keywords are not case sensitive, otherwise "No".
KeyWordLength = the number of characters in each keyword. If this entry is omitted, or set to 0, keywords can be of variable length. It is only required for fixed length keywords that run together, without any delimiters.
BracketChars = characters that can be used for brackets.
OperatorChars = characters that can be used for operators.
PreprocStart = the character used to start a pre-processor statement.
HexPrefix = the characters that prefix hexadecimal numbers. If this entry is omitted, it defaults to "0x".
SyntaxStart = a string of characters that switch on keyword recognition (e.g. "<"), or leave blank.
SyntaxEnd = a string of characters that switch off keyword recognition (e.g. ">"), or leave blank.
CommentStart = a string of characters that start a multiple line comment, or leave blank.
CommentEnd = a string of characters that end a multiple line comment, or leave blank.
CommentStartAlt = an alternative string of characters that start a multiple line comment.
CommentEndAlt = an alternative string of characters that end a multiple line comment.
SingleComment = a string of characters that start a single line comment (e.g. "//" or "REM"), or leave blank.
SingleCommentCol = If a single line comment must start in a specific column, assign the number here. If it must start in the first non-blank column, assign "Leading" here.
SingleCommentAlt = an alternative string of characters that start a single line comment (e.g. "//" or "REM"), or leave blank.
SingleCommentColAlt = If the alternative single line comment must start in a specific column, assign the number here. If it must start in the first non-blank column, assign "Leading" here.
SingleCommentEsc = The character that is used to escape either of the SingleComment strings.
StringsSpanLines = "Yes" if strings can continue over line boundaries, otherwise "No". This can be used in conjunction with StringEsc, if the string can only be continued when the new line is escaped with that character.
StringStart = The character that indicates the start of a string (e.g. double quote).
StringEnd = The character that indicates the end of a string (e.g. double quote).
StringAlt = An alternative character that can be used to delimit strings, if the string contains the StringEnd character.
StringEsc = The character that is used to escape the StringEnd character, if it is part of a string (e.g. "\").
CharStart = The character that is used to start a character literal (e.g. single quote).
CharEnd = The character that is used to end a character literal (e.g. single quote).
CharEsc = The character that is used to escape the CharEnd character, if it is part of a character literal (e.g. "\").
Hope this was helpful.............good luck,
Bob
vpenacho1
Posts: 4
Joined: Thu Jan 22, 2004 9:42 pm

That's what I was looking for

Post by vpenacho1 »

Yep, that's the writeup I saw. I didn't remember it being in the help files.

Interesting to note that this whole discussion has been about the problems trying to use a semi-colon as it is interpreted as the start of comment in the syntax definition file but nowhere in the help does it even mention that there is a comment character.

I guess I'm stuck for now and will have to hope that a later revision is able to handle this.
Post Reply