Help with code folding in custom syntax?

Discuss syntax highlighting or submit new syntax files.
Post Reply
NTB
Posts: 9
Joined: 08 May 2010 15:40

Help with code folding in custom syntax?

Post by NTB »

Can't quite get this to work, so I was wondering if anybody here had any suggestions :)

I'm trying to create a custom syntax file for a language called Envision Basic - I work for a University that uses a system called Datatel Colleague for all of their record-keeping purposes, and this is the language used to make any customizations we want to the basic system that Datatel sells. If anyone here is familiar with IBM's Unidata database and it's UniBasic language, EB is very similar.

I think part of my problem is that EB doesn't use braces to define blocks; it only uses the keywords themselves. So, for an 'IF' statement, you could have:

Code: Select all

IF X GT Y THEN Y = X
OR

Code: Select all

IF X GT Y THEN
  *
  *Code to execute
  *
END
OR

Code: Select all

IF X GT Y THEN
  *
  *Do one thing
  *
END ELSE
  *
  *Do something else
  *
END
The 1st example doesn't need to be folded; it's all on one line. The 2nd should fold between 'IF' and 'END', and the 3rd should fold (A) between 'IF' and 'END ELSE' and (B) between 'END ELSE' and 'END'.

On a single level these all work, and even 'nesting' works as long as you stick with IF/END or IF/END ELSE/END blocks. But a nested, single-line 'IF' statement like this:

Code: Select all

IF X GT Y THEN
  IF Y EQ 0 THEN
END
will throw everything beneath it off, as far as folding is concerned - in that example, the fold starts at the 2nd 'IF', and ends at 'END', when it *should* start at the 1st 'IF'. Any suggestions?

I have a similar problem trying to fold CASE statements:

Code: Select all

BEGIN CASE
  CASE 1
    *
    *code
    *
  CASE 2
    *
    *code
    *
  CASE 3
    *
    *code
    *
END CASE
I can collapse the entire CASE structure between 'BEGIN CASE' and 'END CASE', but not the individual 'CASE' statements themselves.

Any suggestions on either of these would be greatly appreciated :)

Thanks!

Nathan
User avatar
Rickard Johansson
Site Admin
Posts: 6627
Joined: 19 Jul 2006 14:29

Post by Rickard Johansson »

For case structures you could create folds by indention. It's not perfect though. For an example take a look at the Boo.syx file.

I'll try to solve the "If" issues but it wont be easy. There is nothing that tells us which "If" statement we should use to create the fold, except maybe the indention.
User avatar
Rickard Johansson
Site Admin
Posts: 6627
Joined: 19 Jul 2006 14:29

Post by Rickard Johansson »

Actually, these fold settings should work pretty well I think:

Id=If
Begin=
End=
EndBefore=\in
Section=
NoParentOfId=0
NotAlwaysEnded=0
ListItem=

Id=ElseIf
Begin=
End=
EndBefore=\in
Section=
NoParentOfId=0
NotAlwaysEnded=0
ListItem=

Id=Else
Begin=
End=End If
EndBefore=
Section=
NoParentOfId=0
NotAlwaysEnded=0
ListItem=
Post Reply