Page 1 of 2
if .. elif .. end if
Posted: 23.08.2018 12:09
by jmp0x2a
Hi, tried to implement
if .. [elif ..] end if in lexer in a way i can independently close the blocks like this
is there a way to achieve this?
Posted: 23.08.2018 12:57
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 )
Posted: 23.08.2018 14:39
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
Posted: 24.08.2018 13:27
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
Posted: 24.08.2018 17:53
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.
Posted: 28.08.2018 15:00
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
Posted: 28.08.2018 22:50
by Alexey
yes, it seems so to me.
Posted: 07.12.2018 07:47
by Alexey
So what have you done? some lexer for popular lang? then pls show.
Posted: 08.12.2018 21:45
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.
Posted: 08.12.2018 22:03
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