I'm creating a library for a chip I'm using, and everything works fine except for keyword highlighting.
Function names (KEYWORD2) work properly, but the class name (KEYWORD1) doesn't.
My class name is "SR74595". I'm thinking it might have something to do with the fact that the second letter isn't lower case, but the tutorial here has a class named "LED13", so that wouldn't make any sense.
Here's a screenshot so you can see that I've followed the instructions:
Separated by tabs. I used multiple tabs for the "write" function and it still highlights properly. You can see that in the screenshot.
There's not much documentation on "keywords.txt". Is the specification a single tab? Or just "tabs not spaces"? Multiple tabs seem to work for KEYWORD2, so I would assume the same is true for KEYWORD1.
Do you know where I can find the specs for keywords.txt? If they're not anywhere public, I'd like to find out what they are, and add them to the wiki.
Working now. It seems the rules in keywords.txt are applied inconsistently. I can only have a single tab for KEYWORD1, but I can have an arbitrary number of tabs for KEYWORD2.
I had a look through the source for 0021, and found this function in /app/src/processing/app/syntax/PdeKeywords.java:
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();
}
It seems to be the only code containing the string "KEYWORD1" that is looking for tab characters, then doing something. I haven't touched java in years, so it's looking a bit like mandarin at the moment. I wouldn't be able to say why there's a difference in what's allowed between KEYWORD1 and KEYWORD2.