@@ -6,47 +6,78 @@ export interface Variable {
6
6
type ?: string ;
7
7
}
8
8
9
- export interface Function {
9
+
10
+ export interface Subroutine {
11
+
10
12
name : string ;
11
13
args : Variable [ ] ;
12
- return : Variable ;
13
14
docstr : string ;
14
15
lineNumber : number
15
16
}
16
17
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
+
17
28
18
29
19
30
export function getDeclaredFunctions ( document : vscode . TextDocument ) : Function [ ] {
20
31
21
32
let lines = document . lineCount ;
22
- let funs = [ ] ;
33
+ let funcs = [ ] ;
23
34
24
35
for ( let i = 0 ; i < lines ; i ++ ) {
25
36
let line : vscode . TextLine = document . lineAt ( i ) ;
26
37
if ( line . isEmptyOrWhitespace ) continue ;
27
38
let newFunc = parseFunction ( line . text )
28
39
if ( newFunc ) {
29
- funs . push ( { ...newFunc , lineNumber : i } ) ;
40
+ funcs . push ( { ...newFunc , lineNumber : i } ) ;
30
41
}
31
42
}
32
- return funs ;
43
+ return funcs ;
33
44
}
34
45
46
+ export function getDeclaredSubroutines ( document : vscode . TextDocument ) :Subroutine [ ] {
47
+
48
+ return [ ] ;
49
+ }
50
+
51
+
52
+
35
53
export const parseFunction = ( line : string ) => {
36
54
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 ) => {
39
63
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 ) ) {
40
68
let [ name , argsstr ] = functionRegEx . exec ( line ) . slice ( 1 , 3 ) ;
41
69
let args = ( argsstr ) ? parseArgs ( argsstr ) : [ ] ;
42
70
return {
43
71
name : name ,
44
- args : args ,
45
- return : null
72
+ args : args
46
73
} ;
47
74
}
75
+
48
76
}
49
77
78
+
79
+
80
+
50
81
export const parseArgs = ( argsstr : string ) => {
51
82
let args = argsstr . trim ( ) . split ( ',' ) ;
52
83
let variables : Variable [ ] = args . filter ( name => validVariableName ( name ) )
0 commit comments