@@ -12,7 +12,7 @@ namespace ZXBasicStudio.DocumentEditors.ZXTextEditor.Classes.Folding
1212{
1313 public class ZXBasicFoldingStrategy : AbstractFoldingStrategy
1414 {
15- Regex regStartSubFold = new Regex ( "(^|:)[^\\ S\\ r\\ n^:]*(fastcall)?[^\\ S\\ r\\ n^:]*?(sub|function)\\ s+(fastcall\\ s+)?([^\\ s\\ (]+)\\ ([^\\ n]*?$" , RegexOptions . Multiline | RegexOptions . IgnoreCase ) ;
15+ Regex regStartSubFold = new Regex ( "(^|:)[^\\ S\\ r\\ n^:]*(fastcall)?[^\\ S\\ r\\ n^:]*?(sub|function)\\ s+(fastcall\\ s+)?([^\\ s\\ (]+)\\ s*? \\ ([^\\ n]*?$" , RegexOptions . Multiline | RegexOptions . IgnoreCase ) ;
1616 Regex regEndSubFold = new Regex ( "(^|[^\\ S\\ r\\ n^:]+|:)[^\\ S\\ r\\ n^:]*?end\\ s+(sub|function)" , RegexOptions . Multiline | RegexOptions . IgnoreCase ) ;
1717
1818 Regex regStartCommentFold = new Regex ( "/'" , RegexOptions . Multiline | RegexOptions . IgnoreCase ) ;
@@ -27,6 +27,9 @@ public class ZXBasicFoldingStrategy : AbstractFoldingStrategy
2727 Regex regStartMultiDefine = new Regex ( "^[^\\ S$\\ n]*?#define\\ s+(\\ w+(\\ ([^\\ )]*\\ )?))[^\\ n]*?\\ \\ [^\\ S$\\ n]*?$" , RegexOptions . Multiline | RegexOptions . IgnoreCase ) ;
2828 Regex regEndMultiDefine = new Regex ( "^[^\\ \\ ]*?$" , RegexOptions . Multiline | RegexOptions . IgnoreCase ) ;
2929
30+ Regex regStartProcedure = new Regex ( "^\\ s*?PROC\\ s*?[\\ r\\ n;]" , RegexOptions . Multiline | RegexOptions . IgnoreCase ) ;
31+ Regex regEndProcedure = new Regex ( "^\\ s*?ENDP\\ s*?[\\ r\\ n;]" , RegexOptions . Multiline | RegexOptions . IgnoreCase ) ;
32+
3033 public override IEnumerable < NewFolding > CreateNewFoldings ( TextDocument document , out int firstErrorOffset )
3134 {
3235 int subError = - 1 ;
@@ -39,15 +42,18 @@ public override IEnumerable<NewFolding> CreateNewFoldings(TextDocument document,
3942 var regionFoldings = CreateRegionFoldings ( document , out regionError ) ;
4043 int defineError = - 1 ;
4144 var defineFoldings = CreateMultiDefineFoldings ( document , out defineError ) ;
45+ int procedureError = - 1 ;
46+ var procedureFoldings = CreateProcedureFoldings ( document , out procedureError ) ;
4247
4348 List < NewFolding > allFoldings = new List < NewFolding > ( ) ;
4449 allFoldings . AddRange ( subFoldings ) ;
4550 allFoldings . AddRange ( commentFoldings ) ;
4651 allFoldings . AddRange ( dimFoldings ) ;
4752 allFoldings . AddRange ( regionFoldings ) ;
4853 allFoldings . AddRange ( defineFoldings ) ;
54+ allFoldings . AddRange ( procedureFoldings ) ;
4955
50- int [ ] errs = new int [ ] { subError , commentError , dimError , regionError , defineError } ;
56+ int [ ] errs = new int [ ] { subError , commentError , dimError , regionError , defineError , procedureError } ;
5157
5258 firstErrorOffset = ! errs . Any ( e => e != - 1 ) ? - 1 : errs . Where ( e => e != - 1 ) . Min ( ) ;
5359
@@ -201,6 +207,31 @@ private IEnumerable<NewFolding> CreateMultiDefineFoldings(TextDocument document,
201207 foldings . Add ( new NewFolding { StartOffset = start . Index , EndOffset = end . Index + end . Length - disp , DefaultClosed = true , IsDefinition = true , Name = name } ) ;
202208 }
203209
210+ return foldings ;
211+ }
212+ private IEnumerable < NewFolding > CreateProcedureFoldings ( TextDocument document , out int firstErrorOffset )
213+ {
214+ firstErrorOffset = - 1 ;
215+
216+ List < NewFolding > foldings = new List < NewFolding > ( ) ;
217+ var startFoldings = regStartProcedure . Matches ( document . Text ) . ToArray ( ) ;
218+
219+ for ( int buc = 0 ; buc < startFoldings . Length ; buc ++ )
220+ {
221+ var start = startFoldings [ buc ] ;
222+
223+ var end = regEndProcedure . Match ( document . Text , start . Index + start . Length ) ;
224+
225+ if ( end == null || ! end . Success )
226+ continue ;
227+
228+ string name = "PROC" ;
229+
230+ int disp = end . Value . EndsWith ( '\n ' ) || end . Value . EndsWith ( '\r ' ) ? 1 : 0 ;
231+
232+ foldings . Add ( new NewFolding { StartOffset = start . Index , EndOffset = end . Index + end . Length - disp , DefaultClosed = false , IsDefinition = false , Name = name } ) ;
233+ }
234+
204235 return foldings ;
205236 }
206237 }
0 commit comments