Skip to content

Commit e6d003d

Browse files
committed
Highlighting of keywords with parens, fixes processing#2099
1 parent fca707f commit e6d003d

6 files changed

Lines changed: 49 additions & 25 deletions

File tree

app/src/processing/app/syntax/PdeKeywords.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,24 @@ public void addColoring(String keyword, String coloring) {
5050
int num = coloring.charAt(coloring.length() - 1) - '1';
5151
// byte id = (byte) ((isKey ? Token.KEYWORD1 : Token.LITERAL1) + num);
5252
int id = 0;
53-
boolean paren = false;
5453
switch (coloring.charAt(0)) {
55-
case 'K': id = Token.KEYWORD1 + num; break;
56-
case 'L': id = Token.LITERAL1 + num; break;
57-
case 'F': id = Token.FUNCTION1 + num; paren = true; break;
54+
case 'K':
55+
id = Token.KEYWORD1 + num;
56+
keywordColoring.add(keyword, (byte) id, false);
57+
if (id == Token.KEYWORD6) {
58+
// these can be followed by parens
59+
keywordColoring.add(keyword, (byte) id, true);
60+
}
61+
break;
62+
case 'L':
63+
id = Token.LITERAL1 + num;
64+
keywordColoring.add(keyword, (byte) id, false);
65+
break;
66+
case 'F':
67+
id = Token.FUNCTION1 + num;
68+
keywordColoring.add(keyword, (byte) id, true);
69+
break;
5870
}
59-
keywordColoring.add(keyword, (byte) id, paren);
6071
}
6172

6273

app/src/processing/app/syntax/PdeTextAreaDefaults.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public PdeTextAreaDefaults(Mode mode) {
215215
styles[Token.KEYWORD3] = mode.getStyle("keyword3");
216216
styles[Token.KEYWORD4] = mode.getStyle("keyword4");
217217
styles[Token.KEYWORD5] = mode.getStyle("keyword5");
218+
styles[Token.KEYWORD6] = mode.getStyle("keyword6");
218219

219220
styles[Token.FUNCTION1] = mode.getStyle("function1");
220221
styles[Token.FUNCTION2] = mode.getStyle("function2");

app/src/processing/app/syntax/Token.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,35 @@ public class Token {
5656

5757
/** Datatypes (int, boolean, etc.) */
5858
public static final byte KEYWORD5 = 10;
59+
60+
/** Keywords which can be followed by parenthesis */
61+
public static final byte KEYWORD6 = 11;
5962

6063
/** Functions */
61-
public static final byte FUNCTION1 = 11;
64+
public static final byte FUNCTION1 = 12;
6265

6366
/** Methods (functions inside a class) */
64-
public static final byte FUNCTION2 = 12;
67+
public static final byte FUNCTION2 = 13;
6568

6669
/** Loop/function-like blocks (for, while, etc.) */
67-
public static final byte FUNCTION3 = 13;
70+
public static final byte FUNCTION3 = 14;
6871

6972
/** Built-in Processing functions (setup, draw, mouseDragged). */
70-
public static final byte FUNCTION4 = 14;
73+
public static final byte FUNCTION4 = 15;
7174

7275
/**
7376
* Operator token id. This can be used to mark an
7477
* operator. (eg, SQL mode marks +, -, etc with this
7578
* token type)
7679
*/
77-
public static final byte OPERATOR = 15;
80+
public static final byte OPERATOR = 16;
7881

7982
/**
8083
* Invalid token id. This can be used to mark invalid
8184
* or incomplete tokens, so the user can easily spot
8285
* syntax errors.
8386
*/
84-
public static final byte INVALID = 16;
87+
public static final byte INVALID = 17;
8588

8689
/** The total number of defined token ids. */
8790
public static final byte ID_COUNT = INVALID + 1;

build/shared/lib/defaults.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ editor.token.keyword2.style = #33997e,plain
248248
editor.token.keyword3.style = #669900,plain
249249
editor.token.keyword4.style = #d94a7a,plain
250250
editor.token.keyword5.style = #e2661a,plain
251+
editor.token.keyword6.style = #33997e,plain
251252

252253
editor.token.literal1.style = #7D4793,plain
253254
editor.token.literal2.style = #718a62,plain

java/keywords.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ WHITESPACE LITERAL2
180180
# Java keywords (void, import, , etc.)
181181

182182
abstract KEYWORD1
183-
assert KEYWORD1
184183
break KEYWORD1 break
185-
case KEYWORD1 case
186184
class KEYWORD1 class
187185
continue KEYWORD1 continue
188186
default KEYWORD1 default
@@ -202,19 +200,25 @@ package KEYWORD1
202200
private KEYWORD1 private
203201
protected KEYWORD1
204202
public KEYWORD1 public
205-
return KEYWORD1 return
206203
static KEYWORD1 static
207-
strictfp KEYWORD1
208-
super KEYWORD1 super
209-
this KEYWORD1 this
210-
throw KEYWORD1
204+
strictfp KEYWORD1
211205
throws KEYWORD1
212206
transient KEYWORD1
213207
true KEYWORD1 true
214208
void KEYWORD1 void
215209
volatile KEYWORD1
216210

217211

212+
# Java keywords which can be followed by a parenthesis
213+
214+
assert KEYWORD6
215+
case KEYWORD6 case
216+
return KEYWORD6 return
217+
super KEYWORD6 super
218+
this KEYWORD6 this
219+
throw KEYWORD6
220+
221+
218222
# Datatypes
219223

220224
Array KEYWORD5 Array

pdex/keywords.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ WHITESPACE LITERAL2
180180
# Java keywords (void, import, , etc.)
181181

182182
abstract KEYWORD1
183-
assert KEYWORD1
184183
break KEYWORD1 break
185-
case KEYWORD1 case
186184
class KEYWORD1 class
187185
continue KEYWORD1 continue
188186
default KEYWORD1 default
@@ -202,19 +200,25 @@ package KEYWORD1
202200
private KEYWORD1 private
203201
protected KEYWORD1
204202
public KEYWORD1 public
205-
return KEYWORD1 return
206203
static KEYWORD1 static
207-
strictfp KEYWORD1
208-
super KEYWORD1 super
209-
this KEYWORD1 this
210-
throw KEYWORD1
204+
strictfp KEYWORD1
211205
throws KEYWORD1
212206
transient KEYWORD1
213207
true KEYWORD1 true
214208
void KEYWORD1 void
215209
volatile KEYWORD1
216210

217211

212+
# Java keywords which can be followed by a parenthesis
213+
214+
assert KEYWORD6
215+
case KEYWORD6 case
216+
return KEYWORD6 return
217+
super KEYWORD6 super
218+
this KEYWORD6 this
219+
throw KEYWORD6
220+
221+
218222
# Datatypes
219223

220224
Array KEYWORD5 Array

0 commit comments

Comments
 (0)