Help to configure folding in my lexer

All questions regarding lexer highlighting schemes are discussed here...
RogerTunnicliffe
Posts: 10
Joined: 17.06.2025 04:35

Help to configure folding in my lexer

Post by RogerTunnicliffe »

Hi Alexey,
forgive me as am new to this and know little of Regex but I wonder if you could help me.

My language has the following constructs

repeat.if
end.repeat

If (and sometimes .If)
End.If

I am having problems with folding when it detects the "repeat" in the "end.repeat" and matches it with an "IF" that may following
ie.

Repeat.If
somecode
End.Repeat
If X = 1
somecode
End.If

are you able to point me in the right direction
Thx
Roger
main Alexey
Posts: 2541
Joined: 25.08.2021 18:15

Re: Folding problems

Post by main Alexey »

current lexer rules (regex) find only one word 'repeat' when text has 'repeat.if' ?
add the regex to find the whole thing 'repeat.if'. as one token.

some lexers do it: they have rule with regex [a-z_]\w* for usual words, and additional regex like

Code: Select all

(repeat\.if|end\.if|end\.repeat)\b
for special complex things.
this special rule must be placed _above_ usual rule.
RogerTunnicliffe
Posts: 10
Joined: 17.06.2025 04:35

Re: Folding problems

Post by RogerTunnicliffe »

Thx Alexey, I'll give it a shot tomorrow morning.
Cheers
Roger

Oh yeah. How do I reference that in the start and end block ?
main Alexey
Posts: 2541
Joined: 25.08.2021 18:15

Re: Folding problems

Post by main Alexey »

In the properties of the start/end block, check

[x] Identifier
(if regex-rule has kind 'Identifier')

and enter ID text:

end.if
main Alexey
Posts: 2541
Joined: 25.08.2021 18:15

Re: Folding problems

Post by main Alexey »

How my version of 'CVBasic' end-rule looks like:
Attachments
Screenshot from 2025-06-21 17-03-06.png
RogerTunnicliffe
Posts: 10
Joined: 17.06.2025 04:35

Re: Folding problems

Post by RogerTunnicliffe »

Thx Alexey

Okay, last alteration to this post.!!

I seem to have it working in some programs but not others

One program might have the REPEAT's working but the IF's fail.
One program might have The IF's working while the REPEAT.IF, and the REPEAT.WHILE works but the REPEAT.FOR fails
The Lexer doesn't change only the program ???

Also...How do I stop these Repeats showing up in the Code Tree

Cheers
Roger
main Alexey
Posts: 2541
Joined: 25.08.2021 18:15

Re: Folding problems

Post by main Alexey »

I don't undestand such vague questions. so, give me example file. with comments above blocks, which tell what you expect in each block.
and attach your .lcf file ( SynWrite/data/lexlib/LexerName.lcf ).
main Alexey
Posts: 2541
Joined: 25.08.2021 18:15

Re: Folding problems

Post by main Alexey »

>>How do I stop these Repeats showing up in the Code Tree

Synwrite's LexerProps dialog has this checkbox for each range-rule:
[x] Display in syntax tree
RogerTunnicliffe
Posts: 10
Joined: 17.06.2025 04:35

Re: Help to configure folding in my lexer

Post by RogerTunnicliffe »

Thx Alexey,

I have attached an archive.
You should be able to see when things work for one file but not the other
Cheers
Roger
Attachments
examples.zip
(19.23 KiB) Downloaded 2 times
main Alexey
Posts: 2541
Joined: 25.08.2021 18:15

Re: Help to configure folding in my lexer

Post by main Alexey »

if I understand right, repeat-blocks were not folded. I fixed it. you missed the checkbox 'Ignore case' for begin-rule / end-rule. I checked it. now repeat-blocks are folded, and if-blocks too.

advice. you named lexer styles like 'white', 'red', 'aqua'.... bad! name them by sense:
Number
String
Id
Keyword
etc

I also fixed few regex. e.g. lead/trailing space is IGNORED: so I replaced it with \x20.
Attachments
languageONE.zip
(2.13 KiB) Downloaded 3 times
Post Reply