IJSDK-203 Confusing grammar and no info on comments and whitespaces

This commit is contained in:
cheptsov 2016-11-03 13:16:35 +01:00
parent 780bfb2863
commit e3943a8d71
7 changed files with 221 additions and 488 deletions

Binary file not shown.

View File

@ -1,251 +0,0 @@
/** initial size of the lookahead buffer */
--- private static final int ZZ_BUFFERSIZE = ...;
/** lexical states */
--- lexical states, charmap
/* 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"
};
--- isFinal list
/** 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;
--- user class code
--- constructor declaration
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
*/
--- zzScanError declaration
String message;
try {
message = ZZ_ERROR_MSG[errorCode];
}
catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
}
--- throws clause
}
/**
* 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()!
*/
--- yypushback decl (contains zzScanError exception)
if ( number > yylength() )
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
--- zzDoEOF
/**
* 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
*/
--- yylex declaration
int zzInput;
int zzAction;
// cached fields:
int zzCurrentPosL;
int zzMarkedPosL;
int zzEndReadL = zzEndRead;
CharSequence zzBufferL = zzBuffer;
char[] zzBufferArrayL = zzBufferArray;
char [] zzCMapL = ZZ_CMAP;
--- local declarations
while (true) {
zzMarkedPosL = zzMarkedPos;
--- start admin (line, char, col count)
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
--- start admin (lexstate etc)
zzForAction: {
while (true) {
--- next input, line, col, char count, next transition, isFinal action
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
--- line count update
}
}
}
// store back cached position
zzMarkedPos = zzMarkedPosL;
--- char count update
--- actions
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
--- eofvalue
}
else {
--- no match
}
}
}
}
--- main
}

View File

@ -15,13 +15,13 @@ import com.intellij.psi.TokenType;
%eof{ return; %eof{ return;
%eof} %eof}
CRLF= \n|\r|\r\n CRLF=\n
WHITE_SPACE=[\ \t\f] WHITE_SPACE=[\ \t\f]
FIRST_VALUE_CHARACTER=[^ \n\r\f\\] | "\\"{CRLF} | "\\". FIRST_VALUE_CHARACTER=[^ \n\f\\] | "\\"{CRLF} | "\\".
VALUE_CHARACTER=[^\n\r\f\\] | "\\"{CRLF} | "\\". VALUE_CHARACTER=[^\n\f\\] | "\\"{CRLF} | "\\".
END_OF_LINE_COMMENT=("#"|"!")[^\r\n]* END_OF_LINE_COMMENT=("#"|"!")[^\n]*
SEPARATOR=[:=] SEPARATOR=[:=]
KEY_CHARACTER=[^:=\ \n\r\t\f\\] | "\\ " KEY_CHARACTER=[^:=\ \n\t\f\\] | "\\ "
%state WAITING_VALUE %state WAITING_VALUE
@ -39,7 +39,7 @@ KEY_CHARACTER=[^:=\ \n\r\t\f\\] | "\\ "
<WAITING_VALUE> {FIRST_VALUE_CHARACTER}{VALUE_CHARACTER}* { yybegin(YYINITIAL); return SimpleTypes.VALUE; } <WAITING_VALUE> {FIRST_VALUE_CHARACTER}{VALUE_CHARACTER}* { yybegin(YYINITIAL); return SimpleTypes.VALUE; }
({CRLF}|{WHITE_SPACE})+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; } {CRLF}+ { yybegin(YYINITIAL); return SimpleTypes.CRLF; }
{WHITE_SPACE}+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; } {WHITE_SPACE}+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }

View File

@ -5,9 +5,11 @@ import com.intellij.lang.ASTNode;
import com.intellij.psi.TokenType; import com.intellij.psi.TokenType;
import com.intellij.psi.formatter.common.AbstractBlock; import com.intellij.psi.formatter.common.AbstractBlock;
import com.simpleplugin.psi.SimpleTypes; import com.simpleplugin.psi.SimpleTypes;
import org.jetbrains.annotations.*; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.ArrayList;
import java.util.List;
public class SimpleBlock extends AbstractBlock { public class SimpleBlock extends AbstractBlock {
private SpacingBuilder spacingBuilder; private SpacingBuilder spacingBuilder;
@ -22,16 +24,12 @@ public class SimpleBlock extends AbstractBlock {
protected List<Block> buildChildren() { protected List<Block> buildChildren() {
List<Block> blocks = new ArrayList<Block>(); List<Block> blocks = new ArrayList<Block>();
ASTNode child = myNode.getFirstChildNode(); ASTNode child = myNode.getFirstChildNode();
ASTNode previousChild = null;
while (child != null) { while (child != null) {
if (child.getElementType() != TokenType.WHITE_SPACE && if (child.getElementType() != TokenType.WHITE_SPACE && child.getElementType() != SimpleTypes.CRLF) {
(previousChild == null || previousChild.getElementType() != SimpleTypes.CRLF ||
child.getElementType() != SimpleTypes.CRLF)) {
Block block = new SimpleBlock(child, Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment(), Block block = new SimpleBlock(child, Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment(),
spacingBuilder); spacingBuilder);
blocks.add(block); blocks.add(block);
} }
previousChild = child;
child = child.getTreeNext(); child = child.getTreeNext();
} }
return blocks; return blocks;

View File

@ -1,30 +1,29 @@
/* The following code was generated by JFlex 1.4.3 on 02/09/15 10:04 AM */ /* The following code was generated by JFlex 1.7.0-SNAPSHOT tweaked for IntelliJ platform */
package com.simpleplugin; package com.simpleplugin;
import com.intellij.lexer.FlexLexer; import com.intellij.lexer.FlexLexer;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IElementType;
import com.simpleplugin.psi.SimpleTypes; import com.simpleplugin.psi.SimpleTypes;
import com.intellij.psi.TokenType;
/** /**
* This class is a scanner generated by * This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3 * <a href="http://www.jflex.de/">JFlex</a> 1.7.0-SNAPSHOT
* on 02/09/15 10:04 AM from the specification file * from the specification file <tt>Simple.flex</tt>
* <tt>/Users/vlad/src/SimplePlugin/src/com/simpleplugin/Simple.flex</tt>
*/ */
class SimpleLexer implements FlexLexer { class SimpleLexer implements FlexLexer {
/**
* initial size of the lookahead buffer /** This character denotes the end of file */
*/ public static final int YYEOF = -1;
/** initial size of the lookahead buffer */
private static final int ZZ_BUFFERSIZE = 16384; private static final int ZZ_BUFFERSIZE = 16384;
/** /** lexical states */
* lexical states
*/
public static final int WAITING_VALUE = 2;
public static final int YYINITIAL = 0; public static final int YYINITIAL = 0;
public static final int WAITING_VALUE = 2;
/** /**
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
@ -38,15 +37,25 @@ class SimpleLexer implements FlexLexer {
/** /**
* Translates characters to character classes * Translates characters to character classes
* Chosen bits are [9, 6, 6]
* Total runtime size is 1568 bytes
*/ */
private static final String ZZ_CMAP_PACKED = public static int ZZ_CMAP(int ch) {
"\11\0\1\3\1\1\1\0\1\6\1\2\22\0\1\5\1\7\1\0" + return ZZ_CMAP_A[(ZZ_CMAP_Y[ZZ_CMAP_Z[ch>>12]|((ch>>6)&0x3f)]<<6)|(ch&0x3f)];
"\1\7\26\0\1\10\2\0\1\10\36\0\1\4\uffa3\0"; }
/** /* The ZZ_CMAP_Z table has 272 entries */
* Translates characters to character classes static final char ZZ_CMAP_Z[] = zzUnpackCMap(
*/ "\1\0\1\100\1\200\u010d\100");
private static final char[] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
/* The ZZ_CMAP_Y table has 192 entries */
static final char ZZ_CMAP_Y[] = zzUnpackCMap(
"\1\0\1\1\1\2\175\3\1\4\77\3");
/* The ZZ_CMAP_A table has 320 entries */
static final char ZZ_CMAP_A[] = zzUnpackCMap(
"\11\0\1\2\1\1\1\5\1\6\1\5\22\0\1\4\1\7\1\0\1\7\26\0\1\10\2\0\1\10\36\0\1\3"+
"\50\0\1\5\242\0\2\5\26\0");
/** /**
* Translates DFA states to action switch labels. * Translates DFA states to action switch labels.
@ -55,10 +64,10 @@ class SimpleLexer implements FlexLexer {
private static final String ZZ_ACTION_PACKED_0 = private static final String ZZ_ACTION_PACKED_0 =
"\2\0\1\1\1\2\1\3\1\4\1\5\1\6\1\7"+ "\2\0\1\1\1\2\1\3\1\4\1\5\1\6\1\7"+
"\1\3\1\7\2\0\1\6"; "\1\2\1\10\1\4\1\10\2\0\1\3";
private static int [] zzUnpackAction() { private static int [] zzUnpackAction() {
int[] result = new int[14]; int [] result = new int[16];
int offset = 0; int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result; return result;
@ -84,10 +93,10 @@ class SimpleLexer implements FlexLexer {
private static final String ZZ_ROWMAP_PACKED_0 = private static final String ZZ_ROWMAP_PACKED_0 =
"\0\0\0\11\0\22\0\33\0\44\0\55\0\66\0\77"+ "\0\0\0\11\0\22\0\33\0\44\0\55\0\66\0\77"+
"\0\110\0\121\0\132\0\44\0\121\0\143"; "\0\110\0\121\0\132\0\143\0\154\0\55\0\143\0\121";
private static int [] zzUnpackRowMap() { private static int [] zzUnpackRowMap() {
int[] result = new int[14]; int [] result = new int[16];
int offset = 0; int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result; return result;
@ -110,16 +119,18 @@ class SimpleLexer implements FlexLexer {
private static final int [] ZZ_TRANS = zzUnpackTrans(); private static final int [] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 = private static final String ZZ_TRANS_PACKED_0 =
"\1\3\3\4\1\5\2\4\1\6\1\7\1\10\2\4" + "\1\3\1\4\1\5\1\6\1\5\1\3\1\5\1\7"+
"\1\11\1\12\2\13\2\10\1\3\3\0\1\14\2\0" + "\1\10\1\11\1\12\1\13\1\14\1\15\1\11\1\15"+
"\1\3\2\0\3\4\1\0\2\4\7\0\1\3\3\0" + "\2\11\1\3\2\0\1\16\1\0\1\3\1\0\1\3"+
"\1\6\2\0\6\6\11\0\1\10\2\0\1\10\1\15" + "\2\0\1\4\11\0\1\5\1\0\1\5\1\0\1\5"+
"\1\10\1\0\3\10\2\4\1\11\1\15\1\11\1\13" + "\6\0\1\3\4\0\1\7\1\0\7\7\11\0\1\11"+
"\4\10\1\16\6\10\1\0\2\4\1\13\1\0\2\13" + "\1\0\1\11\1\17\2\11\1\0\2\11\1\0\2\20"+
"\2\0\2\10\1\0\1\10\1\15\1\10\1\0\2\10"; "\1\0\1\20\1\0\1\20\2\0\1\11\1\0\1\13"+
"\1\17\1\13\1\11\1\15\7\11\2\0\2\11\2\0"+
"\1\15\1\0\1\15\1\0\1\15\2\0";
private static int [] zzUnpackTrans() { private static int [] zzUnpackTrans() {
int[] result = new int[108]; int [] result = new int[117];
int offset = 0; int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result; return result;
@ -143,13 +154,10 @@ class SimpleLexer implements FlexLexer {
private static final int ZZ_UNKNOWN_ERROR = 0; private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1; private static final int ZZ_NO_MATCH = 1;
private static final int ZZ_PUSHBACK_2BIG = 2; 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 */ /* error messages for the codes above */
private static final String ZZ_ERROR_MSG[] = { private static final String[] ZZ_ERROR_MSG = {
"Unkown internal scanner error", "Unknown internal scanner error",
"Error: could not match input", "Error: could not match input",
"Error: pushback value was too large" "Error: pushback value was too large"
}; };
@ -160,10 +168,10 @@ class SimpleLexer implements FlexLexer {
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = private static final String ZZ_ATTRIBUTE_PACKED_0 =
"\2\0\4\1\1\11\4\1\2\0\1\1"; "\2\0\5\1\1\11\5\1\2\0\1\1";
private static int [] zzUnpackAttribute() { private static int [] zzUnpackAttribute() {
int[] result = new int[14]; int [] result = new int[16];
int offset = 0; int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result; return result;
@ -181,51 +189,30 @@ class SimpleLexer implements FlexLexer {
return j; return j;
} }
/** /** the input device */
* the current state of the DFA private java.io.Reader zzReader;
*/
/** the current state of the DFA */
private int zzState; private int zzState;
/** /** the current lexical state */
* the current lexical state
*/
private int zzLexicalState = YYINITIAL; private int zzLexicalState = YYINITIAL;
/** /** this buffer contains the current text to be matched and is
* this buffer contains the current text to be matched and is the source of the yytext() string */
* the source of the yytext() string
*/
private CharSequence zzBuffer = ""; private CharSequence zzBuffer = "";
/** /** the textposition at the last accepting state */
* 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; private int zzMarkedPos;
/** /** the current text position in the buffer */
* the textposition at the last state to be included in yytext
*/
private int zzPushbackPos;
/**
* the current text position in the buffer
*/
private int zzCurrentPos; private int zzCurrentPos;
/** /** startRead marks the beginning of the yytext() string in the buffer */
* startRead marks the beginning of the yytext() string in the buffer
*/
private int zzStartRead; private int zzStartRead;
/** /** endRead marks the last character in the buffer, that has been read
* endRead marks the last character in the buffer, that has been read from input */
* from input
*/
private int zzEndRead; private int zzEndRead;
/** /**
@ -233,30 +220,22 @@ class SimpleLexer implements FlexLexer {
*/ */
private boolean zzAtBOL = true; private boolean zzAtBOL = true;
/** /** zzAtEOF == true <=> the scanner is at the EOF */
* zzAtEOF == true <=> the scanner is at the EOF
*/
private boolean zzAtEOF; private boolean zzAtEOF;
/** /** denotes if the user-EOF-code has already been executed */
* denotes if the user-EOF-code has already been executed
*/
private boolean zzEOFDone; private boolean zzEOFDone;
/**
* Creates a new scanner
*
* @param in the java.io.Reader to read input from.
*/
SimpleLexer(java.io.Reader in) { SimpleLexer(java.io.Reader in) {
this.zzReader = 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.
*/
SimpleLexer(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/** /**
* Unpacks the compressed character translation table. * Unpacks the compressed character translation table.
@ -265,10 +244,14 @@ class SimpleLexer implements FlexLexer {
* @return the unpacked character translation table * @return the unpacked character translation table
*/ */
private static char [] zzUnpackCMap(String packed) { private static char [] zzUnpackCMap(String packed) {
char[] map = new char[0x10000]; int size = 0;
for (int i = 0, length = packed.length(); i < length; i += 2) {
size += packed.charAt(i);
}
char[] map = new char[size];
int i = 0; /* index in packed string */ int i = 0; /* index in packed string */
int j = 0; /* index in unpacked array */ int j = 0; /* index in unpacked array */
while (i < 36) { while (i < packed.length()) {
int count = packed.charAt(i++); int count = packed.charAt(i++);
char value = packed.charAt(i++); char value = packed.charAt(i++);
do map[j++] = value; while (--count > 0); do map[j++] = value; while (--count > 0);
@ -286,9 +269,7 @@ class SimpleLexer implements FlexLexer {
public void reset(CharSequence buffer, int start, int end, int initialState) { public void reset(CharSequence buffer, int start, int end, int initialState) {
zzBuffer = buffer; zzBuffer = buffer;
zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer);
zzCurrentPos = zzMarkedPos = zzStartRead = start; zzCurrentPos = zzMarkedPos = zzStartRead = start;
zzPushbackPos = 0;
zzAtEOF = false; zzAtEOF = false;
zzAtBOL = true; zzAtBOL = true;
zzEndRead = end; zzEndRead = end;
@ -299,7 +280,8 @@ class SimpleLexer implements FlexLexer {
* Refills the input buffer. * Refills the input buffer.
* *
* @return <code>false</code>, iff there was new input. * @return <code>false</code>, iff there was new input.
* @throws java.io.IOException if any I/O-Error occurs *
* @exception java.io.IOException if any I/O-Error occurs
*/ */
private boolean zzRefill() throws java.io.IOException { private boolean zzRefill() throws java.io.IOException {
return true; return true;
@ -335,15 +317,16 @@ class SimpleLexer implements FlexLexer {
/** /**
* Returns the character at position <tt>pos</tt> from the * Returns the character at position <tt>pos</tt> from the
* matched text. * matched text.
* <p> *
* It is equivalent to yytext().charAt(pos), but faster * It is equivalent to yytext().charAt(pos), but faster
* *
* @param pos the position of the character to fetch. * @param pos the position of the character to fetch.
* A value from 0 to yylength()-1. * A value from 0 to yylength()-1.
*
* @return the character at position pos * @return the character at position pos
*/ */
public final char yycharat(int pos) { public final char yycharat(int pos) {
return zzBufferArray != null ? zzBufferArray[zzStartRead + pos] : zzBuffer.charAt(zzStartRead + pos); return zzBuffer.charAt(zzStartRead+pos);
} }
@ -357,13 +340,13 @@ class SimpleLexer implements FlexLexer {
/** /**
* Reports an error that occured while scanning. * Reports an error that occured while scanning.
* <p> *
* In a wellformed scanner (no or only correct usage of * In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method * yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen". * will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong * If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.). * (e.g. a JFlex bug producing a faulty scanner etc.).
* <p> *
* Usual syntax/scanner level error handling should be done * Usual syntax/scanner level error handling should be done
* in error fallback rules. * in error fallback rules.
* *
@ -373,7 +356,8 @@ class SimpleLexer implements FlexLexer {
String message; String message;
try { try {
message = ZZ_ERROR_MSG[errorCode]; message = ZZ_ERROR_MSG[errorCode];
} catch (ArrayIndexOutOfBoundsException e) { }
catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
} }
@ -383,7 +367,7 @@ class SimpleLexer implements FlexLexer {
/** /**
* Pushes the specified amount of characters back into the input stream. * Pushes the specified amount of characters back into the input stream.
* <p> *
* They will be read again by then next call of the scanning method * They will be read again by then next call of the scanning method
* *
* @param number the number of characters to be read again. * @param number the number of characters to be read again.
@ -414,7 +398,7 @@ class SimpleLexer implements FlexLexer {
* the end of input is encountered or an I/O-Error occurs. * the end of input is encountered or an I/O-Error occurs.
* *
* @return the next token * @return the next token
* @throws java.io.IOException if any I/O-Error occurs * @exception java.io.IOException if any I/O-Error occurs
*/ */
public IElementType advance() throws java.io.IOException { public IElementType advance() throws java.io.IOException {
int zzInput; int zzInput;
@ -425,8 +409,6 @@ class SimpleLexer implements FlexLexer {
int zzMarkedPosL; int zzMarkedPosL;
int zzEndReadL = zzEndRead; int zzEndReadL = zzEndRead;
CharSequence zzBufferL = zzBuffer; CharSequence zzBufferL = zzBuffer;
char[] zzBufferArrayL = zzBufferArray;
char[] zzCMapL = ZZ_CMAP;
int [] zzTransL = ZZ_TRANS; int [] zzTransL = ZZ_TRANS;
int [] zzRowMapL = ZZ_ROWMAP; int [] zzRowMapL = ZZ_ROWMAP;
@ -441,17 +423,25 @@ class SimpleLexer implements FlexLexer {
zzState = ZZ_LEXSTATE[zzLexicalState]; zzState = ZZ_LEXSTATE[zzLexicalState];
// set up zzAction for empty match case:
int zzAttributes = zzAttrL[zzState];
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
}
zzForAction:
{ zzForAction: {
while (true) { while (true) {
if (zzCurrentPosL < zzEndReadL) if (zzCurrentPosL < zzEndReadL) {
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL/*, zzEndReadL*/);
zzCurrentPosL += Character.charCount(zzInput);
}
else if (zzAtEOF) { else if (zzAtEOF) {
zzInput = YYEOF; zzInput = YYEOF;
break zzForAction; break zzForAction;
} else { }
else {
// store back cached positions // store back cached positions
zzCurrentPos = zzCurrentPosL; zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL; zzMarkedPos = zzMarkedPosL;
@ -464,15 +454,17 @@ class SimpleLexer implements FlexLexer {
if (eof) { if (eof) {
zzInput = YYEOF; zzInput = YYEOF;
break zzForAction; break zzForAction;
} else { }
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++)); else {
zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL/*, zzEndReadL*/);
zzCurrentPosL += Character.charCount(zzInput);
} }
} }
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; int zzNext = zzTransL[ zzRowMapL[zzState] + ZZ_CMAP(zzInput) ];
if (zzNext == -1) break zzForAction; if (zzNext == -1) break zzForAction;
zzState = zzNext; zzState = zzNext;
int zzAttributes = zzAttrL[zzState]; zzAttributes = zzAttrL[zzState];
if ( (zzAttributes & 1) == 1 ) { if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState; zzAction = zzState;
zzMarkedPosL = zzCurrentPosL; zzMarkedPosL = zzCurrentPosL;
@ -485,54 +477,46 @@ class SimpleLexer implements FlexLexer {
// store back cached position // store back cached position
zzMarkedPos = zzMarkedPosL; zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 6: {
yybegin(YYINITIAL);
return SimpleTypes.VALUE;
}
case 8:
break;
case 5: {
yybegin(WAITING_VALUE);
return SimpleTypes.SEPARATOR;
}
case 9:
break;
case 4: {
yybegin(YYINITIAL);
return SimpleTypes.COMMENT;
}
case 10:
break;
case 3: {
return TokenType.BAD_CHARACTER;
}
case 11:
break;
case 2: {
yybegin(YYINITIAL);
return TokenType.WHITE_SPACE;
}
case 12:
break;
case 7: {
yybegin(WAITING_VALUE);
return TokenType.WHITE_SPACE;
}
case 13:
break;
case 1: {
yybegin(YYINITIAL);
return SimpleTypes.KEY;
}
case 14:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true; zzAtEOF = true;
zzDoEOF(); zzDoEOF();
return null; return null;
} else { }
else {
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 1:
{ yybegin(YYINITIAL); return SimpleTypes.KEY;
}
case 9: break;
case 2:
{ yybegin(YYINITIAL); return SimpleTypes.CRLF;
}
case 10: break;
case 3:
{ yybegin(YYINITIAL); return TokenType.WHITE_SPACE;
}
case 11: break;
case 4:
{ return TokenType.BAD_CHARACTER;
}
case 12: break;
case 5:
{ yybegin(YYINITIAL); return SimpleTypes.COMMENT;
}
case 13: break;
case 6:
{ yybegin(WAITING_VALUE); return SimpleTypes.SEPARATOR;
}
case 14: break;
case 7:
{ yybegin(YYINITIAL); return SimpleTypes.VALUE;
}
case 15: break;
case 8:
{ yybegin(WAITING_VALUE); return TokenType.WHITE_SPACE;
}
case 16: break;
default:
zzScanError(ZZ_NO_MATCH); zzScanError(ZZ_NO_MATCH);
} }
} }

View File

@ -1,61 +1,61 @@
Simple File(0,492) Simple File(0,492)
PsiComment(SimpleTokenType.COMMENT)('# You are reading the ".properties" entry.')(0,42) PsiComment(SimpleTokenType.COMMENT)('# You are reading the ".properties" entry.')(0,42)
PsiWhiteSpace('\n')(42,43) PsiElement(SimpleTokenType.CRLF)('\n')(42,43)
PsiComment(SimpleTokenType.COMMENT)('! The exclamation mark can also mark text as comments.')(43,97) PsiComment(SimpleTokenType.COMMENT)('! The exclamation mark can also mark text as comments.')(43,97)
PsiWhiteSpace('\n')(97,98) PsiElement(SimpleTokenType.CRLF)('\n')(97,98)
SimplePropertyImpl(PROPERTY)(98,132) SimplePropertyImpl(PROPERTY)(98,132)
PsiElement(SimpleTokenType.KEY)('website')(98,105) PsiElement(SimpleTokenType.KEY)('website')(98,105)
PsiWhiteSpace(' ')(105,106) PsiWhiteSpace(' ')(105,106)
PsiElement(SimpleTokenType.SEPARATOR)('=')(106,107) PsiElement(SimpleTokenType.SEPARATOR)('=')(106,107)
PsiWhiteSpace(' ')(107,108) PsiWhiteSpace(' ')(107,108)
PsiElement(SimpleTokenType.VALUE)('http://en.wikipedia.org/')(108,132) PsiElement(SimpleTokenType.VALUE)('http://en.wikipedia.org/')(108,132)
PsiWhiteSpace('\n\n')(132,134) PsiElement(SimpleTokenType.CRLF)('\n\n')(132,134)
SimplePropertyImpl(PROPERTY)(134,152) SimplePropertyImpl(PROPERTY)(134,152)
PsiElement(SimpleTokenType.KEY)('language')(134,142) PsiElement(SimpleTokenType.KEY)('language')(134,142)
PsiWhiteSpace(' ')(142,143) PsiWhiteSpace(' ')(142,143)
PsiElement(SimpleTokenType.SEPARATOR)('=')(143,144) PsiElement(SimpleTokenType.SEPARATOR)('=')(143,144)
PsiWhiteSpace(' ')(144,145) PsiWhiteSpace(' ')(144,145)
PsiElement(SimpleTokenType.VALUE)('English')(145,152) PsiElement(SimpleTokenType.VALUE)('English')(145,152)
PsiWhiteSpace('\n')(152,153) PsiElement(SimpleTokenType.CRLF)('\n')(152,153)
PsiComment(SimpleTokenType.COMMENT)('# The backslash below tells the application to continue reading')(153,216) PsiComment(SimpleTokenType.COMMENT)('# The backslash below tells the application to continue reading')(153,216)
PsiWhiteSpace('\n')(216,217) PsiElement(SimpleTokenType.CRLF)('\n')(216,217)
PsiComment(SimpleTokenType.COMMENT)('# the value onto the next line.')(217,248) PsiComment(SimpleTokenType.COMMENT)('# the value onto the next line.')(217,248)
PsiWhiteSpace('\n')(248,249) PsiElement(SimpleTokenType.CRLF)('\n')(248,249)
SimplePropertyImpl(PROPERTY)(249,292) SimplePropertyImpl(PROPERTY)(249,292)
PsiElement(SimpleTokenType.KEY)('message')(249,256) PsiElement(SimpleTokenType.KEY)('message')(249,256)
PsiWhiteSpace(' ')(256,257) PsiWhiteSpace(' ')(256,257)
PsiElement(SimpleTokenType.SEPARATOR)('=')(257,258) PsiElement(SimpleTokenType.SEPARATOR)('=')(257,258)
PsiWhiteSpace(' ')(258,259) PsiWhiteSpace(' ')(258,259)
PsiElement(SimpleTokenType.VALUE)('Welcome to \\n Wikipedia!')(259,292) PsiElement(SimpleTokenType.VALUE)('Welcome to \\n Wikipedia!')(259,292)
PsiWhiteSpace('\n')(292,293) PsiElement(SimpleTokenType.CRLF)('\n')(292,293)
PsiComment(SimpleTokenType.COMMENT)('# Add spaces to the key')(293,316) PsiComment(SimpleTokenType.COMMENT)('# Add spaces to the key')(293,316)
PsiWhiteSpace('\n')(316,317) PsiElement(SimpleTokenType.CRLF)('\n')(316,317)
SimplePropertyImpl(PROPERTY)(317,410) SimplePropertyImpl(PROPERTY)(317,410)
PsiElement(SimpleTokenType.KEY)('key\ with\ spaces')(317,334) PsiElement(SimpleTokenType.KEY)('key\ with\ spaces')(317,334)
PsiWhiteSpace(' ')(334,335) PsiWhiteSpace(' ')(334,335)
PsiElement(SimpleTokenType.SEPARATOR)('=')(335,336) PsiElement(SimpleTokenType.SEPARATOR)('=')(335,336)
PsiWhiteSpace(' ')(336,337) PsiWhiteSpace(' ')(336,337)
PsiElement(SimpleTokenType.VALUE)('This is the value that could be looked up with the key "key with spaces".')(337,410) PsiElement(SimpleTokenType.VALUE)('This is the value that could be looked up with the key "key with spaces".')(337,410)
PsiWhiteSpace('\n')(410,411) PsiElement(SimpleTokenType.CRLF)('\n')(410,411)
PsiComment(SimpleTokenType.COMMENT)('# Unicode')(411,420) PsiComment(SimpleTokenType.COMMENT)('# Unicode')(411,420)
PsiWhiteSpace('\n')(420,421) PsiElement(SimpleTokenType.CRLF)('\n')(420,421)
SimplePropertyImpl(PROPERTY)(421,433) SimplePropertyImpl(PROPERTY)(421,433)
PsiElement(SimpleTokenType.KEY)('tab')(421,424) PsiElement(SimpleTokenType.KEY)('tab')(421,424)
PsiWhiteSpace(' ')(424,425) PsiWhiteSpace(' ')(424,425)
PsiElement(SimpleTokenType.SEPARATOR)(':')(425,426) PsiElement(SimpleTokenType.SEPARATOR)(':')(425,426)
PsiWhiteSpace(' ')(426,427) PsiWhiteSpace(' ')(426,427)
PsiElement(SimpleTokenType.VALUE)('\u0009')(427,433) PsiElement(SimpleTokenType.VALUE)('\u0009')(427,433)
PsiWhiteSpace('\n')(433,434) PsiElement(SimpleTokenType.CRLF)('\n')(433,434)
PsiComment(SimpleTokenType.COMMENT)('# test for illegal key attempt')(434,464) PsiComment(SimpleTokenType.COMMENT)('# test for illegal key attempt')(434,464)
PsiWhiteSpace('\n')(464,465) PsiElement(SimpleTokenType.CRLF)('\n')(464,465)
SimplePropertyImpl(PROPERTY)(465,468) SimplePropertyImpl(PROPERTY)(465,468)
PsiElement(SimpleTokenType.KEY)('key')(465,468) PsiElement(SimpleTokenType.KEY)('key')(465,468)
PsiErrorElement:<property>, SimpleTokenType.COMMENT, SimpleTokenType.CRLF or SimpleTokenType.SEPARATOR expected, got '\'(468,469) PsiErrorElement:<property>, SimpleTokenType.COMMENT, SimpleTokenType.CRLF or SimpleTokenType.SEPARATOR expected, got '\'(468,469)
PsiElement(BAD_CHARACTER)('\')(468,469) PsiElement(BAD_CHARACTER)('\')(468,469)
PsiWhiteSpace('\n')(469,470) PsiElement(SimpleTokenType.CRLF)('\n')(469,470)
PsiElement(SimpleTokenType.KEY)('with')(470,474) PsiElement(SimpleTokenType.KEY)('with')(470,474)
PsiElement(BAD_CHARACTER)('\')(474,475) PsiElement(BAD_CHARACTER)('\')(474,475)
PsiWhiteSpace('\n')(475,476) PsiElement(SimpleTokenType.CRLF)('\n')(475,476)
PsiElement(SimpleTokenType.KEY)('endofline')(476,485) PsiElement(SimpleTokenType.KEY)('endofline')(476,485)
PsiWhiteSpace(' ')(485,486) PsiWhiteSpace(' ')(485,486)
PsiElement(SimpleTokenType.SEPARATOR)('=')(486,487) PsiElement(SimpleTokenType.SEPARATOR)('=')(486,487)

View File

@ -8,6 +8,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageInfo;
import com.intellij.util.containers.ContainerUtil;
import com.simpleplugin.psi.SimpleProperty; import com.simpleplugin.psi.SimpleProperty;
import java.util.Arrays; import java.util.Arrays;
@ -45,7 +46,8 @@ public class SimpleCodeInsightTest extends LightCodeInsightFixtureTestCase {
new WriteCommandAction.Simple(getProject()) { new WriteCommandAction.Simple(getProject()) {
@Override @Override
protected void run() throws Throwable { protected void run() throws Throwable {
CodeStyleManager.getInstance(getProject()).reformat(myFixture.getFile()); CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(),
ContainerUtil.newArrayList(myFixture.getFile().getTextRange()));
} }
}.execute(); }.execute();
myFixture.checkResultByFile("DefaultTestData.simple"); myFixture.checkResultByFile("DefaultTestData.simple");