KT-1545, KT-3161 KDoc lexer & parser
This commit is contained in:
committed by
Mikhael Bogdanov
parent
2ad1bfa743
commit
5ff1f746d4
@@ -46,6 +46,8 @@
|
||||
<target name="lexer">
|
||||
<echo message="${flex.base}"/>
|
||||
<flex flexfile="${home}/src/org/jetbrains/jet/lexer/Jet.flex"
|
||||
destdir="${home}//src/org/jetbrains/jet/lexer/"/>
|
||||
destdir="${home}/src/org/jetbrains/jet/lexer/"/>
|
||||
<flex flexfile="${home}/src/org/jetbrains/jet/kdoc/lexer/KDoc.flex"
|
||||
destdir="${home}/src/org/jetbrains/jet/kdoc/lexer/"/>
|
||||
</target>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.jetbrains.jet.kdoc.lexer;
|
||||
|
||||
import com.intellij.lexer.FlexLexer;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
|
||||
%%
|
||||
|
||||
%unicode
|
||||
%class _KDocLexer
|
||||
%implements FlexLexer
|
||||
|
||||
%{
|
||||
public _KDocLexer() {
|
||||
this((java.io.Reader)null);
|
||||
}
|
||||
|
||||
private final boolean isLastToken() {
|
||||
return zzMarkedPos == zzBuffer.length();
|
||||
}
|
||||
|
||||
private final Boolean yytextContainLineBreaks() {
|
||||
return CharArrayUtil.containLineBreaks(zzBuffer, zzStartRead, zzMarkedPos);
|
||||
}
|
||||
|
||||
private final void pushbackEnd() {
|
||||
if (isLastToken() && CharArrayUtil.regionMatches(zzBuffer, zzMarkedPos - 2, zzMarkedPos, "*/")) {
|
||||
yypushback(2);
|
||||
}
|
||||
}
|
||||
|
||||
private final void pushbackText() {
|
||||
int i = zzStartRead;
|
||||
while (zzBuffer.charAt(i) == '*') i++;
|
||||
yypushback(zzMarkedPos - i);
|
||||
}
|
||||
%}
|
||||
|
||||
%function advance
|
||||
%type IElementType
|
||||
%eof{
|
||||
return;
|
||||
%eof}
|
||||
|
||||
%state CONTENTS
|
||||
%state LINE_BEGINNING
|
||||
|
||||
WHITE_SPACE_CHAR =[\ \t\f\n\r]
|
||||
NOT_WHITE_SPACE_CHAR=[^\ \t\f\n\r]
|
||||
|
||||
%%
|
||||
|
||||
|
||||
<YYINITIAL> "/**" { yybegin(CONTENTS);
|
||||
return KDocTokens.START; }
|
||||
"*"+ "/" { if (isLastToken())
|
||||
return KDocTokens.END; }
|
||||
|
||||
// hack: make longest match
|
||||
<LINE_BEGINNING> "*"+ {NOT_WHITE_SPACE_CHAR}* { pushbackText();
|
||||
yybegin(CONTENTS);
|
||||
return KDocTokens.LEADING_ASTERISK; }
|
||||
|
||||
<CONTENTS, LINE_BEGINNING> {
|
||||
// todo: put markdown and @tags token patterns here
|
||||
|
||||
{NOT_WHITE_SPACE_CHAR}+ { pushbackEnd();
|
||||
return KDocTokens.TEXT; }
|
||||
{WHITE_SPACE_CHAR}+ { if (yytextContainLineBreaks())
|
||||
yybegin(LINE_BEGINNING);
|
||||
return TokenType.WHITE_SPACE; }
|
||||
}
|
||||
|
||||
. { return TokenType.BAD_CHARACTER; }
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.kdoc.lexer;
|
||||
|
||||
import com.intellij.lexer.FlexAdapter;
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
public class KDocLexer extends FlexAdapter {
|
||||
public KDocLexer() {
|
||||
super(new _KDocLexer((Reader) null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.kdoc.lexer;
|
||||
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
|
||||
public class KDocToken extends JetToken {
|
||||
public KDocToken(@NotNull @NonNls String debugName) {
|
||||
super(debugName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.kdoc.lexer;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.PsiBuilderFactory;
|
||||
import com.intellij.lang.PsiParser;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.ILazyParseableElementType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.kdoc.parser.KDocParser;
|
||||
import org.jetbrains.jet.kdoc.psi.impl.KDocImpl;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
public interface KDocTokens {
|
||||
ILazyParseableElementType KDOC = new ILazyParseableElementType("KDoc", JetLanguage.INSTANCE) {
|
||||
@Override
|
||||
public ASTNode parseContents(ASTNode chameleon) {
|
||||
PsiElement parentElement = chameleon.getTreeParent().getPsi();
|
||||
Project project = parentElement.getProject();
|
||||
PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new KDocLexer(), getLanguage(),
|
||||
chameleon.getText());
|
||||
PsiParser parser = new KDocParser();
|
||||
|
||||
return parser.parse(this, builder).getFirstChildNode();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ASTNode createNode(CharSequence text) {
|
||||
return new KDocImpl(text);
|
||||
}
|
||||
};
|
||||
|
||||
KDocToken START = new KDocToken("KDOC_START");
|
||||
KDocToken END = new KDocToken("KDOC_END");
|
||||
KDocToken LEADING_ASTERISK = new KDocToken("KDOC_LEADING_ASTERISK");
|
||||
|
||||
KDocToken TEXT = new KDocToken("KDOC_TEXT");
|
||||
}
|
||||
@@ -0,0 +1,539 @@
|
||||
/* The following code was generated by JFlex 1.4.3 on 23.05.13 19:26 */
|
||||
|
||||
package org.jetbrains.jet.kdoc.lexer;
|
||||
|
||||
import com.intellij.lexer.FlexLexer;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
|
||||
|
||||
/**
|
||||
* This class is a scanner generated by
|
||||
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
||||
* on 23.05.13 19:26 from the specification file
|
||||
* <tt>/Users/factitious/Documents/kotlin/compiler/frontend/src/org/jetbrains/jet/kdoc/lexer/KDoc.flex</tt>
|
||||
*/
|
||||
class _KDocLexer implements FlexLexer {
|
||||
/** initial size of the lookahead buffer */
|
||||
private static final int ZZ_BUFFERSIZE = 16384;
|
||||
|
||||
/** lexical states */
|
||||
public static final int LINE_BEGINNING = 4;
|
||||
public static final int CONTENTS = 2;
|
||||
public static final int YYINITIAL = 0;
|
||||
|
||||
/**
|
||||
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
|
||||
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
|
||||
* at the beginning of a line
|
||||
* l is of the form l = 2*k, k a non negative integer
|
||||
*/
|
||||
private static final int ZZ_LEXSTATE[] = {
|
||||
0, 0, 1, 1, 2, 2
|
||||
};
|
||||
|
||||
/**
|
||||
* Translates characters to character classes
|
||||
*/
|
||||
private static final String ZZ_CMAP_PACKED =
|
||||
"\11\0\1\1\1\4\1\0\2\1\22\0\1\1\11\0\1\3\4\0"+
|
||||
"\1\2\uffd0\0";
|
||||
|
||||
/**
|
||||
* Translates characters to character classes
|
||||
*/
|
||||
private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
|
||||
|
||||
/**
|
||||
* Translates DFA states to action switch labels.
|
||||
*/
|
||||
private static final int [] ZZ_ACTION = zzUnpackAction();
|
||||
|
||||
private static final String ZZ_ACTION_PACKED_0 =
|
||||
"\3\0\3\1\1\2\1\3\1\2\1\4\1\0\1\5"+
|
||||
"\1\0\1\5\1\4\1\5\1\6";
|
||||
|
||||
private static int [] zzUnpackAction() {
|
||||
int [] result = new int[17];
|
||||
int offset = 0;
|
||||
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackAction(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int count = packed.charAt(i++);
|
||||
int value = packed.charAt(i++);
|
||||
do result[j++] = value; while (--count > 0);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translates a state to a row index in the transition table
|
||||
*/
|
||||
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
|
||||
|
||||
private static final String ZZ_ROWMAP_PACKED_0 =
|
||||
"\0\0\0\5\0\12\0\17\0\24\0\31\0\36\0\43"+
|
||||
"\0\50\0\55\0\62\0\17\0\31\0\36\0\67\0\67"+
|
||||
"\0\17";
|
||||
|
||||
private static int [] zzUnpackRowMap() {
|
||||
int [] result = new int[17];
|
||||
int offset = 0;
|
||||
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackRowMap(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int high = packed.charAt(i++) << 16;
|
||||
result[j++] = high | packed.charAt(i++);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
/**
|
||||
* The transition table of the DFA
|
||||
*/
|
||||
private static final int [] ZZ_TRANS = zzUnpackTrans();
|
||||
|
||||
private static final String ZZ_TRANS_PACKED_0 =
|
||||
"\2\4\1\5\1\6\1\0\1\7\1\10\1\7\1\11"+
|
||||
"\1\10\1\7\1\10\1\7\1\12\1\10\10\0\1\13"+
|
||||
"\3\0\1\14\1\15\1\0\1\7\1\0\2\7\2\0"+
|
||||
"\1\10\2\0\1\10\1\7\1\0\1\16\1\11\1\0"+
|
||||
"\1\17\1\0\1\20\1\12\4\0\1\21\1\0\1\17"+
|
||||
"\1\0\2\17\1\0";
|
||||
|
||||
private static int [] zzUnpackTrans() {
|
||||
int [] result = new int[60];
|
||||
int offset = 0;
|
||||
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackTrans(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int count = packed.charAt(i++);
|
||||
int value = packed.charAt(i++);
|
||||
value--;
|
||||
do result[j++] = value; while (--count > 0);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
/* error codes */
|
||||
private static final int ZZ_UNKNOWN_ERROR = 0;
|
||||
private static final int ZZ_NO_MATCH = 1;
|
||||
private static final int ZZ_PUSHBACK_2BIG = 2;
|
||||
private static final char[] EMPTY_BUFFER = new char[0];
|
||||
private static final int YYEOF = -1;
|
||||
private static java.io.Reader zzReader = null; // Fake
|
||||
|
||||
/* error messages for the codes above */
|
||||
private static final String ZZ_ERROR_MSG[] = {
|
||||
"Unkown internal scanner error",
|
||||
"Error: could not match input",
|
||||
"Error: pushback value was too large"
|
||||
};
|
||||
|
||||
/**
|
||||
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
|
||||
*/
|
||||
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
|
||||
|
||||
private static final String ZZ_ATTRIBUTE_PACKED_0 =
|
||||
"\3\0\1\11\6\1\1\0\1\11\1\0\3\1\1\11";
|
||||
|
||||
private static int [] zzUnpackAttribute() {
|
||||
int [] result = new int[17];
|
||||
int offset = 0;
|
||||
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackAttribute(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int count = packed.charAt(i++);
|
||||
int value = packed.charAt(i++);
|
||||
do result[j++] = value; while (--count > 0);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
/** the current state of the DFA */
|
||||
private int zzState;
|
||||
|
||||
/** the current lexical state */
|
||||
private int zzLexicalState = YYINITIAL;
|
||||
|
||||
/** this buffer contains the current text to be matched and is
|
||||
the source of the yytext() string */
|
||||
private CharSequence zzBuffer = "";
|
||||
|
||||
/** this buffer may contains the current text array to be matched when it is cheap to acquire it */
|
||||
private char[] zzBufferArray;
|
||||
|
||||
/** the textposition at the last accepting state */
|
||||
private int zzMarkedPos;
|
||||
|
||||
/** the textposition at the last state to be included in yytext */
|
||||
private int zzPushbackPos;
|
||||
|
||||
/** the current text position in the buffer */
|
||||
private int zzCurrentPos;
|
||||
|
||||
/** startRead marks the beginning of the yytext() string in the buffer */
|
||||
private int zzStartRead;
|
||||
|
||||
/** endRead marks the last character in the buffer, that has been read
|
||||
from input */
|
||||
private int zzEndRead;
|
||||
|
||||
/**
|
||||
* zzAtBOL == true <=> the scanner is currently at the beginning of a line
|
||||
*/
|
||||
private boolean zzAtBOL = true;
|
||||
|
||||
/** zzAtEOF == true <=> the scanner is at the EOF */
|
||||
private boolean zzAtEOF;
|
||||
|
||||
/** denotes if the user-EOF-code has already been executed */
|
||||
private boolean zzEOFDone;
|
||||
|
||||
/* user code: */
|
||||
public _KDocLexer() {
|
||||
this((java.io.Reader)null);
|
||||
}
|
||||
|
||||
private final boolean isLastToken() {
|
||||
return zzMarkedPos == zzBuffer.length();
|
||||
}
|
||||
|
||||
private final Boolean yytextContainLineBreaks() {
|
||||
return CharArrayUtil.containLineBreaks(zzBuffer, zzStartRead, zzMarkedPos);
|
||||
}
|
||||
|
||||
private final void pushbackEnd() {
|
||||
if (isLastToken() && CharArrayUtil.regionMatches(zzBuffer, zzMarkedPos - 2, zzMarkedPos, "*/")) {
|
||||
yypushback(2);
|
||||
}
|
||||
}
|
||||
|
||||
private final void pushbackText() {
|
||||
int i = zzStartRead;
|
||||
while (zzBuffer.charAt(i) == '*') i++;
|
||||
yypushback(zzMarkedPos - i);
|
||||
}
|
||||
|
||||
|
||||
_KDocLexer(java.io.Reader in) {
|
||||
this.zzReader = in;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new scanner.
|
||||
* There is also java.io.Reader version of this constructor.
|
||||
*
|
||||
* @param in the java.io.Inputstream to read input from.
|
||||
*/
|
||||
_KDocLexer(java.io.InputStream in) {
|
||||
this(new java.io.InputStreamReader(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks the compressed character translation table.
|
||||
*
|
||||
* @param packed the packed character translation table
|
||||
* @return the unpacked character translation table
|
||||
*/
|
||||
private static char [] zzUnpackCMap(String packed) {
|
||||
char [] map = new char[0x10000];
|
||||
int i = 0; /* index in packed string */
|
||||
int j = 0; /* index in unpacked array */
|
||||
while (i < 24) {
|
||||
int count = packed.charAt(i++);
|
||||
char value = packed.charAt(i++);
|
||||
do map[j++] = value; while (--count > 0);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public final int getTokenStart(){
|
||||
return zzStartRead;
|
||||
}
|
||||
|
||||
public final int getTokenEnd(){
|
||||
return getTokenStart() + yylength();
|
||||
}
|
||||
|
||||
public void reset(CharSequence buffer, int start, int end,int initialState){
|
||||
zzBuffer = buffer;
|
||||
zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer);
|
||||
zzCurrentPos = zzMarkedPos = zzStartRead = start;
|
||||
zzPushbackPos = 0;
|
||||
zzAtEOF = false;
|
||||
zzAtBOL = true;
|
||||
zzEndRead = end;
|
||||
yybegin(initialState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refills the input buffer.
|
||||
*
|
||||
* @return <code>false</code>, iff there was new input.
|
||||
*
|
||||
* @exception java.io.IOException if any I/O-Error occurs
|
||||
*/
|
||||
private boolean zzRefill() throws java.io.IOException {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current lexical state.
|
||||
*/
|
||||
public final int yystate() {
|
||||
return zzLexicalState;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enters a new lexical state
|
||||
*
|
||||
* @param newState the new lexical state
|
||||
*/
|
||||
public final void yybegin(int newState) {
|
||||
zzLexicalState = newState;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the text matched by the current regular expression.
|
||||
*/
|
||||
public final CharSequence yytext() {
|
||||
return zzBuffer.subSequence(zzStartRead, zzMarkedPos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the character at position <tt>pos</tt> from the
|
||||
* matched text.
|
||||
*
|
||||
* It is equivalent to yytext().charAt(pos), but faster
|
||||
*
|
||||
* @param pos the position of the character to fetch.
|
||||
* A value from 0 to yylength()-1.
|
||||
*
|
||||
* @return the character at position pos
|
||||
*/
|
||||
public final char yycharat(int pos) {
|
||||
return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the length of the matched text region.
|
||||
*/
|
||||
public final int yylength() {
|
||||
return zzMarkedPos-zzStartRead;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reports an error that occured while scanning.
|
||||
*
|
||||
* In a wellformed scanner (no or only correct usage of
|
||||
* yypushback(int) and a match-all fallback rule) this method
|
||||
* will only be called with things that "Can't Possibly Happen".
|
||||
* If this method is called, something is seriously wrong
|
||||
* (e.g. a JFlex bug producing a faulty scanner etc.).
|
||||
*
|
||||
* Usual syntax/scanner level error handling should be done
|
||||
* in error fallback rules.
|
||||
*
|
||||
* @param errorCode the code of the errormessage to display
|
||||
*/
|
||||
private void zzScanError(int errorCode) {
|
||||
String message;
|
||||
try {
|
||||
message = ZZ_ERROR_MSG[errorCode];
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
|
||||
}
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pushes the specified amount of characters back into the input stream.
|
||||
*
|
||||
* They will be read again by then next call of the scanning method
|
||||
*
|
||||
* @param number the number of characters to be read again.
|
||||
* This number must not be greater than yylength()!
|
||||
*/
|
||||
public void yypushback(int number) {
|
||||
if ( number > yylength() )
|
||||
zzScanError(ZZ_PUSHBACK_2BIG);
|
||||
|
||||
zzMarkedPos -= number;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Contains user EOF-code, which will be executed exactly once,
|
||||
* when the end of file is reached
|
||||
*/
|
||||
private void zzDoEOF() {
|
||||
if (!zzEOFDone) {
|
||||
zzEOFDone = true;
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resumes scanning until the next regular expression is matched,
|
||||
* the end of input is encountered or an I/O-Error occurs.
|
||||
*
|
||||
* @return the next token
|
||||
* @exception java.io.IOException if any I/O-Error occurs
|
||||
*/
|
||||
public IElementType advance() throws java.io.IOException {
|
||||
int zzInput;
|
||||
int zzAction;
|
||||
|
||||
// cached fields:
|
||||
int zzCurrentPosL;
|
||||
int zzMarkedPosL;
|
||||
int zzEndReadL = zzEndRead;
|
||||
CharSequence zzBufferL = zzBuffer;
|
||||
char[] zzBufferArrayL = zzBufferArray;
|
||||
char [] zzCMapL = ZZ_CMAP;
|
||||
|
||||
int [] zzTransL = ZZ_TRANS;
|
||||
int [] zzRowMapL = ZZ_ROWMAP;
|
||||
int [] zzAttrL = ZZ_ATTRIBUTE;
|
||||
|
||||
while (true) {
|
||||
zzMarkedPosL = zzMarkedPos;
|
||||
|
||||
zzAction = -1;
|
||||
|
||||
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
|
||||
|
||||
zzState = ZZ_LEXSTATE[zzLexicalState];
|
||||
|
||||
|
||||
zzForAction: {
|
||||
while (true) {
|
||||
|
||||
if (zzCurrentPosL < zzEndReadL)
|
||||
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
|
||||
else if (zzAtEOF) {
|
||||
zzInput = YYEOF;
|
||||
break zzForAction;
|
||||
}
|
||||
else {
|
||||
// store back cached positions
|
||||
zzCurrentPos = zzCurrentPosL;
|
||||
zzMarkedPos = zzMarkedPosL;
|
||||
boolean eof = zzRefill();
|
||||
// get translated positions and possibly new buffer
|
||||
zzCurrentPosL = zzCurrentPos;
|
||||
zzMarkedPosL = zzMarkedPos;
|
||||
zzBufferL = zzBuffer;
|
||||
zzEndReadL = zzEndRead;
|
||||
if (eof) {
|
||||
zzInput = YYEOF;
|
||||
break zzForAction;
|
||||
}
|
||||
else {
|
||||
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
|
||||
if (zzNext == -1) break zzForAction;
|
||||
zzState = zzNext;
|
||||
|
||||
int zzAttributes = zzAttrL[zzState];
|
||||
if ( (zzAttributes & 1) == 1 ) {
|
||||
zzAction = zzState;
|
||||
zzMarkedPosL = zzCurrentPosL;
|
||||
if ( (zzAttributes & 8) == 8 ) break zzForAction;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// store back cached position
|
||||
zzMarkedPos = zzMarkedPosL;
|
||||
|
||||
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
|
||||
case 6:
|
||||
{ yybegin(CONTENTS);
|
||||
return KDocTokens.START;
|
||||
}
|
||||
case 7: break;
|
||||
case 5:
|
||||
{ if (isLastToken())
|
||||
return KDocTokens.END;
|
||||
}
|
||||
case 8: break;
|
||||
case 1:
|
||||
{ return TokenType.BAD_CHARACTER;
|
||||
}
|
||||
case 9: break;
|
||||
case 2:
|
||||
{ pushbackEnd();
|
||||
return KDocTokens.TEXT;
|
||||
}
|
||||
case 10: break;
|
||||
case 4:
|
||||
{ pushbackText();
|
||||
yybegin(CONTENTS);
|
||||
return KDocTokens.LEADING_ASTERISK;
|
||||
}
|
||||
case 11: break;
|
||||
case 3:
|
||||
{ if (yytextContainLineBreaks())
|
||||
yybegin(LINE_BEGINNING);
|
||||
return TokenType.WHITE_SPACE;
|
||||
}
|
||||
case 12: break;
|
||||
default:
|
||||
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
|
||||
zzAtEOF = true;
|
||||
zzDoEOF();
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
zzScanError(ZZ_NO_MATCH);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.kdoc.parser;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.PsiParser;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class KDocParser implements PsiParser {
|
||||
@Override
|
||||
@NotNull
|
||||
public ASTNode parse(IElementType root, PsiBuilder builder) {
|
||||
PsiBuilder.Marker rootMarker = builder.mark();
|
||||
|
||||
// todo: parse KDoc tags, markdown, etc...
|
||||
while (!builder.eof()) {
|
||||
builder.advanceLexer();
|
||||
}
|
||||
|
||||
rootMarker.done(root);
|
||||
return builder.getTreeBuilt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.kdoc.psi.api;
|
||||
|
||||
import com.intellij.psi.PsiComment;
|
||||
|
||||
// Don't implement JetElement (or it will be treated as statement)
|
||||
public interface KDoc extends PsiComment {
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.kdoc.psi.api;
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
|
||||
public interface KDocElement extends JetElement {
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.kdoc.psi.impl;
|
||||
|
||||
import com.intellij.extapi.psi.ASTWrapperPsiElement;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
public abstract class KDocElementImpl extends ASTWrapperPsiElement {
|
||||
@NotNull
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return JetLanguage.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getNode().getElementType().toString();
|
||||
}
|
||||
|
||||
public KDocElementImpl(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.kdoc.psi.impl;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.psi.impl.source.tree.LazyParseablePsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.kdoc.lexer.KDocTokens;
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDoc;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
public class KDocImpl extends LazyParseablePsiElement implements KDoc {
|
||||
public KDocImpl(CharSequence buffer) {
|
||||
super(KDocTokens.KDOC, buffer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return JetLanguage.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getNode().getElementType().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementType getTokenType() {
|
||||
return JetTokens.DOC_COMMENT;
|
||||
}
|
||||
}
|
||||
@@ -408,5 +408,4 @@ public class JetVisitor<R, D> extends PsiElementVisitor {
|
||||
public R visitEscapeStringTemplateEntry(JetEscapeStringTemplateEntry entry, D data) {
|
||||
return visitStringTemplateEntry(entry, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,14 +19,17 @@ package org.jetbrains.jet.lexer;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.jet.kdoc.lexer.KDocTokens;
|
||||
|
||||
public interface JetTokens {
|
||||
JetToken EOF = new JetToken("EOF");
|
||||
|
||||
JetToken BLOCK_COMMENT = new JetToken("BLOCK_COMMENT");
|
||||
JetToken DOC_COMMENT = new JetToken("DOC_COMMENT");
|
||||
JetToken EOL_COMMENT = new JetToken("EOL_COMMENT");
|
||||
JetToken SHEBANG_COMMENT = new JetToken("SHEBANG_COMMENT");
|
||||
JetToken BLOCK_COMMENT = new JetToken("BLOCK_COMMENT");
|
||||
JetToken EOL_COMMENT = new JetToken("EOL_COMMENT");
|
||||
JetToken SHEBANG_COMMENT = new JetToken("SHEBANG_COMMENT");
|
||||
|
||||
//JetToken DOC_COMMENT = new JetToken("DOC_COMMENT");
|
||||
IElementType DOC_COMMENT = KDocTokens.KDOC;
|
||||
|
||||
IElementType WHITE_SPACE = TokenType.WHITE_SPACE;
|
||||
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
/* The following code was generated by JFlex 1.4.3 on 3/12/13 8:22 PM */
|
||||
/* The following code was generated by JFlex 1.4.3 on 23.05.13 19:26 */
|
||||
|
||||
package org.jetbrains.jet.lexer;
|
||||
|
||||
import java.util.*;
|
||||
import com.intellij.lexer.*;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.lexer.FlexLexer;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.containers.Stack;
|
||||
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
|
||||
/**
|
||||
* This class is a scanner generated by
|
||||
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
||||
* on 3/12/13 8:22 PM from the specification file
|
||||
* <tt>C:/1/kotlin/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex</tt>
|
||||
* on 23.05.13 19:26 from the specification file
|
||||
* <tt>/Users/factitious/Documents/kotlin/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex</tt>
|
||||
*/
|
||||
class _JetLexer implements FlexLexer {
|
||||
/** initial size of the lookahead buffer */
|
||||
@@ -843,7 +840,7 @@ class _JetLexer implements FlexLexer {
|
||||
while (true) {
|
||||
|
||||
if (zzCurrentPosL < zzEndReadL)
|
||||
zzInput = zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++]:zzBufferL.charAt(zzCurrentPosL++);
|
||||
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
|
||||
else if (zzAtEOF) {
|
||||
zzInput = YYEOF;
|
||||
break zzForAction;
|
||||
@@ -863,7 +860,7 @@ class _JetLexer implements FlexLexer {
|
||||
break zzForAction;
|
||||
}
|
||||
else {
|
||||
zzInput = zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++]:zzBufferL.charAt(zzCurrentPosL++);
|
||||
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
|
||||
@@ -904,193 +901,202 @@ class _JetLexer implements FlexLexer {
|
||||
{ return JetTokens.NULL_KEYWORD ;
|
||||
}
|
||||
case 110: break;
|
||||
case 35:
|
||||
{ if (lBraceCount == 0) {
|
||||
popState();
|
||||
return JetTokens.LONG_TEMPLATE_ENTRY_END;
|
||||
}
|
||||
lBraceCount--;
|
||||
return JetTokens.RBRACE;
|
||||
}
|
||||
case 111: break;
|
||||
case 16:
|
||||
{ return JetTokens.LT ;
|
||||
}
|
||||
case 111: break;
|
||||
case 112: break;
|
||||
case 54:
|
||||
{ return JetTokens.DO_KEYWORD ;
|
||||
}
|
||||
case 112: break;
|
||||
case 113: break;
|
||||
case 20:
|
||||
{ return JetTokens.PLUS ;
|
||||
}
|
||||
case 113: break;
|
||||
case 114: break;
|
||||
case 59:
|
||||
{ return JetTokens.PLUSEQ ;
|
||||
}
|
||||
case 114: break;
|
||||
case 115: break;
|
||||
case 94:
|
||||
{ popState(); return JetTokens.THIS_KEYWORD;
|
||||
}
|
||||
case 115: break;
|
||||
case 116: break;
|
||||
case 28:
|
||||
{ return JetTokens.COMMA ;
|
||||
}
|
||||
case 116: break;
|
||||
case 117: break;
|
||||
case 17:
|
||||
{ return JetTokens.GT ;
|
||||
}
|
||||
case 117: break;
|
||||
case 118: break;
|
||||
case 4:
|
||||
{ return JetTokens.WHITE_SPACE;
|
||||
}
|
||||
case 118: break;
|
||||
case 119: break;
|
||||
case 26:
|
||||
{ return JetTokens.RPAR ;
|
||||
}
|
||||
case 119: break;
|
||||
case 120: break;
|
||||
case 57:
|
||||
{ return JetTokens.DOUBLE_ARROW;
|
||||
}
|
||||
case 120: break;
|
||||
case 121: break;
|
||||
case 88:
|
||||
{ return JetTokens.TRUE_KEYWORD ;
|
||||
}
|
||||
case 121: break;
|
||||
case 122: break;
|
||||
case 82:
|
||||
{ return JetTokens.IDE_TEMPLATE_START ;
|
||||
}
|
||||
case 122: break;
|
||||
case 123: break;
|
||||
case 37:
|
||||
{ return JetTokens.FIELD_IDENTIFIER;
|
||||
}
|
||||
case 123: break;
|
||||
case 124: break;
|
||||
case 61:
|
||||
{ return JetTokens.ANDAND ;
|
||||
}
|
||||
case 124: break;
|
||||
case 125: break;
|
||||
case 66:
|
||||
{ pushState(LONG_TEMPLATE_ENTRY); return JetTokens.LONG_TEMPLATE_ENTRY_START;
|
||||
}
|
||||
case 125: break;
|
||||
case 126: break;
|
||||
case 36:
|
||||
{ return JetTokens.FLOAT_LITERAL;
|
||||
}
|
||||
case 126: break;
|
||||
case 127: break;
|
||||
case 40:
|
||||
{ return JetTokens.EOL_COMMENT;
|
||||
}
|
||||
case 127: break;
|
||||
case 128: break;
|
||||
case 92:
|
||||
{ return JetTokens.WHEN_KEYWORD ;
|
||||
}
|
||||
case 128: break;
|
||||
case 129: break;
|
||||
case 75:
|
||||
{ pushState(RAW_STRING); return JetTokens.OPEN_QUOTE;
|
||||
}
|
||||
case 129: break;
|
||||
case 130: break;
|
||||
case 22:
|
||||
{ return JetTokens.COLON ;
|
||||
}
|
||||
case 130: break;
|
||||
case 131: break;
|
||||
case 55:
|
||||
{ return JetTokens.LTEQ ;
|
||||
}
|
||||
case 131: break;
|
||||
case 132: break;
|
||||
case 47:
|
||||
{ return JetTokens.ARROW ;
|
||||
}
|
||||
case 132: break;
|
||||
case 133: break;
|
||||
case 32:
|
||||
{ popState(); return JetTokens.IDENTIFIER;
|
||||
}
|
||||
case 133: break;
|
||||
case 134: break;
|
||||
case 23:
|
||||
{ return JetTokens.LBRACKET ;
|
||||
}
|
||||
case 134: break;
|
||||
case 135: break;
|
||||
case 70:
|
||||
{ yypushback(2); return JetTokens.INTEGER_LITERAL;
|
||||
}
|
||||
case 135: break;
|
||||
case 136: break;
|
||||
case 11:
|
||||
{ return JetTokens.CHARACTER_LITERAL;
|
||||
}
|
||||
case 136: break;
|
||||
case 137: break;
|
||||
case 80:
|
||||
{ return JetTokens.VAR_KEYWORD ;
|
||||
}
|
||||
case 137: break;
|
||||
case 138: break;
|
||||
case 56:
|
||||
{ return JetTokens.GTEQ ;
|
||||
}
|
||||
case 138: break;
|
||||
case 139: break;
|
||||
case 2:
|
||||
{ return JetTokens.INTEGER_LITERAL;
|
||||
}
|
||||
case 139: break;
|
||||
case 140: break;
|
||||
case 14:
|
||||
{ return JetTokens.RBRACE ;
|
||||
}
|
||||
case 140: break;
|
||||
case 141: break;
|
||||
case 98:
|
||||
{ return JetTokens.CLASS_KEYWORD ;
|
||||
}
|
||||
case 141: break;
|
||||
case 142: break;
|
||||
case 76:
|
||||
{ return JetTokens.TRY_KEYWORD ;
|
||||
}
|
||||
case 142: break;
|
||||
case 143: break;
|
||||
case 8:
|
||||
{ return JetTokens.EXCL ;
|
||||
}
|
||||
case 143: break;
|
||||
case 144: break;
|
||||
case 44:
|
||||
{ return JetTokens.EXCLEQ ;
|
||||
}
|
||||
case 144: break;
|
||||
case 145: break;
|
||||
case 48:
|
||||
{ return JetTokens.MINUSEQ ;
|
||||
}
|
||||
case 145: break;
|
||||
case 146: break;
|
||||
case 104:
|
||||
{ return JetTokens.PACKAGE_KEYWORD ;
|
||||
}
|
||||
case 146: break;
|
||||
case 147: break;
|
||||
case 95:
|
||||
{ return JetTokens.THROW_KEYWORD ;
|
||||
}
|
||||
case 147: break;
|
||||
case 148: break;
|
||||
case 97:
|
||||
{ return JetTokens.SUPER_KEYWORD ;
|
||||
}
|
||||
case 148: break;
|
||||
case 149: break;
|
||||
case 69:
|
||||
{ if (commentDepth > 0) {
|
||||
commentDepth--;
|
||||
}
|
||||
else {
|
||||
int state = yystate();
|
||||
popState();
|
||||
zzStartRead = commentStart;
|
||||
return commentStateToTokenType(state);
|
||||
}
|
||||
}
|
||||
case 150: break;
|
||||
case 100:
|
||||
{ return JetTokens.WHILE_KEYWORD ;
|
||||
}
|
||||
case 149: break;
|
||||
case 151: break;
|
||||
case 46:
|
||||
{ return JetTokens.MINUSMINUS;
|
||||
}
|
||||
case 150: break;
|
||||
case 152: break;
|
||||
case 105:
|
||||
{ return JetTokens.CONTINUE_KEYWORD ;
|
||||
}
|
||||
case 151: break;
|
||||
case 153: break;
|
||||
case 73:
|
||||
{ return JetTokens.NOT_IN;
|
||||
}
|
||||
case 152: break;
|
||||
case 154: break;
|
||||
case 39:
|
||||
{ return JetTokens.ATAT ;
|
||||
}
|
||||
case 153: break;
|
||||
case 71:
|
||||
{ pushState(DOC_COMMENT);
|
||||
commentDepth = 0;
|
||||
commentStart = getTokenStart();
|
||||
}
|
||||
case 154: break;
|
||||
case 155: break;
|
||||
case 6:
|
||||
{ return JetTokens.DIV ;
|
||||
}
|
||||
case 155: break;
|
||||
case 65:
|
||||
{ pushState(SHORT_TEMPLATE_ENTRY);
|
||||
yypushback(yylength() - 1);
|
||||
return JetTokens.SHORT_TEMPLATE_ENTRY_START;
|
||||
}
|
||||
case 156: break;
|
||||
case 83:
|
||||
{ return JetTokens.IDE_TEMPLATE_END ;
|
||||
@@ -1108,14 +1114,10 @@ class _JetLexer implements FlexLexer {
|
||||
{ return JetTokens.QUEST ;
|
||||
}
|
||||
case 160: break;
|
||||
case 43:
|
||||
{ if (zzCurrentPos == 0) {
|
||||
return JetTokens.SHEBANG_COMMENT;
|
||||
}
|
||||
else {
|
||||
yypushback(yylength() - 1);
|
||||
return JetTokens.HASH;
|
||||
}
|
||||
case 71:
|
||||
{ pushState(DOC_COMMENT);
|
||||
commentDepth = 0;
|
||||
commentStart = getTokenStart();
|
||||
}
|
||||
case 161: break;
|
||||
case 62:
|
||||
@@ -1142,83 +1144,77 @@ class _JetLexer implements FlexLexer {
|
||||
{ return TokenType.BAD_CHARACTER;
|
||||
}
|
||||
case 167: break;
|
||||
case 65:
|
||||
{ pushState(SHORT_TEMPLATE_ENTRY);
|
||||
yypushback(yylength() - 1);
|
||||
return JetTokens.SHORT_TEMPLATE_ENTRY_START;
|
||||
}
|
||||
case 168: break;
|
||||
case 72:
|
||||
{ return JetTokens.NOT_IS;
|
||||
}
|
||||
case 168: break;
|
||||
case 169: break;
|
||||
case 15:
|
||||
{ return JetTokens.MUL ;
|
||||
}
|
||||
case 169: break;
|
||||
case 170: break;
|
||||
case 24:
|
||||
{ return JetTokens.RBRACKET ;
|
||||
}
|
||||
case 170: break;
|
||||
case 171: break;
|
||||
case 60:
|
||||
{ return JetTokens.PLUSPLUS ;
|
||||
}
|
||||
case 171: break;
|
||||
case 87:
|
||||
{ return JetTokens.THIS_KEYWORD ;
|
||||
}
|
||||
case 172: break;
|
||||
case 9:
|
||||
{ return JetTokens.DOT ;
|
||||
}
|
||||
case 173: break;
|
||||
case 27:
|
||||
{ return JetTokens.SEMICOLON ;
|
||||
}
|
||||
case 174: break;
|
||||
case 51:
|
||||
{ return JetTokens.IF_KEYWORD ;
|
||||
}
|
||||
case 175: break;
|
||||
case 67:
|
||||
{ return JetTokens.ESCAPE_SEQUENCE;
|
||||
}
|
||||
case 176: break;
|
||||
case 41:
|
||||
{ pushState(BLOCK_COMMENT);
|
||||
commentDepth = 0;
|
||||
commentStart = getTokenStart();
|
||||
}
|
||||
case 173: break;
|
||||
case 87:
|
||||
{ return JetTokens.THIS_KEYWORD ;
|
||||
}
|
||||
case 174: break;
|
||||
case 9:
|
||||
{ return JetTokens.DOT ;
|
||||
}
|
||||
case 175: break;
|
||||
case 27:
|
||||
{ return JetTokens.SEMICOLON ;
|
||||
}
|
||||
case 176: break;
|
||||
case 51:
|
||||
{ return JetTokens.IF_KEYWORD ;
|
||||
}
|
||||
case 177: break;
|
||||
case 67:
|
||||
{ return JetTokens.ESCAPE_SEQUENCE;
|
||||
}
|
||||
case 178: break;
|
||||
case 31:
|
||||
{ popState(); return JetTokens.CLOSING_QUOTE;
|
||||
}
|
||||
case 178: break;
|
||||
case 179: break;
|
||||
case 18:
|
||||
{ return JetTokens.EQ ;
|
||||
}
|
||||
case 179: break;
|
||||
case 180: break;
|
||||
case 5:
|
||||
{ return JetTokens.AT ;
|
||||
}
|
||||
case 180: break;
|
||||
case 181: break;
|
||||
case 77:
|
||||
{ return JetTokens.AS_SAFE;
|
||||
}
|
||||
case 181: break;
|
||||
case 182: break;
|
||||
case 25:
|
||||
{ return JetTokens.LPAR ;
|
||||
}
|
||||
case 182: break;
|
||||
case 183: break;
|
||||
case 10:
|
||||
{ return JetTokens.MINUS ;
|
||||
}
|
||||
case 183: break;
|
||||
case 69:
|
||||
{ if (commentDepth > 0) {
|
||||
commentDepth--;
|
||||
}
|
||||
else {
|
||||
int state = yystate();
|
||||
popState();
|
||||
zzStartRead = commentStart;
|
||||
return commentStateToTokenType(state);
|
||||
}
|
||||
}
|
||||
case 184: break;
|
||||
case 101:
|
||||
{ return JetTokens.FALSE_KEYWORD ;
|
||||
@@ -1288,42 +1284,43 @@ class _JetLexer implements FlexLexer {
|
||||
{ return JetTokens.MULTEQ ;
|
||||
}
|
||||
case 201: break;
|
||||
case 43:
|
||||
{ if (zzCurrentPos == 0) {
|
||||
return JetTokens.SHEBANG_COMMENT;
|
||||
}
|
||||
else {
|
||||
yypushback(yylength() - 1);
|
||||
return JetTokens.HASH;
|
||||
}
|
||||
}
|
||||
case 202: break;
|
||||
case 13:
|
||||
{ return JetTokens.LBRACE ;
|
||||
}
|
||||
case 202: break;
|
||||
case 203: break;
|
||||
case 102:
|
||||
{ return JetTokens.OBJECT_KEYWORD ;
|
||||
}
|
||||
case 203: break;
|
||||
case 204: break;
|
||||
case 99:
|
||||
{ return JetTokens.BREAK_KEYWORD ;
|
||||
}
|
||||
case 204: break;
|
||||
case 205: break;
|
||||
case 85:
|
||||
{ return JetTokens.BLOCK_COMMENT;
|
||||
}
|
||||
case 205: break;
|
||||
case 206: break;
|
||||
case 96:
|
||||
{ return JetTokens.TRAIT_KEYWORD ;
|
||||
}
|
||||
case 206: break;
|
||||
case 207: break;
|
||||
case 64:
|
||||
{ return JetTokens.COLONCOLON;
|
||||
}
|
||||
case 207: break;
|
||||
case 208: break;
|
||||
case 33:
|
||||
{
|
||||
}
|
||||
case 208: break;
|
||||
case 35:
|
||||
{ if (lBraceCount == 0) {
|
||||
popState();
|
||||
return JetTokens.LONG_TEMPLATE_ENTRY_END;
|
||||
}
|
||||
lBraceCount--;
|
||||
return JetTokens.RBRACE;
|
||||
}
|
||||
case 209: break;
|
||||
case 7:
|
||||
{ return JetTokens.HASH ;
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
JetFile: DocCommentAtBeginningOfFile2.jet
|
||||
PsiComment(DOC_COMMENT)('/**\n/**')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -1,4 +0,0 @@
|
||||
JetFile: DocCommentAtBeginningOfFile3.jet
|
||||
PsiComment(DOC_COMMENT)('/**\n\nfooo')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -1,4 +0,0 @@
|
||||
JetFile: DocCommentAtBeginningOfFile4.jet
|
||||
PsiComment(DOC_COMMENT)('/**\n\n/**foo*/\n\nasdfas')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -25,7 +25,10 @@ JetFile: EOLsInComments.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiComment(DOC_COMMENT)('/** */')
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PREFIX_EXPRESSION
|
||||
OPERATION_REFERENCE
|
||||
PsiElement(PLUS)('+')
|
||||
@@ -72,7 +75,10 @@ JetFile: EOLsInComments.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiComment(DOC_COMMENT)('/**\n */')
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace(' ')
|
||||
OPERATION_REFERENCE
|
||||
PsiElement(PLUS)('+')
|
||||
|
||||
@@ -32,17 +32,30 @@ JetFile: NestedComments.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiComment(DOC_COMMENT)('/***/')
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiComment(DOC_COMMENT)('/** /***/*/')
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('/***/')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiComment(DOC_COMMENT)('/** /**\n\n*/***/')
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('/**')
|
||||
PsiWhiteSpace('\n\n')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('*')
|
||||
PsiElement(KDOC_TEXT)('/**')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
|
||||
@@ -1,5 +1,44 @@
|
||||
JetFile: MutableArray.jet
|
||||
PsiComment(DOC_COMMENT)('/**\n These declarations are "shallow" in the sense that they are not really compiled, only the type-checker uses them\n*/')
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_TEXT)('These')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('declarations')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('are')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('"shallow"')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('in')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('the')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('sense')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('that')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('they')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('are')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('not')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('really')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('compiled,')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('only')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('the')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('type-checker')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('uses')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('them')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n\n')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
JetFile: DocCommentAtBeginningOfFile1.jet
|
||||
PsiComment(DOC_COMMENT)('/**')
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -0,0 +1,7 @@
|
||||
JetFile: DocCommentAtBeginningOfFile2.jet
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(KDOC_TEXT)('/**')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -0,0 +1,7 @@
|
||||
JetFile: DocCommentAtBeginningOfFile3.jet
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n\n')
|
||||
PsiElement(KDOC_TEXT)('fooo')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -0,0 +1,9 @@
|
||||
JetFile: DocCommentAtBeginningOfFile4.jet
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n\n')
|
||||
PsiElement(KDOC_TEXT)('/**foo*/')
|
||||
PsiWhiteSpace('\n\n')
|
||||
PsiElement(KDOC_TEXT)('asdfas')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -0,0 +1,2 @@
|
||||
/**
|
||||
*/
|
||||
@@ -0,0 +1,7 @@
|
||||
JetFile: EndOnLeadingAsterisks.kt
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -0,0 +1 @@
|
||||
/**text*/
|
||||
@@ -0,0 +1,7 @@
|
||||
JetFile: EndRightAfterText.kt
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiElement(KDOC_TEXT)('text')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -0,0 +1,2 @@
|
||||
/**
|
||||
contents
|
||||
@@ -0,0 +1,7 @@
|
||||
JetFile: Incomplete.kt
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_TEXT)('contents')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -0,0 +1,7 @@
|
||||
/** line 0
|
||||
line 1 //
|
||||
** line 2 /*
|
||||
line 3 /**
|
||||
* line * 4
|
||||
*** line */ 5
|
||||
** line 6 */
|
||||
@@ -0,0 +1,52 @@
|
||||
JetFile: Simple.kt
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('line')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('0')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_TEXT)('line')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('1')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('//')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('**')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('line')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('2')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('/*')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_TEXT)('line')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('3')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('/**')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('*')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('line')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('*')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('4')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('***')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('line')
|
||||
PsiWhiteSpace(' */')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('5')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('**')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('line')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_TEXT)('6')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -0,0 +1,3 @@
|
||||
/**
|
||||
**test
|
||||
*/
|
||||
@@ -0,0 +1,10 @@
|
||||
JetFile: TextRightAfterLeadAsterisks.kt
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('**')
|
||||
PsiElement(KDOC_TEXT)('test')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
@@ -139,6 +139,7 @@ public class JetParsingTest extends ParsingTestCase {
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "script", true, factory));
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "recovery", true, factory));
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "propertyDelegate", true, factory));
|
||||
suite.addTest(JetTestCaseBuilder.suiteForDirectory(prefix, "kdoc", true, factory));
|
||||
return suite;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin;
|
||||
import com.intellij.lang.CodeDocumentationAwareCommenter;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDoc;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
public class JetCommenter implements CodeDocumentationAwareCommenter {
|
||||
@@ -79,6 +80,6 @@ public class JetCommenter implements CodeDocumentationAwareCommenter {
|
||||
|
||||
@Override
|
||||
public boolean isDocumentationComment(PsiComment element) {
|
||||
return element.getTokenType().equals(JetTokens.DOC_COMMENT);
|
||||
return element instanceof KDoc;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user