mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
(Re-)implementing syntax highlighting support for library keywords.
This commit is contained in:
parent
f0c3263b2f
commit
59a85bfe59
@ -75,7 +75,9 @@ public class Base {
|
|||||||
static private File librariesFolder;
|
static private File librariesFolder;
|
||||||
static private File toolsFolder;
|
static private File toolsFolder;
|
||||||
static private File hardwareFolder;
|
static private File hardwareFolder;
|
||||||
|
|
||||||
|
static HashSet<File> libraries;
|
||||||
|
|
||||||
// maps imported packages to their library folder
|
// maps imported packages to their library folder
|
||||||
static HashMap<String, File> importToLibraryTable;
|
static HashMap<String, File> importToLibraryTable;
|
||||||
|
|
||||||
@ -962,6 +964,9 @@ public class Base {
|
|||||||
public void rebuildImportMenu(JMenu importMenu) {
|
public void rebuildImportMenu(JMenu importMenu) {
|
||||||
//System.out.println("rebuilding import menu");
|
//System.out.println("rebuilding import menu");
|
||||||
importMenu.removeAll();
|
importMenu.removeAll();
|
||||||
|
|
||||||
|
// reset the set of libraries
|
||||||
|
libraries = new HashSet<File>();
|
||||||
|
|
||||||
// reset the table mapping imports to libraries
|
// reset the table mapping imports to libraries
|
||||||
importToLibraryTable = new HashMap<String, File>();
|
importToLibraryTable = new HashMap<String, File>();
|
||||||
@ -1148,6 +1153,7 @@ public class Base {
|
|||||||
// // need to associate each import with a library folder
|
// // need to associate each import with a library folder
|
||||||
// String packages[] =
|
// String packages[] =
|
||||||
// Compiler.packageListFromClassPath(libraryClassPath);
|
// Compiler.packageListFromClassPath(libraryClassPath);
|
||||||
|
libraries.add(subfolder);
|
||||||
String packages[] = Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
|
String packages[] = Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
|
||||||
for (String pkg : packages) {
|
for (String pkg : packages) {
|
||||||
importToLibraryTable.put(pkg, subfolder);
|
importToLibraryTable.put(pkg, subfolder);
|
||||||
@ -1393,6 +1399,11 @@ public class Base {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static public Set<File> getLibraries() {
|
||||||
|
return libraries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static public String getExamplesPath() {
|
static public String getExamplesPath() {
|
||||||
|
@ -58,53 +58,11 @@ public class PdeKeywords extends CTokenMarker {
|
|||||||
try {
|
try {
|
||||||
keywordColoring = new KeywordMap(false);
|
keywordColoring = new KeywordMap(false);
|
||||||
keywordToReference = new Hashtable();
|
keywordToReference = new Hashtable();
|
||||||
|
getKeywords(Base.getLibStream("keywords.txt"));
|
||||||
InputStream input = Base.getLibStream("keywords.txt");
|
for (File lib : Base.getLibraries()) {
|
||||||
InputStreamReader isr = new InputStreamReader(input);
|
File keywords = new File(lib, "keywords.txt");
|
||||||
BufferedReader reader = new BufferedReader(isr);
|
if (keywords.exists()) getKeywords(new FileInputStream(keywords));
|
||||||
|
|
||||||
String line = null;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
//System.out.println("line is " + line);
|
|
||||||
// in case there's any garbage on the line
|
|
||||||
//if (line.trim().length() == 0) continue;
|
|
||||||
|
|
||||||
String pieces[] = processing.core.PApplet.split(line, '\t');
|
|
||||||
if (pieces.length >= 2) {
|
|
||||||
//int tab = line.indexOf('\t');
|
|
||||||
// any line with no tab is ignored
|
|
||||||
// meaning that a comment is any line without a tab
|
|
||||||
//if (tab == -1) continue;
|
|
||||||
|
|
||||||
String keyword = pieces[0].trim();
|
|
||||||
//String keyword = line.substring(0, tab).trim();
|
|
||||||
//String second = line.substring(tab + 1);
|
|
||||||
//tab = second.indexOf('\t');
|
|
||||||
//String coloring = second.substring(0, tab).trim();
|
|
||||||
//String htmlFilename = second.substring(tab + 1).trim();
|
|
||||||
String coloring = pieces[1].trim();
|
|
||||||
|
|
||||||
if (coloring.length() > 0) {
|
|
||||||
// text will be KEYWORD or LITERAL
|
|
||||||
boolean isKey = (coloring.charAt(0) == 'K');
|
|
||||||
// KEYWORD1 -> 0, KEYWORD2 -> 1, etc
|
|
||||||
int num = coloring.charAt(coloring.length() - 1) - '1';
|
|
||||||
byte id = (byte)
|
|
||||||
((isKey ? Token.KEYWORD1 : Token.LITERAL1) + num);
|
|
||||||
//System.out.println("got " + (isKey ? "keyword" : "literal") +
|
|
||||||
// (num+1) + " for " + keyword);
|
|
||||||
keywordColoring.add(keyword, id);
|
|
||||||
}
|
|
||||||
if (pieces.length >= 3) {
|
|
||||||
String htmlFilename = pieces[2].trim();
|
|
||||||
if (htmlFilename.length() > 0) {
|
|
||||||
keywordToReference.put(keyword, htmlFilename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
reader.close();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Base.showError("Problem loading keywords",
|
Base.showError("Problem loading keywords",
|
||||||
"Could not load keywords.txt,\n" +
|
"Could not load keywords.txt,\n" +
|
||||||
@ -114,6 +72,53 @@ public class PdeKeywords extends CTokenMarker {
|
|||||||
}
|
}
|
||||||
return keywordColoring;
|
return keywordColoring;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static private void getKeywords(InputStream input) throws Exception {
|
||||||
|
InputStreamReader isr = new InputStreamReader(input);
|
||||||
|
BufferedReader reader = new BufferedReader(isr);
|
||||||
|
|
||||||
|
String line = null;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
//System.out.println("line is " + line);
|
||||||
|
// in case there's any garbage on the line
|
||||||
|
//if (line.trim().length() == 0) continue;
|
||||||
|
|
||||||
|
String pieces[] = processing.core.PApplet.split(line, '\t');
|
||||||
|
if (pieces.length >= 2) {
|
||||||
|
//int tab = line.indexOf('\t');
|
||||||
|
// any line with no tab is ignored
|
||||||
|
// meaning that a comment is any line without a tab
|
||||||
|
//if (tab == -1) continue;
|
||||||
|
|
||||||
|
String keyword = pieces[0].trim();
|
||||||
|
//String keyword = line.substring(0, tab).trim();
|
||||||
|
//String second = line.substring(tab + 1);
|
||||||
|
//tab = second.indexOf('\t');
|
||||||
|
//String coloring = second.substring(0, tab).trim();
|
||||||
|
//String htmlFilename = second.substring(tab + 1).trim();
|
||||||
|
String coloring = pieces[1].trim();
|
||||||
|
|
||||||
|
if (coloring.length() > 0) {
|
||||||
|
// text will be KEYWORD or LITERAL
|
||||||
|
boolean isKey = (coloring.charAt(0) == 'K');
|
||||||
|
// KEYWORD1 -> 0, KEYWORD2 -> 1, etc
|
||||||
|
int num = coloring.charAt(coloring.length() - 1) - '1';
|
||||||
|
byte id = (byte)
|
||||||
|
((isKey ? Token.KEYWORD1 : Token.LITERAL1) + num);
|
||||||
|
//System.out.println("got " + (isKey ? "keyword" : "literal") +
|
||||||
|
// (num+1) + " for " + keyword);
|
||||||
|
keywordColoring.add(keyword, id);
|
||||||
|
}
|
||||||
|
if (pieces.length >= 3) {
|
||||||
|
String htmlFilename = pieces[2].trim();
|
||||||
|
if (htmlFilename.length() > 0) {
|
||||||
|
keywordToReference.put(keyword, htmlFilename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static public String getReference(String keyword) {
|
static public String getReference(String keyword) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user