From c3e1a9443cda7402d7e54360017536e526d18584 Mon Sep 17 00:00:00 2001 From: "ricardo.jl.rufino" Date: Wed, 22 Apr 2015 13:50:10 -0300 Subject: [PATCH] simple code refactor on PdePreprocessor --- .../app/preproc/PdePreprocessor.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arduino-core/src/processing/app/preproc/PdePreprocessor.java b/arduino-core/src/processing/app/preproc/PdePreprocessor.java index 576f7468b..dc30922a9 100644 --- a/arduino-core/src/processing/app/preproc/PdePreprocessor.java +++ b/arduino-core/src/processing/app/preproc/PdePreprocessor.java @@ -42,6 +42,9 @@ import java.util.regex.*; * Class that orchestrates preprocessing p5 syntax into straight Java. */ public class PdePreprocessor { + + private static final String IMPORT_REGEX = "^\\s*#include\\s*[<\"](\\S+)[\">]"; + // stores number of built user-defined function prototypes public int prototypeCount = 0; @@ -94,10 +97,9 @@ public class PdePreprocessor { } //String importRegexp = "(?:^|\\s|;)(import\\s+)(\\S+)(\\s*;)"; - String importRegexp = "^\\s*#include\\s*[<\"](\\S+)[\">]"; programImports = new ArrayList(); - String[][] pieces = PApplet.matchAll(program, importRegexp); + String[][] pieces = PApplet.matchAll(program, IMPORT_REGEX); if (pieces != null) for (int i = 0; i < pieces.length; i++) @@ -121,6 +123,19 @@ public class PdePreprocessor { return headerCount + prototypeCount; } + public static List findIncludes(String code){ + + String[][] pieces = PApplet.matchAll(code, IMPORT_REGEX); + + ArrayList programImports = new ArrayList(); + + if (pieces != null) + for (int i = 0; i < pieces.length; i++) + programImports.add(pieces[i][1]); // the package name + + return programImports; + } + static String substituteUnicode(String program) { // check for non-ascii chars (these will be/must be in unicode format)