2 * Copyright 2006 Sascha Weinreuter
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.intellij
.lang
.regexp
;
18 import com
.intellij
.lang
.BracePair
;
19 import com
.intellij
.lang
.Language
;
20 import com
.intellij
.lang
.LanguageAnnotators
;
21 import com
.intellij
.lang
.LanguageBraceMatching
;
22 import com
.intellij
.lang
.LanguageDocumentation
;
23 import com
.intellij
.lang
.LanguageParserDefinitions
;
24 import com
.intellij
.lang
.LanguageSurrounders
;
25 import com
.intellij
.lang
.PairedBraceMatcher
;
26 import com
.intellij
.lang
.documentation
.QuickDocumentationProvider
;
27 import com
.intellij
.openapi
.fileTypes
.SingleLazyInstanceSyntaxHighlighterFactory
;
28 import com
.intellij
.openapi
.fileTypes
.SyntaxHighlighter
;
29 import com
.intellij
.openapi
.fileTypes
.SyntaxHighlighterFactory
;
30 import com
.intellij
.psi
.PsiElement
;
31 import com
.intellij
.psi
.PsiFile
;
32 import com
.intellij
.psi
.tree
.IElementType
;
33 import org
.intellij
.lang
.regexp
.psi
.RegExpGroup
;
34 import org
.intellij
.lang
.regexp
.psi
.impl
.RegExpElementImpl
;
35 import org
.intellij
.lang
.regexp
.surroundWith
.SimpleSurroundDescriptor
;
36 import org
.intellij
.lang
.regexp
.validation
.RegExpAnnotator
;
37 import org
.jetbrains
.annotations
.NotNull
;
38 import org
.jetbrains
.annotations
.Nullable
;
40 public class RegExpLanguage
extends Language
{
41 public static final RegExpLanguage INSTANCE
= new RegExpLanguage();
43 protected RegExpLanguage() {
45 final RegExpParserDefinition parserDefinition
= new RegExpParserDefinition();
47 LanguageAnnotators
.INSTANCE
.addExpicitExtension(this, new RegExpAnnotator());
48 LanguageParserDefinitions
.INSTANCE
.addExpicitExtension(this, parserDefinition
);
49 LanguageBraceMatching
.INSTANCE
.addExpicitExtension(this, createPairedBraceMatcher());
50 LanguageSurrounders
.INSTANCE
.addExpicitExtension(this, new SimpleSurroundDescriptor());
51 SyntaxHighlighterFactory
.LANGUAGE_FACTORY
.addExpicitExtension(this, new SingleLazyInstanceSyntaxHighlighterFactory() {
53 protected SyntaxHighlighter
createHighlighter() {
54 return new RegExpHighlighter(null, parserDefinition
);
58 LanguageDocumentation
.INSTANCE
.addExpicitExtension(this, new QuickDocumentationProvider() {
60 public String
getQuickNavigateInfo(PsiElement element
) {
61 if (element
instanceof RegExpGroup
) {
62 return "Capturing Group: " + ((RegExpElementImpl
)element
).getUnescapedText();
71 private static PairedBraceMatcher
createPairedBraceMatcher() {
72 return new PairedBraceMatcher() {
73 public BracePair
[] getPairs() {
74 return new BracePair
[]{
75 new BracePair(RegExpTT
.GROUP_BEGIN
, RegExpTT
.GROUP_END
, true),
76 new BracePair(RegExpTT
.SET_OPTIONS
, RegExpTT
.GROUP_END
, true),
77 new BracePair(RegExpTT
.NON_CAPT_GROUP
, RegExpTT
.GROUP_END
, true),
78 new BracePair(RegExpTT
.POS_LOOKAHEAD
, RegExpTT
.GROUP_END
, true),
79 new BracePair(RegExpTT
.NEG_LOOKAHEAD
, RegExpTT
.GROUP_END
, true),
80 new BracePair(RegExpTT
.POS_LOOKBEHIND
, RegExpTT
.GROUP_END
, true),
81 new BracePair(RegExpTT
.NEG_LOOKBEHIND
, RegExpTT
.GROUP_END
, true),
82 new BracePair(RegExpTT
.CLASS_BEGIN
, RegExpTT
.CLASS_END
, false),
83 new BracePair(RegExpTT
.LBRACE
, RegExpTT
.RBRACE
, false),
84 new BracePair(RegExpTT
.QUOTE_BEGIN
, RegExpTT
.QUOTE_END
, false),
88 public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType
, @Nullable IElementType contextType
) {
92 public int getCodeConstructStart(PsiFile file
, int openingBraceOffset
) {
93 return openingBraceOffset
;