/*
 * Copyright 2015 Marek Kaput
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.rustidea.lexer;

import com.intellij.lexer.LayeredLexer;
import com.intellij.psi.tree.IElementType;
import org.rustidea.psi.types.RsTypes;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

import static org.rustidea.lexer.RsStringLiteralLexer.ESCAPE.*;

public class RsHighlightingLexer extends LayeredLexer {
    private static final Map<IElementType, EnumSet<RsStringLiteralLexer.ESCAPE>> STRING_LAYERS = new HashMap<IElementType, EnumSet<RsStringLiteralLexer.ESCAPE>>();

    static {
        STRING_LAYERS.put(RsTypes.CHAR_LIT, EnumSet.of(BYTE_ESCAPE, UNICODE_ESCAPE));
        STRING_LAYERS.put(RsTypes.BYTE_LIT, EnumSet.of(BYTE_ESCAPE));
        STRING_LAYERS.put(RsTypes.STRING_LIT, EnumSet.of(BYTE_ESCAPE, UNICODE_ESCAPE, EOL_ESCAPE));
        STRING_LAYERS.put(RsTypes.BYTE_STRING_LIT, EnumSet.of(BYTE_ESCAPE, EOL_ESCAPE));
    }

    public RsHighlightingLexer() {
        super(new RsLexer());
        for (Map.Entry<IElementType, EnumSet<RsStringLiteralLexer.ESCAPE>> layer : STRING_LAYERS.entrySet()) {
            IElementType literal = layer.getKey();
            EnumSet<RsStringLiteralLexer.ESCAPE> escapes = layer.getValue();
            registerLayer(new RsStringLiteralLexer(literal, escapes), literal);
        }
    }
}

@@ -616,16 +616,63 @@
 lexer;%0A%0A
+import com.google.common.collect.ImmutableMap;%0A
 import c
@@ -703,16 +703,16 @@
 dLexer;%0A
-
 import c
@@ -816,34 +816,8 @@
 et;%0A
-import java.util.HashMap;%0A
 impo
@@ -1056,20 +1056,41 @@
 RS =
- new HashMap
+%0A        new ImmutableMap.Builder
 %3CIEl
@@ -1143,45 +1143,21 @@
 %3E%3E()
-;%0A
 %0A    
-static %7B%0A        STRING_LAYERS
+        
 .put
@@ -1207,33 +1207,32 @@
 UNICODE_ESCAPE))
-;
 %0A        STRING_
@@ -1220,37 +1220,28 @@
 E))%0A        
-STRING_LAYERS
+    
 .put(RsTypes
@@ -1267,33 +1267,32 @@
 of(BYTE_ESCAPE))
-;
 %0A        STRING_
@@ -1280,37 +1280,28 @@
 E))%0A        
-STRING_LAYERS
+    
 .put(RsTypes
@@ -1361,25 +1361,24 @@
 EOL_ESCAPE))
-;
 %0A        STR
@@ -1374,29 +1374,20 @@
         
-STRING_LAYERS
+    
 .put(RsT
@@ -1448,15 +1448,30 @@
 PE))
-;
 %0A    
-%7D
+        .build();
 %0A%0A  

Use immutable map in RsHighlightingLexer