1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

platforms.txt recipes now have symbolic variables instead of indexes ({0},{1},etc.)

Recipes arguments are splitted with spaces instead of |. Single argument containing spaces
should be placed between "double quotes".
Refactored and formatted Compiler class, removed all unused code in comments.
This commit is contained in:
Cristian Maglie
2011-12-31 14:32:48 +01:00
parent 1b3ae5fa63
commit abe41d805d
5 changed files with 500 additions and 656 deletions

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@ package processing.app.debug;
* An exception with a line number attached that occurs
* during either compile time or run time.
*/
@SuppressWarnings("serial")
public class RunnerException extends Exception /*RuntimeException*/ {
protected String message;
protected int codeIndex;
@ -64,6 +65,10 @@ public class RunnerException extends Exception /*RuntimeException*/ {
}
public RunnerException(Exception e) {
this(e.getMessage(), true);
}
/**
* Override getMessage() in Throwable, so that I can set
* the message text outside the constructor.

View File

@ -35,6 +35,14 @@ import processing.core.PApplet;
public class PreferencesMap extends HashMap<String, String> {
public PreferencesMap(PreferencesMap prefs) {
super(prefs);
}
public PreferencesMap() {
super();
}
/**
* Parse a property list file and put kev/value pairs into the Map
*
@ -67,6 +75,32 @@ public class PreferencesMap extends HashMap<String, String> {
}
}
/**
* Create a new Map<String, PreferenceMap> where the keys are the first level
* of the current mapping. E.g. the folowing mapping:<br />
*
* <pre>
* Map (
* alpha.some.keys = v1
* alpha.other.keys = v2
* beta.some.keys = v3
* )
* </pre>
*
* will generate the following result:
*
* <pre>
* alpha = Map(
* some.keys = v1
* other.keys = v2
* )
* beta = Map(
* some.keys = v3
* )
* </pre>
*
* @return
*/
public Map<String, PreferencesMap> createFirstLevelMap() {
Map<String, PreferencesMap> res = new HashMap<String, PreferencesMap>();
for (String key : keySet()) {
@ -84,5 +118,40 @@ public class PreferencesMap extends HashMap<String, String> {
return res;
}
/**
* Create a new PreferenceMap using a subtree of the current mapping. E.g.
* with the folowing mapping:<br />
*
* <pre>
* Map (
* alpha.some.keys = v1
* alpha.other.keys = v2
* beta.some.keys = v3
* )
* </pre>
*
* a call to createSubTree("alpha") will generate the following result:
*
* <pre>
* Map(
* some.keys = v1
* other.keys = v2
* )
* </pre>
*
* @param parent
* @return
*/
public PreferencesMap createSubTree(String parent) {
PreferencesMap res = new PreferencesMap();
parent += ".";
int parentLen = parent.length();
for (String key : keySet()) {
if (key.startsWith(parent))
res.put(key.substring(parentLen), get(key));
}
return res;
}
private static final long serialVersionUID = 2330591567444282843L;
}

View File

@ -0,0 +1,66 @@
package processing.app.helpers;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class StringReplacer {
public static String[] formatAndSplit(String src, Map<String, String> dict)
throws Exception {
// Do a replace with dictionary
src = StringReplacer.replaceFromMapping(src, dict);
// Split the resulting string in arguments
return quotedSplit(src, '"', false);
}
public static String[] quotedSplit(String src, char escapeChar,
boolean acceptEmptyArguments) throws Exception {
String quote = "" + escapeChar;
List<String> res = new ArrayList<String>();
String escapedArg = null;
boolean escaping = false;
for (String i : src.split(" ")) {
if (!escaping) {
if (!i.startsWith(quote)) {
if (!i.trim().isEmpty() || acceptEmptyArguments)
res.add(i);
continue;
}
escaping = true;
i = i.substring(1);
escapedArg = "";
}
if (!i.endsWith(quote)) {
escapedArg += i + " ";
continue;
}
escapedArg += i.substring(0, i.length() - 1);
if (!escapedArg.trim().isEmpty() || acceptEmptyArguments)
res.add(escapedArg);
escaping = false;
}
if (escaping)
throw new Exception("Invalid quoting: no closing '" + escapeChar
+ "' char found.");
return res.toArray(new String[0]);
}
public static String replaceFromMapping(String src, Map<String, String> map) {
return replaceFromMapping(src, map, "{", "}");
}
public static String replaceFromMapping(String src, Map<String, String> map,
String leftDelimiter, String rightDelimiter) {
for (String k : map.keySet()) {
String keyword = leftDelimiter + k + rightDelimiter;
src = src.replace(keyword, map.get(k));
}
return src;
}
}