@@ -42,6 +42,9 @@ Processing version Copyright (c) 2004-05 Ben Fry and Casey Reas
4242 * Class that orchestrates preprocessing p5 syntax into straight Java.
4343 */
4444public class PdePreprocessor {
45+
46+ private static final String IMPORT_REGEX = "^\\ s*#include\\ s*[<\" ](\\ S+)[\" >]" ;
47+
4548 // stores number of built user-defined function prototypes
4649 public int prototypeCount = 0 ;
4750
@@ -94,10 +97,9 @@ public int writePrefix(String program)
9497 }
9598
9699 //String importRegexp = "(?:^|\\s|;)(import\\s+)(\\S+)(\\s*;)";
97- String importRegexp = "^\\ s*#include\\ s*[<\" ](\\ S+)[\" >]" ;
98100 programImports = new ArrayList <String >();
99101
100- String [][] pieces = PApplet .matchAll (program , importRegexp );
102+ String [][] pieces = PApplet .matchAll (program , IMPORT_REGEX );
101103
102104 if (pieces != null )
103105 for (int i = 0 ; i < pieces .length ; i ++)
@@ -121,6 +123,19 @@ public int writePrefix(String program)
121123 return headerCount + prototypeCount ;
122124 }
123125
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+
124139
125140 static String substituteUnicode (String program ) {
126141 // check for non-ascii chars (these will be/must be in unicode format)
0 commit comments