@@ -35,36 +35,37 @@ public class SketchParser {
3535
3636 String [] codeTabs ;
3737 boolean requiresComment ;
38- ArrayList <ColorMode > colorModes ;
38+ List <ColorMode > colorModes ;
3939
4040 List <List <Range >> scientificNotations ;
41-
41+
4242 Range setupFunction ;
43-
43+
4444 List <List <Range >> commentBlocks ;
4545 List <int []> curlyScopes ;
46-
46+
47+
4748 public SketchParser (String [] codeTabs , boolean requiresComment ) {
4849 this .codeTabs = codeTabs ;
4950 this .requiresComment = requiresComment ;
50- intVarCount = 0 ;
51- floatVarCount = 0 ;
52-
51+ intVarCount = 0 ;
52+ floatVarCount = 0 ;
53+
5354 // get all comment blocks
5455 commentBlocks = new ArrayList <>();
5556 for (String code : codeTabs ) {
5657 commentBlocks .add (getCommentBlocks (code ));
5758 }
58-
59+
5960 // get setup function range (to ignore all numbers there)
6061 setupFunction = new Range (getSetupStart (codeTabs [0 ]), getSetupEnd (codeTabs [0 ]));
61-
62+
6263 // build curly scope for every character in the code
6364 curlyScopes = new ArrayList <>();
6465 for (String code : codeTabs ) {
65- curlyScopes .add (getCurlyScopes (code ));
66+ curlyScopes .add (getCurlyScopes (code ));
6667 }
67-
68+
6869 // get all scientific notation (to ignore them)
6970 scientificNotations = getAllScientificNotations ();
7071
@@ -84,7 +85,7 @@ public SketchParser(String[] codeTabs, boolean requiresComment) {
8485 }
8586
8687
87- public void addAllNumbers () {
88+ private void addAllNumbers () {
8889 allHandles = new ArrayList <>();
8990
9091 addAllDecimalNumbers ();
@@ -123,7 +124,7 @@ private void addAllDecimalNumbers() {
123124 // ignore comments
124125 continue ;
125126 }
126-
127+
127128 if (setupFunction .contains (start )) {
128129 // ignore numbers in setup
129130 continue ;
@@ -215,7 +216,7 @@ private void addAllHexNumbers() {
215216 // ignore comments
216217 continue ;
217218 }
218-
219+
219220 if (setupFunction .contains (start )) {
220221 // ignore number in setup
221222 continue ;
@@ -276,7 +277,7 @@ private void addAllWebColorNumbers() {
276277 // ignore comments
277278 continue ;
278279 }
279-
280+
280281 if (setupFunction .contains (start )) {
281282 // ignore number in setup
282283 continue ;
@@ -380,7 +381,7 @@ private void createColorBoxes() {
380381 // ignore colors in a comment
381382 continue ;
382383 }
383-
384+
384385 if (setupFunction .contains (m .start ())) {
385386 // ignore number in setup
386387 continue ;
@@ -464,7 +465,7 @@ private void createColorBoxesForLights() {
464465 // ignore colors in a comment
465466 continue ;
466467 }
467-
468+
468469 if (setupFunction .contains (m .start ())) {
469470 // ignore number in setup
470471 continue ;
@@ -683,28 +684,28 @@ static private boolean isInsideString(int pos, String code) {
683684
684685 return false ;
685686 }
686-
687+
687688 /**
688689 * Builds an int array for every tab that represents the scope depth at each character
689- *
690+ *
690691 * @return
691692 */
692693 static private int [] getCurlyScopes (String code )
693694 {
694695 List <Range > comments = getCommentBlocks (code );
695-
696+
696697 int [] scopes = new int [code .length ()];
697698 int curlyScope = 0 ;
698699 boolean arrayAssignmentMaybeCommingFlag = false ;
699700 int arrayAssignmentCurlyScope = 0 ;
700701 for (int pos =0 ; pos <code .length (); pos ++) {
701702 scopes [pos ] = curlyScope ;
702-
703+
703704 if (isInRangeList (pos , comments )) {
704705 // we are inside a comment, ignore and move on
705706 continue ;
706707 }
707-
708+
708709 if (code .charAt (pos ) == '{' ) {
709710 if (arrayAssignmentMaybeCommingFlag ||
710711 arrayAssignmentCurlyScope >0 ) {
@@ -731,10 +732,10 @@ else if (!isWhiteSpace(code.charAt(pos))) {
731732 arrayAssignmentMaybeCommingFlag = false ;
732733 }
733734 }
734-
735+
735736 return scopes ;
736737 }
737-
738+
738739 static private boolean isWhiteSpace (char c ) {
739740 return c == ' ' || c == '\t' || c == '\n' || c == '\r' ;
740741 }
@@ -745,15 +746,15 @@ static private boolean isWhiteSpace(char c) {
745746 * @param codeTabIndex index of the code in codeTabs
746747 * @return
747748 * true if the position 'pos' is in global scope in the code 'codeTabs[codeTabIndex]'
748- *
749+ *
749750 */
750751 private boolean isGlobal (int pos , int codeTabIndex ) {
751752 return (curlyScopes .get (codeTabIndex )[pos ]==0 );
752753 };
753754
754- public static List <Range > getCommentBlocks (String code ) {
755+ static private List <Range > getCommentBlocks (String code ) {
755756 List <Range > commentBlocks = new ArrayList <Range >();
756-
757+
757758 int lastBlockStart =0 ;
758759 boolean lookForEnd = false ;
759760 for (int pos =0 ; pos <code .length ()-1 ; pos ++) {
@@ -775,19 +776,19 @@ else if (code.charAt(pos) == '/' && code.charAt(pos+1) == '/') {
775776 commentBlocks .add (new Range (pos , getEndOfLine (pos , code )));
776777 }
777778 }
778-
779+
779780 }
780-
781+
781782 return commentBlocks ;
782783 }
783-
784+
784785 private static boolean isInRangeList (int pos , List <Range > rangeList ) {
785786 for (Range r : rangeList ) {
786787 if (r .contains (pos )) {
787788 return true ;
788789 }
789790 }
790-
791+
791792 return false ;
792793 }
793794
@@ -826,7 +827,7 @@ else if (readObject) {
826827 }
827828
828829
829- public static int getSetupStart (String code ) {
830+ static public int getSetupStart (String code ) {
830831 Pattern p = Pattern .compile ("void[\\ s\\ t\\ r\\ n]*setup[\\ s\\ t]*\\ (\\ )[\\ s\\ t\\ r\\ n]*\\ {" );
831832 Matcher m = p .matcher (code );
832833
@@ -836,42 +837,43 @@ public static int getSetupStart(String code) {
836837
837838 return -1 ;
838839 }
839-
840- public static int getSetupEnd (String code ) {
840+
841+
842+ static public int getSetupEnd (String code ) {
841843 List <Range > comments = getCommentBlocks (code );
842-
844+
843845 int setupStart = getSetupStart (code );
844846 if (setupStart == -1 ) {
845847 return -1 ;
846848 }
847-
849+
848850 System .out .println ("setup start = " + setupStart );
849-
851+
850852 // count brackets to look for setup end
851853 int bracketCount =1 ;
852854 int pos = setupStart ;
853855 while (bracketCount >0 && pos <code .length ()) {
854-
856+
855857 if (isInRangeList (pos , comments )) {
856858 // in a comment, ignore and move on
857859 pos ++;
858860 continue ;
859861 }
860-
862+
861863 if (code .charAt (pos ) == '{' ) {
862864 bracketCount ++;
863865 }
864866 else if (code .charAt (pos ) == '}' ) {
865867 bracketCount --;
866868 }
867-
869+
868870 pos ++;
869871 }
870-
872+
871873 if (bracketCount == 0 ) {
872874 return pos -1 ;
873875 }
874-
876+
875877 return -1 ;
876878 }
877879
@@ -880,12 +882,12 @@ static class Range {
880882 int start ;
881883 int end ;
882884
883- public Range (int s , int e ) {
885+ Range (int s , int e ) {
884886 start = s ;
885887 end = e ;
886888 }
887889
888- public boolean contains (int v ) {
890+ boolean contains (int v ) {
889891 return v >= start && v < end ;
890892 }
891893 }
0 commit comments