Search in sources :

Example 1 with LayeredLexer

use of com.intellij.lexer.LayeredLexer in project intellij-plugins by JetBrains.

the class CfmlIndexPatternBuilder method getIndexingLexer.

public Lexer getIndexingLexer(@NotNull final PsiFile file) {
    if (file instanceof CfmlFile) {
        Project project = file.getProject();
        SqlLanguageDialect dialect = SqlDialectMappings.getMapping(project, file.getVirtualFile());
        Lexer sqlLexer = LanguageParserDefinitions.INSTANCE.forLanguage(dialect).createLexer(project);
        LayeredLexer cfmlLayeredLexer = new LayeredLexer(new CfmlLexer(true, project));
        cfmlLayeredLexer.registerLayer(new HtmlHighlightingLexer(), CfmlElementTypes.TEMPLATE_TEXT);
        cfmlLayeredLexer.registerLayer(sqlLexer, CfmlElementTypes.SQL);
        return cfmlLayeredLexer;
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) Lexer(com.intellij.lexer.Lexer) HtmlHighlightingLexer(com.intellij.lexer.HtmlHighlightingLexer) CfmlLexer(com.intellij.coldFusion.model.lexer.CfmlLexer) LayeredLexer(com.intellij.lexer.LayeredLexer) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) HtmlHighlightingLexer(com.intellij.lexer.HtmlHighlightingLexer) LayeredLexer(com.intellij.lexer.LayeredLexer) CfmlLexer(com.intellij.coldFusion.model.lexer.CfmlLexer) SqlLanguageDialect(com.intellij.sql.dialects.SqlLanguageDialect)

Example 2 with LayeredLexer

use of com.intellij.lexer.LayeredLexer in project intellij-community by JetBrains.

the class CustomFileHighlighter method getHighlightingLexer.

@Override
@NotNull
public Lexer getHighlightingLexer() {
    Lexer customFileTypeLexer = new CustomFileTypeLexer(myTable, true);
    if (myTable.isHasStringEscapes()) {
        customFileTypeLexer = new LayeredLexer(customFileTypeLexer);
        ((LayeredLexer) customFileTypeLexer).registerSelfStoppingLayer(new StringLiteralLexer('\"', CustomHighlighterTokenType.STRING, true, "x"), new IElementType[] { CustomHighlighterTokenType.STRING }, IElementType.EMPTY_ARRAY);
        ((LayeredLexer) customFileTypeLexer).registerSelfStoppingLayer(new StringLiteralLexer('\'', CustomHighlighterTokenType.STRING, true, "x"), new IElementType[] { CustomHighlighterTokenType.SINGLE_QUOTED_STRING }, IElementType.EMPTY_ARRAY);
    }
    return customFileTypeLexer;
}
Also used : Lexer(com.intellij.lexer.Lexer) StringLiteralLexer(com.intellij.lexer.StringLiteralLexer) LayeredLexer(com.intellij.lexer.LayeredLexer) StringLiteralLexer(com.intellij.lexer.StringLiteralLexer) LayeredLexer(com.intellij.lexer.LayeredLexer) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LayeredLexer

use of com.intellij.lexer.LayeredLexer in project intellij-community by JetBrains.

the class PythonEditorHighlighter method setEditor.

@Override
public void setEditor(@NotNull HighlighterClient editor) {
    Lexer l = getLexer();
    if (l instanceof LayeredLexer) {
        editor.getDocument().putUserData(KEY, editor.getDocument().getText().indexOf(PyNames.UNICODE_LITERALS) == -1);
    }
    super.setEditor(editor);
}
Also used : Lexer(com.intellij.lexer.Lexer) LayeredLexer(com.intellij.lexer.LayeredLexer) LayeredLexer(com.intellij.lexer.LayeredLexer)

Example 4 with LayeredLexer

use of com.intellij.lexer.LayeredLexer in project intellij-community by JetBrains.

the class PythonEditorHighlighter method documentChanged.

@Override
public void documentChanged(DocumentEvent e) {
    synchronized (this) {
        final Document document = e.getDocument();
        Lexer l = getLexer();
        // we should update the whole document
        if (l instanceof LayeredLexer) {
            Lexer delegate = ((LayeredLexer) l).getDelegate();
            int offset = e.getOffset();
            int lineNumber = document.getLineNumber(offset);
            TextRange tr = new TextRange(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber));
            document.putUserData(KEY, document.getText(tr).indexOf(PyNames.UNICODE_LITERALS) == -1);
            Boolean hasUnicodeImport = document.getUserData(KEY);
            if (delegate instanceof PythonHighlightingLexer && (((PythonHighlightingLexer) delegate).getImportOffset() > e.getOffset() || hasUnicodeImport != hadUnicodeImport)) {
                ((PythonHighlightingLexer) delegate).clearState(e.getDocument().getTextLength());
                setText(document.getCharsSequence());
            } else
                super.documentChanged(e);
        } else
            super.documentChanged(e);
    }
}
Also used : Lexer(com.intellij.lexer.Lexer) LayeredLexer(com.intellij.lexer.LayeredLexer) LayeredLexer(com.intellij.lexer.LayeredLexer) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document)

Example 5 with LayeredLexer

use of com.intellij.lexer.LayeredLexer in project intellij-community by JetBrains.

the class PyHighlighter method getHighlightingLexer.

@NotNull
public Lexer getHighlightingLexer() {
    LayeredLexer ret = new LayeredLexer(createHighlightingLexer(myLanguageLevel));
    ret.registerLayer(new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_STRING), PyTokenTypes.SINGLE_QUOTED_STRING);
    ret.registerLayer(new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), PyTokenTypes.SINGLE_QUOTED_UNICODE);
    ret.registerLayer(new PyStringLiteralLexer(PyTokenTypes.TRIPLE_QUOTED_STRING), PyTokenTypes.TRIPLE_QUOTED_STRING);
    ret.registerLayer(new PyStringLiteralLexer(PyTokenTypes.TRIPLE_QUOTED_UNICODE), PyTokenTypes.TRIPLE_QUOTED_UNICODE);
    return ret;
}
Also used : PyStringLiteralLexer(com.jetbrains.python.lexer.PyStringLiteralLexer) LayeredLexer(com.intellij.lexer.LayeredLexer) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LayeredLexer (com.intellij.lexer.LayeredLexer)5 Lexer (com.intellij.lexer.Lexer)4 NotNull (org.jetbrains.annotations.NotNull)2 CfmlFile (com.intellij.coldFusion.model.files.CfmlFile)1 CfmlLexer (com.intellij.coldFusion.model.lexer.CfmlLexer)1 HtmlHighlightingLexer (com.intellij.lexer.HtmlHighlightingLexer)1 StringLiteralLexer (com.intellij.lexer.StringLiteralLexer)1 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 SqlLanguageDialect (com.intellij.sql.dialects.SqlLanguageDialect)1 PyStringLiteralLexer (com.jetbrains.python.lexer.PyStringLiteralLexer)1