if .. elif .. end if

All questions regarding lexer highlighting schemes are discussed here...
jmp0x2a
Posts: 4
Joined: 23.08.2018 11:51

if .. elif .. end if

Post by jmp0x2a »

Hi, tried to implement if .. [elif ..] end if in lexer in a way i can independently close the blocks like this

Code: Select all

+ if
| ...
+ elif
| ...
- end if
is there a way to achieve this?
jmp0x2a
Posts: 4
Joined: 23.08.2018 11:51

Post by jmp0x2a »

tried to implement this the hard (?) way creating rules for every possible combination and ordering them in the correct way, it somehow works now, but when i close a block, it makes closing of the next impossible, is there a way to exclude that line?

(since i can not upload zip/inf/lcf, here is the link to the zip i exported from SynWrite http://0x2a.tech/lexer.toyLang.zip )
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

Seems there is way to shrink ending of a block: for "end rule" you can set "block offset" (value >0 or <0, forgot).

and: this folding of middle parts - is unusual, weird.
if you configure it, Ok though.

http://wiki.freepascal.org/CudaText#I_h ... bute_it.3F
jmp0x2a
Posts: 4
Joined: 23.08.2018 11:51

Post by jmp0x2a »

folding of middle parts - is unusual
take for example a simple shell script

Code: Select all

if [ $this ]; then
  pwd
elif [ $that ]; then
  date
else
  ls -la
fi
Cuda folds from if to fi
N++ in default does nothing... but with a user defined language there is a middle folding option so i can config it to work fine
VC can handle this

for most languages its not a problem, since they usually use a single word to close of any block, use indentation or use some kind of block nominating character ( { and } in case of C like languages ), sadly, i want to use an SQL based language that uses this wierd syntax.

https://www.ibm.com/support/knowledgece ... qt_460.htm
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

"create function" to "end function"? It's possible to fold this. Maybe see SQL (several) lexers, or T-SQL lexer.

update. T-SQL lexer has example: "begin try" to "end try" and other blocks like it.
jmp0x2a
Posts: 4
Joined: 23.08.2018 11:51

Post by jmp0x2a »

no, not the "create function" to "end function" part, but the IF .. ELIF .. ELSE .. END IF part i want to fold. Looks like the current lexer can not do this :(
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

yes, it seems so to me.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

So what have you done? some lexer for popular lang? then pls show.
Shando
Posts: 13
Joined: 11.10.2018 02:25

Post by Shando »

@jmp0x2a Do you mean you want to fold like this:

Code: Select all

if x = 1 then
    Do something
elif x= 2 then
    Do something else
else
    Do this
end
folded:

Code: Select all

if x = 1 then
elif x= 2 then
else
end
where each part can be folded individually?

If so, the Falcon Lexer can do this. In the rules there are:

1) a standard 'end' rule
2) a standard 'if' rule that uses the 'end' rule
3) an 'elif end' rule that closes on 'elif', 'else' & 'end'
4) an 'elif' rule
5) an 'else' rule
6) an 'else end' rule (not sure this is required though?)

HTH

Shando

EDIT: Sorry, looks like Falcon can't close the 'if' individually, it closes the whole block (i.e. to the 'end'). I'll have a quick play and see if I can fix it.
Shando
Posts: 13
Joined: 11.10.2018 02:25

Post by Shando »

OK, looks like you'll need to add the following rules:

PROPERTIES = 'if end' as a 'Range End' with a 'Block Offset' of 1 - CONDITIONS = 'id' and Keys List = 'elif', 'else', end'
PROPERTIES = 'if' as a 'Range Start' with a 'Range End' of 'if end' - CONDITIONS = 'id' and Keys List = 'if'
PROPERTIES = 'elif' as a 'Range Start' with a 'Range End' of 'elif end' - TEXT RANGE = 'Self Closing Range' - CONDITIONS = 'id' and Keys List = 'elif'
PROPERTIES = 'elif end' as a 'Range End' with a 'Block Offset' of 1 - CONDITIONS = 'id' and Keys List = 'else', 'end'
PROPERTIES = 'else' as a 'Range Start' - CONDITIONS = 'id' and Keys List = 'else'
PROPERTIES = 'else end' as a 'Range End' with a 'Range Start' of 'else' - CONDITIONS = 'id' and Keys List = 'end'

The above seem to work fine in the Falcon Lexer.

Shando
Locked