@@ -6,47 +6,78 @@ export interface Variable {
66 type ?: string ;
77}
88
9- export interface Function {
9+
10+ export interface Subroutine {
11+
1012 name : string ;
1113 args : Variable [ ] ;
12- return : Variable ;
1314 docstr : string ;
1415 lineNumber : number
1516}
1617
18+ export interface Function extends Subroutine {
19+
20+ return : Variable ; // function is a subroutine with return type
21+ }
22+
23+ export enum MethodType {
24+ Subroutine ,
25+ Function
26+ } ;
27+
1728
1829
1930export function getDeclaredFunctions ( document : vscode . TextDocument ) : Function [ ] {
2031
2132 let lines = document . lineCount ;
22- let funs = [ ] ;
33+ let funcs = [ ] ;
2334
2435 for ( let i = 0 ; i < lines ; i ++ ) {
2536 let line : vscode . TextLine = document . lineAt ( i ) ;
2637 if ( line . isEmptyOrWhitespace ) continue ;
2738 let newFunc = parseFunction ( line . text )
2839 if ( newFunc ) {
29- funs . push ( { ...newFunc , lineNumber : i } ) ;
40+ funcs . push ( { ...newFunc , lineNumber : i } ) ;
3041 }
3142 }
32- return funs ;
43+ return funcs ;
3344}
3445
46+ export function getDeclaredSubroutines ( document : vscode . TextDocument ) :Subroutine [ ] {
47+
48+ return [ ] ;
49+ }
50+
51+
52+
3553export const parseFunction = ( line : string ) => {
3654
37- const functionRegEx = / f u n c t i o n \s * ( [ a - z A - Z ] [ a - z A - Z 0 - 9 _ ] * ) \s * \( ( \s * [ a - z A - z ] [ a - z A - z 0 - 9 _ , \s ] * ) * \s * \) / g
38- if ( line . match ( functionRegEx ) ) {
55+ return _parse ( line , MethodType . Function ) ;
56+ }
57+
58+ export const parseSubroutine = ( line : string ) => {
59+
60+ return _parse ( line , MethodType . Subroutine ) ;
61+ }
62+ export const _parse = ( line : string , type : MethodType ) => {
3963
64+ const functionRegEx = / ( [ a - z A - Z ] + ( \( [ \w . = ] + \) ) * ) * \s * f u n c t i o n \s * ( [ a - z A - Z _ ] [ a - z A - Z 0 - 9 _ ] * ) \s * \( ( \s * [ a - z A - z ] [ a - z A - z 0 - 9 _ , \s ] * ) * \s * \) \s * ( r e s u l t \( [ a - z A - z _ ] [ \w ] * \) ) * / g;
65+ const subroutineRegEx = / s u b r o u t i n e \s * ( [ a - z A - Z ] [ a - z A - Z 0 - 9 _ ] * ) \s * \( ( \s * [ a - z A - z ] [ a - z A - z 0 - 9 _ , \s ] * ) * \s * \) / g
66+ const regEx = ( type === MethodType . Subroutine ) ?subroutineRegEx : functionRegEx ;
67+ if ( line . match ( regEx ) ) {
4068 let [ name , argsstr ] = functionRegEx . exec ( line ) . slice ( 1 , 3 ) ;
4169 let args = ( argsstr ) ? parseArgs ( argsstr ) : [ ] ;
4270 return {
4371 name : name ,
44- args : args ,
45- return : null
72+ args : args
4673 } ;
4774 }
75+
4876}
4977
78+
79+
80+
5081export const parseArgs = ( argsstr : string ) => {
5182 let args = argsstr . trim ( ) . split ( ',' ) ;
5283 let variables : Variable [ ] = args . filter ( name => validVariableName ( name ) )
0 commit comments