Fix highlighting of properties keyword.

The properties keyword was not being recognized as one that could
also be used as an identified.  Also put in instructions on how
to make sure that new keywords would follow the right strategy.

Bug: 86216

Change-Id: I5c6bf937e588734eb62fe380b86b5ba10c3719cd
Reviewed-on: https://fuchsia-review.googlesource.com/c/intellij-language-fidl/+/603449
Reviewed-by: Alex Zaslavsky <azaslavsky@google.com>
diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml
index 711f685..1a3d1df 100644
--- a/resources/META-INF/plugin.xml
+++ b/resources/META-INF/plugin.xml
@@ -20,7 +20,8 @@
       <ul>
         <li><b>0.18</b>
           <ul>
-            <li>AEnabled configurable style/formatting.</li>
+            <li>Enabled configurable style/formatting.</li>
+            <li>Fixed bug where syntax highlighting was applied incorrectly.<li>
           </ul>
         </li>
         <li><b>0.17</b>
diff --git a/src/fuchsia/developer/plugin/fidl/ContextAwareHighlighter.java b/src/fuchsia/developer/plugin/fidl/ContextAwareHighlighter.java
index d6c6c64..a6f364d 100644
--- a/src/fuchsia/developer/plugin/fidl/ContextAwareHighlighter.java
+++ b/src/fuchsia/developer/plugin/fidl/ContextAwareHighlighter.java
@@ -1,6 +1,5 @@
 package fuchsia.developer.plugin.fidl;
 
-import com.google.common.collect.ImmutableSet;
 import com.intellij.lang.ASTNode;
 import com.intellij.lang.annotation.Annotation;
 import com.intellij.lang.annotation.AnnotationHolder;
@@ -10,15 +9,12 @@
 import com.intellij.psi.tree.IElementType;
 import com.intellij.psi.tree.TokenSet;
 import fuchsia.developer.plugin.fidl.psi.Types;
-import java.util.Arrays;
-import java.util.Set;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 public class ContextAwareHighlighter implements Annotator {
 
   private static final TextAttributesKey KEYWORD_ATTRIBUTE;
-  private static final Set<String> TYPE_KEYWORDS;
   private static final TextAttributesKey IDENTIFIER_ATTRIBUTE;
   private static final SyntaxHighlighter SYNTAX_HIGHLIGHTER;
   private static final TokenSet INTEGRAL_TYPES =
@@ -39,60 +35,11 @@
     TextAttributesKey[] key = SYNTAX_HIGHLIGHTER.getKeywordHighlights();
     KEYWORD_ATTRIBUTE = key[0];
 
-    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
-    builder.addAll(
-        Arrays.asList(
-            "alias",
-            "type",
-            "array",
-            "vector",
-            "string",
-            "handle",
-            "process",
-            "thread",
-            "vmo",
-            "channel",
-            "clock",
-            "event",
-            "port",
-            "interrupt",
-            "log",
-            "socket",
-            "resource",
-            "eventpair",
-            "exception",
-            "job",
-            "vmar",
-            "fifo",
-            "guest",
-            "timer",
-            "request",
-            "iommu",
-            "pager",
-            "pcidevice",
-            "pmt",
-            "suspendtoken",
-            "vcpu",
-            "strict",
-            "bool",
-            "float32",
-            "float64",
-            "int8",
-            "int16",
-            "int32",
-            "int64",
-            "uint8",
-            "uint16",
-            "uint32",
-            "uint64"));
-    TYPE_KEYWORDS = builder.build();
-
     key = SYNTAX_HIGHLIGHTER.getTokenHighlights(Types.IDENTIFIER);
     IDENTIFIER_ATTRIBUTE = key[0];
   }
 
   private static class NumberAndRadix {
-
     String representation;
     int radix;
   }
@@ -266,7 +213,7 @@
     // think this identifier is a type, color it.
     if (parentType == Types.COMPOUND_IDENTIFIER) {
       if (grandParentType != null && grandParentType == Types.TYPE_CONSTRUCTOR) {
-        if (TYPE_KEYWORDS.contains(element.getText())) {
+        if (FidlLexer.ALL_KEYWORDS.contains(element.getText())) {
           Annotation annotation = holder.createInfoAnnotation(element, null);
           annotation.setTextAttributes(KEYWORD_ATTRIBUTE);
         }
diff --git a/src/fuchsia/developer/plugin/fidl/Fidl.bnf b/src/fuchsia/developer/plugin/fidl/Fidl.bnf
index 8005c25..1d96763 100644
--- a/src/fuchsia/developer/plugin/fidl/Fidl.bnf
+++ b/src/fuchsia/developer/plugin/fidl/Fidl.bnf
@@ -148,4 +148,4 @@
                      FLOAT64 | INT8 | INT16 | INT32 | INT64 | UINT8 | UINT16 | UINT32 | UINT64 |
                      TRUE | FALSE | PROTOCOL | COMPOSE | BITS | BYTES | EXCEPTION | STRICT |
                      IOMMU | PAGER | PCIDEVICE | PMT | SUSPENDTOKEN | VCPU | SERVICE | FLEXIBLE |
-                     CLOCK | RESOURCE_DEFINITION | ALIAS | TYPE
+                     CLOCK | RESOURCE_DEFINITION | ALIAS | TYPE | PROPERTIES
diff --git a/src/fuchsia/developer/plugin/fidl/FidlLexer.flex b/src/fuchsia/developer/plugin/fidl/FidlLexer.flex
index b24948e..8c7944e 100644
--- a/src/fuchsia/developer/plugin/fidl/FidlLexer.flex
+++ b/src/fuchsia/developer/plugin/fidl/FidlLexer.flex
@@ -4,6 +4,9 @@
 
 package fuchsia.developer.plugin.fidl;
 
+import java.util.Arrays;
+
+import com.google.common.collect.ImmutableSet;
 import com.intellij.lexer.FlexLexer;
 import com.intellij.psi.tree.IElementType;
 import com.intellij.psi.TokenType;
@@ -29,6 +32,12 @@
 
 WHITE_SPACE=\s+
 
+// NOTE: All keywords that require syntax highlighting and can also be used
+// as identifiers must go in:
+//   This list
+//   The ImmutableSet defined below.
+//   The identifier-token production in Fidl.bnf
+
 // Reserved words
 ALIAS=alias
 ARRAY=array
@@ -99,6 +108,81 @@
 UINT32=uint32
 UINT64=uint64
 
+%{
+  public static ImmutableSet<String> ALL_KEYWORDS;
+  static {
+    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
+    builder.addAll(
+        Arrays.asList(
+            "alias",
+            "array",
+            "as",
+            "bits",
+            "bytes",
+            "compose",
+            "const",
+            "enum",
+            "error",
+            "flexible",
+            "handle",
+            "interface",
+            "library",
+            "protocol",
+            "properties",
+            "request",
+            "reserved",
+            "resource",
+            "resource_definition",
+            "service",
+            "string",
+            "strict",
+            "struct",
+            "table",
+            "type",
+            "union",
+            "using",
+            "vector",
+            "xunion",
+            "channel",
+            "clock",
+            "event",
+            "eventpair",
+            "exception",
+            "fifo",
+            "guest",
+            "interrupt",
+            "iommu",
+            "job",
+            "log",
+            "pager",
+            "pcidevice",
+            "pmt",
+            "port",
+            "process",
+            "resource",
+            "socket",
+            "suspendtoken",
+            "thread",
+            "timer",
+            "vcpu",
+            "vmar",
+            "vmo",
+            "bool",
+            "float32",
+            "float64",
+            "int8",
+            "int16",
+            "int32",
+            "int64",
+            "uint8",
+            "uint16",
+            "uint32",
+            "uint64"));
+    ALL_KEYWORDS = builder.build();
+  }
+%}
+
+
 // Operators, etc.
 AT="@"
 OBRACE="{"
diff --git a/test/good.test.fidl b/test/good.test.fidl
index 5526880..58412d5 100644
--- a/test/good.test.fidl
+++ b/test/good.test.fidl
@@ -93,9 +93,17 @@
         // hi
         f1 Bar; //hi
         f2 uint8;
+        // Should not be any highlighting here:
+        properties uint8;
     });
 };
 
+resource_definition SomeResource : uint32 {
+    properties {
+        f1 uint8;
+    };
+};
+
 service Qux {
     foo Foo:client_end;
     bar Foo:<client_end>;