@@ -42,6 +42,9 @@ Processing version Copyright (c) 2004-05 Ben Fry and Casey Reas
42
42
* Class that orchestrates preprocessing p5 syntax into straight Java.
43
43
*/
44
44
public class PdePreprocessor {
45
+
46
+ private static final String IMPORT_REGEX = "^\\ s*#include\\ s*[<\" ](\\ S+)[\" >]" ;
47
+
45
48
// stores number of built user-defined function prototypes
46
49
public int prototypeCount = 0 ;
47
50
@@ -94,10 +97,9 @@ public int writePrefix(String program)
94
97
}
95
98
96
99
//String importRegexp = "(?:^|\\s|;)(import\\s+)(\\S+)(\\s*;)";
97
- String importRegexp = "^\\ s*#include\\ s*[<\" ](\\ S+)[\" >]" ;
98
100
programImports = new ArrayList <String >();
99
101
100
- String [][] pieces = PApplet .matchAll (program , importRegexp );
102
+ String [][] pieces = PApplet .matchAll (program , IMPORT_REGEX );
101
103
102
104
if (pieces != null )
103
105
for (int i = 0 ; i < pieces .length ; i ++)
@@ -121,6 +123,19 @@ public int writePrefix(String program)
121
123
return headerCount + prototypeCount ;
122
124
}
123
125
126
+ public static List <String > findIncludes (String code ){
127
+
128
+ String [][] pieces = PApplet .matchAll (code , IMPORT_REGEX );
129
+
130
+ ArrayList programImports = new ArrayList <String >();
131
+
132
+ if (pieces != null )
133
+ for (int i = 0 ; i < pieces .length ; i ++)
134
+ programImports .add (pieces [i ][1 ]); // the package name
135
+
136
+ return programImports ;
137
+ }
138
+
124
139
125
140
static String substituteUnicode (String program ) {
126
141
// check for non-ascii chars (these will be/must be in unicode format)
0 commit comments