RTF Syntax Hiliter: Numeric parms "attached" to keywords

Discuss syntax highlighting or submit new syntax files.
Post Reply
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by rjbill »

I couldn't find any info about my question anywhere.

In RTF files, numeric parameters are appended to the end of
Control Words without any symbols or whitespace.

So, for example, if the keyword is ri (right indent), there is a
numeric value attached to that for a value in Twips, like:

\ri1260

Before I embark on trying to create a syntax highlighter for RTF,
I wanted to make sure this was supported, so the values can be
colored as (e.g.):

\ri1260

Where "\ri" is the keyword and "1260" is a numeric value. (and the value
can be negative, so it could have a preceding "-" sign, which could be a
different color if that's the way it had to be)

Here is some example RTF code with some hand-highlighting:
(not the best color scheme)

{\rtf1\ansi\deff22

{\fonttbl{\f1\fcharset0 Abadi MT Condensed Extra Bold;}

{\stylesheet{\f22 \sbasedon222\snext0 Normal;}
{\s1\li2160\ri2160\f77\sb0 \sbasedon0\snext1 GENERAL;}
}

\widowctrl\ftnbj\ftnrestart\fracwidth \sectd \linemod0\linex0\cols1\endnhere
\margl0\margr0\paperw12240

{\pard\plain \ql \caps\sb240\f77\fs24\sl180\s3\fi0\ri1440\li2160 This is actual text}
}
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by rjbill »

I went ahead and made the Syntax file for RTF and it seems
to be working the way I thought it would, unless there is
something I can do.

Here is what I have so far.

Image

As you can see, the keywords without appended numeric values
are showing in Blue, but those with numeric values are showing
as Text.

This actually looks like a bug to me. I think numerics should use
alphas as delimiters, and vice-versa. (or it should be an option?)

I would also like the braces, and backslashes, to be different colors
than the other symbols because they are special. "\*" is also a
special Control Word, so I want it to be bold red.

If there isn't a way to do this, it would be nice to have symbols1,
symbols2, and symbols3.

Or, can keywords be single symbol characters or be composed of symbols?
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
User avatar
Rickard Johansson
Site Admin
Posts: 6575
Joined: 19 Jul 2006 14:29

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by Rickard Johansson »

Could you send me the syntax *.syx file or display it here in the forum?
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by rjbill »

I tried making {, }, \, and \* Keywords, and that works (kind of),
as long as {, }, and \, are not set as Symbols, which
overrides the Keyword colors.

Also, if you remove {, }, and \ from Symbols, it stops
showing the Control Word keywords, I suppose because
they are not delimited by Symbols then (\), so it only
colors them correctly if they have a SPACE or EOL as a delimiter.

I don't know if it would mess things up, but it might work if
Keyword coloring takes precedence over Symbol coloring.

I would think that would be the way you would want it anyway,
but maybe only if you have symbols as keywords or parts of keywords,
which might only be in certain circumstances, like RTF coding.
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by rjbill »

This is what I have now: (I removed most of the Control Words keywords below because there are about 1500 of them)

Code: Select all

;{$RTF;rtf.syx}

[Keywords]
Control Words=ab|absh|abslock|absnoovrlp|absw|acaps|acccircle|acccomma|accdot|accnone|accunderdot|acf|adeff|additive|adeflang|adjustright|adn|aenddoc|
Special Control Words=\*|
Braces=}|{|
Backslash=\|

[Options]
Symbols=.,<>?!#%/()=+-[];{}\
Numbers=0123456789
AddProjectClassesToCompletion=1
AutoCloseBlockStart={
AutoCloseBlockEnd=}
AutoCompleteCharA=.
AutoCompleteCharB= 

[Fold]
1_Id=
1_Begin={
1_End=}
1_EndBefore=
1_Section=
1_NoParentOfId=0
1_NotAlwaysEnded=0
1_ListItem=
The above generates this:

Image

So {, }, \, and \* are shown as Symbol (and Text) colors.
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
User avatar
Rickard Johansson
Site Admin
Posts: 6575
Joined: 19 Jul 2006 14:29

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by Rickard Johansson »

It's difficult to improve much, but this isn't so bad...

Code: Select all

;{$RTF;rtf.syx}

[Keywords]
Control Words=ab|absh|abslock|absnoovrlp|absw|acaps|acccircle|acccomma|accdot|accnone|accunderdot|acf|adeff|additive|adeflang|adjustright|adn|aenddoc|

[Options]
Symbols=.,<>?!#%/()=+-[]\{};0123456789
Numbers=
AddProjectClassesToCompletion=1
AutoCloseBlockStart={
AutoCloseBlockEnd=}
AutoCompleteCharA=.
AutoCompleteCharB= 

[Fold]
1_Id=
1_Begin={
1_End=}
1_EndBefore=
1_Section=
1_NoParentOfId=0
1_NotAlwaysEnded=0
1_ListItem=
I added 0..9 as symbols, removed numbers and removed some keyword groups.
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by rjbill »

Rickard Johansson wrote: {snip}
Yeah, thanks.

So what about the changes I suggested might be needed to support something like this more fully?

Are those never going to happen? (maybe because they would break something)

And I'm guessing "symbol characters" are not allowed as "keywords".

Or if they are, they will be "overwritten" by "symbol highlighting".

If you did support symbols, symbols2, and symbols3, that would be nice,
because then you could have some symbols one color, and others another color.
That might not be too hard to implement. (relatively speaking)

I wish you let people help with the development, and I wish I had the ability to do it.
(I do have the ability, I'm just not in a position to do it, unfortunately)
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
User avatar
Rickard Johansson
Site Admin
Posts: 6575
Joined: 19 Jul 2006 14:29

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by Rickard Johansson »

In v7.50 final this should work:

Code: Select all

[Options]
Symbols=.,<>?!#%/()=+-[]\{};0123456789
Numbers=0123456789
Numbers are treated as symbols but highlighted as numbers. Numbers are also recognized as numbers before, or after, keywords. E.g. marg10 could be highlighted as marg10.

Doing this for numbers is easy, but doing the same for keywords would probably bring down the drawing functions down to a crawl. Testing all entered symbols against every keyword takes some time and would have to be done when drawing and repeated every time a symbol is encountered.

I'll consider adding "Symbols2..." in a later version.
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by rjbill »

I assume there is a coloring sequence.

If we could select first keywords then symbols,
or first symbols then keywords, to choose which
gets preference, that would be nice for some
more obscure non-programming specs like RTF.

That, along with an additional symbol color would be great.
(two more would be better than one more, though, or, like
Keywords, allow as many as you want to create)

Since I don't know how you do it internally, I don't know
if that would be easy, or difficult, or "impossible".

For example, the 'control word' "\*" is very special and
I would like to make it bold red so it really stands out.
That's why I tried to make it a keyword group by itself.

And I would like to make the "\" symbol a special color
by itself because it is actually part of the keyword, but
would make the keywords stand out better because they
are usually next to each other without spacing, as in my
example. So a backslash doesn't stand out now if there
is a numeric parameter like: \sb240\f77
So you can see that the slash gets lost in the coloring and
doesn't look like the delimiter it is.

And, since braces are used as groupers, it would be nice to
see them as a different highlight, too.

It's interesting that you don't use alpha as delimiters for numbers, though.
Personally, I would want all numbers to be treated as numbers, no matter
what they were delimited by on either side.

Although, I guess that would potentially do weird things if you used numbers
as part of variable names and function names and such. Again, it could possibly
come down to the sequence you use in coloring, where one would override
another because it is done after the other.

If you colored numbers "first", then other situations would be okay, and
"all numbers" would be colored as numbers unless they were part of some
other thing, like a keyword.

But what you showed me will work better than nothing.
(although and even though there are a lot of anomalies / 'errors')

Thanks.
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
User avatar
Rickard Johansson
Site Admin
Posts: 6575
Joined: 19 Jul 2006 14:29

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by Rickard Johansson »

If you haven't already, install v7.50. Modify the lines below in your syntax file

Code: Select all

[Options]
Symbols=.,<>?!#%/()=+-[]\{};0123456789
Numbers=0123456789
and use a different color for symbols and numbers. You don't have to use the same color for \ and numbers.
User avatar
Rickard Johansson
Site Admin
Posts: 6575
Joined: 19 Jul 2006 14:29

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by Rickard Johansson »

Added a solution in the next version using something called "SymbolWords". Think of them as arrays with values separated by spaces. Each value has to have the same width. You can use up to 3 symbol word arrays with different value sizes. All symbols used must also exist in the "Symbols=" string.

E.x.
[Options]
Symbols=\*?
SymbolWordsA=\* \? \\
SymbolWordsB=\

Note that the larger values should be first "SymbolWordsA" and smaller declared later.

My test RTF syntax file now look like below:

Code: Select all

;{$RTF;rtf.syx}

[Keywords]
Control Words=ab|absh|abslock|absnoovrlp|absw|acaps|acccircle|acccomma|accdot|accnone|accunderdot|acf|adeff|additive|adeflang|adjustright|adn|aenddoc|

[Options]
Symbols=.,<>?!#*%/()=+-[]\{};0123456789
SymbolWordsA=\*
SymbolWordsB=\
Numbers=0123456789
AddProjectClassesToCompletion=1
AutoCloseBlockStart={
AutoCloseBlockEnd=}
AutoCompleteCharA=.
AutoCompleteCharB= 

[Fold]
1_Id=
1_Begin={
1_End=}
1_EndBefore=
1_Section=
1_NoParentOfId=0
1_NotAlwaysEnded=0
1_ListItem=
User avatar
rjbill
Posts: 872
Joined: 13 Jun 2011 06:36

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by rjbill »

Thanks. I just realized there is a new version. (I was two behind)
So I'll try it.
RJTE version 16.12 (actual) - 64-bit
Win 10 Pro 64-bit 8 GB RAM Intel Core i7-6700 3.40 GHz SCSI Hard Drive 1 TB

Note: The signature is dynamic, not static,
so it may not show the correct version above
that was in use at the time of the post.
tentionfree
Posts: 1
Joined: 21 Jan 2013 08:29

Re: RTF Syntax Hiliter: Numeric parms "attached" to keywords

Post by tentionfree »

Also, if you remove {, }, and \ from Symbols, it stops
showing the Control Word keywords, I suppose because
they are not delimited by Symbols then (\), so it only
colors them correctly if they have a SPACE or EOL as a delimiter.
Post Reply