Skip to content

Commit

Permalink
Added brace matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Gusakov committed Sep 22, 2014
1 parent 7b62d11 commit e8a9929
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<fileTypeFactory implementation="com.zephir.ZephirFileTypeFactory"/>
<!--<lang.parserDefinition language="Zephir" implementationClass="com.zephir.ZephirParserDefinition"/>-->
<lang.commenter language="Zephir" implementationClass="com.zephir.lang.ZephirCommenter"/>
<lang.braceMatcher language="Zephir" implementationClass="com.zephir.lang.ZephirBraceMatcher"/>
<lang.syntaxHighlighterFactory key="Zephir" implementationClass="com.zephir.highlight.ZephirSyntaxHighlighterFactory"/>
<colorSettingsPage implementation="com.zephir.highlight.ZephirColorSettingsPage"/>

Expand Down
35 changes: 35 additions & 0 deletions src/com/zephir/lang/ZephirBraceMatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.zephir.lang;

import com.intellij.lang.BracePair;
import com.intellij.lang.PairedBraceMatcher;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IElementType;
import com.zephir.psi.ZephirTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author Nikita Gusakov
*/
public class ZephirBraceMatcher implements PairedBraceMatcher {
private static final BracePair[] BRACE_PAIRS = {
new BracePair(ZephirTypes.BRACKET_OPEN, ZephirTypes.BRACKET_CLOSE, true),
new BracePair(ZephirTypes.SBRACKET_OPEN, ZephirTypes.SBRACKET_CLOSE, false),
new BracePair(ZephirTypes.PARENTHESES_OPEN, ZephirTypes.PARENTHESES_CLOSE, false)
};

@Override
public BracePair[] getPairs() {
return BRACE_PAIRS;
}

@Override
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType braceType, @Nullable IElementType contextType) {
return true;
}

@Override
public int getCodeConstructStart(PsiFile file, int openingBraceOffset) {
return openingBraceOffset;
}
}

0 comments on commit e8a9929

Please sign in to comment.