001/* 002 * Copyright 2010-2013 JetBrains s.r.o. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.jetbrains.jet.kdoc.lexer; 018 019import com.intellij.lang.ASTNode; 020import com.intellij.lang.PsiBuilder; 021import com.intellij.lang.PsiBuilderFactory; 022import com.intellij.lang.PsiParser; 023import com.intellij.openapi.project.Project; 024import com.intellij.psi.PsiElement; 025import com.intellij.psi.tree.ILazyParseableElementType; 026import com.intellij.psi.tree.TokenSet; 027import org.jetbrains.annotations.Nullable; 028import org.jetbrains.jet.kdoc.parser.KDocParser; 029import org.jetbrains.jet.kdoc.psi.impl.KDocImpl; 030import org.jetbrains.jet.plugin.JetLanguage; 031 032public interface KDocTokens { 033 ILazyParseableElementType KDOC = new ILazyParseableElementType("KDoc", JetLanguage.INSTANCE) { 034 @Override 035 public ASTNode parseContents(ASTNode chameleon) { 036 PsiElement parentElement = chameleon.getTreeParent().getPsi(); 037 Project project = parentElement.getProject(); 038 PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new KDocLexer(), getLanguage(), 039 chameleon.getText()); 040 PsiParser parser = new KDocParser(); 041 042 return parser.parse(this, builder).getFirstChildNode(); 043 } 044 045 @Nullable 046 @Override 047 public ASTNode createNode(CharSequence text) { 048 return new KDocImpl(text); 049 } 050 }; 051 052 KDocToken START = new KDocToken("KDOC_START"); 053 KDocToken END = new KDocToken("KDOC_END"); 054 KDocToken LEADING_ASTERISK = new KDocToken("KDOC_LEADING_ASTERISK"); 055 056 KDocToken TEXT = new KDocToken("KDOC_TEXT"); 057 KDocToken TAG_NAME = new KDocToken("KDOC_TAG_NAME"); 058 KDocToken WIKI_LINK_OPEN = new KDocToken("KDOC_WIKI_LINK_OPEN"); 059 KDocToken WIKI_LINK_CLOSE = new KDocToken("KDOC_WIKI_LINK_CLOSE"); 060 061 KDocToken MARKDOWN_ESCAPED_CHAR = new KDocToken("KDOC_MARKDOWN_ESCAPED_CHAR"); 062 063 TokenSet KDOC_HIGHLIGHT_TOKENS = TokenSet.create(START, END, LEADING_ASTERISK, TEXT, WIKI_LINK_OPEN, WIKI_LINK_CLOSE, MARKDOWN_ESCAPED_CHAR); 064 TokenSet CONTENT_TOKENS = TokenSet.create(TEXT, TAG_NAME, WIKI_LINK_OPEN, WIKI_LINK_CLOSE, MARKDOWN_ESCAPED_CHAR); 065}