com.intellij.lexer.LayeredLexer Java Examples

The following examples show how to use com.intellij.lexer.LayeredLexer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LatteIndexPatternBuilder.java    From intellij-latte with MIT License 6 votes vote down vote up
@Nullable
@Override
public Lexer getIndexingLexer(@NotNull PsiFile file) {
	if (!(file instanceof LatteFile)) {
		return null;
	}
	VirtualFile virtualFile = file.getVirtualFile();
	if (virtualFile == null) {
		virtualFile = file.getViewProvider().getVirtualFile();
	}

	try {
		LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE);
		EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file.getProject(), virtualFile);
		return new LexerEditorHighlighterLexer(highlighter, false);
	} finally {
		LayeredLexer.ourDisableLayersFlag.set(Boolean.FALSE);
	}
}
 
Example #2
Source File: SyntaxHighlighterOverEditorHighlighter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public SyntaxHighlighterOverEditorHighlighter(SyntaxHighlighter _highlighter, VirtualFile file, Project project) {
  if (file.getFileType() == PlainTextFileType.INSTANCE) { // optimization for large files, PlainTextSyntaxHighlighterFactory is slow
    highlighter = new PlainSyntaxHighlighter();
    lexer = highlighter.getHighlightingLexer();
  } else {
    highlighter = _highlighter;
    LayeredLexer.ourDisableLayersFlag.set(Boolean.TRUE);
    EditorHighlighter editorHighlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file);

    try {
      if (editorHighlighter instanceof LayeredLexerEditorHighlighter) {
        lexer = new LexerEditorHighlighterLexer(editorHighlighter, false);
      }
      else {
        lexer = highlighter.getHighlightingLexer();
      }
    }
    finally {
      LayeredLexer.ourDisableLayersFlag.set(null);
    }
  }
}
 
Example #3
Source File: LatteLexer.java    From intellij-latte with MIT License 5 votes vote down vote up
public LatteLexer() {
	super(new LatteTopLexerAdapter());
	LayeredLexer macroLexer = new LayeredLexer(new LatteMacroLexerAdapter());
	macroLexer.registerLayer(createContentLexerAdapter(), LatteTypes.T_MACRO_CONTENT);

	registerLayer(macroLexer, LatteTypes.T_MACRO_CLASSIC);
	registerLayer(createContentLexerAdapter(), LatteTypes.T_MACRO_CONTENT);
}
 
Example #4
Source File: CppHighlighter.java    From CppTools with Apache License 2.0 5 votes vote down vote up
@NotNull
public Lexer getHighlightingLexer() {
  return new LayeredLexer( new FlexAdapter(new _CppLexer(true, false, true, true, true)) ) { // TODO: c/c++ dialects
    {
      registerSelfStoppingLayer(new StringLiteralLexer('\"', CppTokenTypes.STRING_LITERAL),
                            new IElementType[]{CppTokenTypes.STRING_LITERAL}, IElementType.EMPTY_ARRAY);

      registerSelfStoppingLayer(new StringLiteralLexer('\'', CppTokenTypes.SINGLE_QUOTE_STRING_LITERAL),
                            new IElementType[]{CppTokenTypes.SINGLE_QUOTE_STRING_LITERAL},
                            IElementType.EMPTY_ARRAY);
    }
  };
}
 
Example #5
Source File: LatteLexer.java    From intellij-latte with MIT License 4 votes vote down vote up
private LayeredLexer createContentLexerAdapter() {
	LayeredLexer contentMacroLexer = new LayeredLexer(new LatteMacroContentLexerAdapter());
	contentMacroLexer.registerLayer(new LattePhpLexerAdapter(), LatteTypes.T_PHP_CONTENT);
	return contentMacroLexer;
}