Permalink
Browse files

Lexer test added. Fixed VSFT & .flex file

  • Loading branch information...
1 parent 6d2626a commit 9e65bff390409d9937c4554a05fb72b1fa541834 @kvmamich committed Nov 10, 2011
View
51 resources/META-INF/plugin.xml
@@ -1,44 +1,25 @@
-<idea-plugin url="http://plugins.intellij.net/plugin/?id=164">
- <name>IdeaVIM</name>
- <id>IdeaVIM</id>
- <description><![CDATA[
- VIM Emulator. This plugin provides nearly complete vi/vim/gvim emulation while editing files in IntelliJ platform based products. It actually emulates 'gvim' more than 'vim'. IdeaVim can be used with IntellIJ IDEA, RubyMine, PyCharm, PhpStorm and WebStorm IDEs.
- The following functionality is supported:
- <ul>
- <li>Motion keys</li>
- <li>Deletion/Changing</li>
- <li>Insert mode commands</li>
- <li>Marks</li>
- <li>Registers</li>
- <li>VIM undo/redo</li>
- <li>Visual mode commands</li>
- <li>Some Ex commands</li>
- <li>Some :set options</li>
- <li>Full VIM regular expressions for search and search/replace</li>
- <li>Macros</li>
- <li>Diagraphs</li>
- <li>VIM help</li>
- </ul>
- ]]></description>
- <version>@VERSION@</version>
- <vendor logo="/icons/vim16x16.png">Rick Maddy, JetBrains</vendor>
+<idea-plugin version="2">
+ <name>Plugin name here</name>
+ <description>short description of the plugin</description>
+ <version>1.0</version>
+ <vendor>YourCompany</vendor>
+ <idea-version since-build="8000"/>
- <helpset file="help.jar" path="/VimHelp.hs"/>
- <idea-version since-build="@SINCE-VERSION@"/>
-
- <!-- Mark the plugin as compatible with RubyMine and other products based on the IntelliJ platform -->
- <depends>com.intellij.modules.lang</depends>
- <resource-bundle xmlns="">messages</resource-bundle>
-
- <application-components>
+ <application-components>
<component>
<implementation-class>com.maddyhome.idea.vim.VimPlugin</implementation-class>
</component>
</application-components>
- <extensions defaultExtensionNs="com.intellij">
+ <project-components>
+ <!-- Add your project components here -->
+ </project-components>
+
+ <extensions defaultExtensionNs="com.intellij">
<errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
- </extensions>
+ <fileTypeFactory implementation="com.maddyhome.idea.vim.file.VimScriptFileTypeLoader"/>
+
+ </extensions>
<actions>
<action id="VimPluginToggle" class="com.maddyhome.idea.vim.VimPluginToggleAction" text="VIM Emulator" description="Toggle the Vim Plugin On/Off">
@@ -342,4 +323,4 @@
<action id="VimEditorUp" class="com.maddyhome.idea.vim.action.key.UpAction" text="Up"/>
<action id="VimDigraphEntry" class="com.maddyhome.idea.vim.action.key.KeyAction" text="Digraph Entry"/>
</actions>
-</idea-plugin>
+</idea-plugin>
View
2 src/com/maddyhome/idea/vim/file/VimScriptFileType.java
@@ -45,6 +45,6 @@ public String getDefaultExtension() {
@Nullable
public Icon getIcon() {
- return IconLoader.findIcon("resources/icons/logo.png"); //TODO: am I really should do this?
+ return IconLoader.findIcon("/icons/logo.png"); //TODO: am I really should do this?
}
}
View
4 src/com/maddyhome/idea/vim/lang/lexer/VimScriptTokenTypes.java
@@ -71,11 +71,9 @@
/* string */
public static final IElementType STRING = new VimScriptElementType("string");
+ public static final TokenSet strings = TokenSet.create(STRING);
/* comment */
public static final IElementType COMMENT = new VimScriptElementType("comment");
public static final TokenSet comments = TokenSet.create(COMMENT);
-
- /* eof */
- public static final IElementType EOF = new VimScriptElementType("EOF");
}
View
9 src/com/maddyhome/idea/vim/lang/lexer/_VimScriptLexer.java
@@ -1,4 +1,4 @@
-/* The following code was generated by JFlex 1.4.3 on 04.11.11 1:00 */
+/* The following code was generated by JFlex 1.4.3 on 09.11.11 22:49 */
/**
* VimScript lexer.
@@ -8,15 +8,16 @@
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
+import static com.maddyhome.idea.vim.lang.lexer.VimScriptTokenTypes.*;
/**
* This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
- * on 04.11.11 1:00 from the specification file
+ * on 09.11.11 22:49 from the specification file
* <tt>D:/CSC/IdeaVIM/ideavim/src/com/maddyhome/idea/vim/lang/lexer/vimscript.flex</tt>
*/
-public final class _VimScriptLexer implements FlexLexer, VimScriptTokenTypes {
+public final class _VimScriptLexer implements FlexLexer {
/** initial size of the lookahead buffer */
private static final int ZZ_BUFFERSIZE = 16384;
@@ -654,7 +655,7 @@ else if (zzAtEOF) {
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
{
- return EOF;
+ return null;
}
}
else {
View
4 src/com/maddyhome/idea/vim/lang/lexer/vimscript.flex
@@ -6,7 +6,7 @@ package com.maddyhome.idea.vim.lang.lexer;
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
-import static com.maddyhome.idea.vim.lang.lexer.VimScriptTokenTypes;
+import static com.maddyhome.idea.vim.lang.lexer.VimScriptTokenTypes.*;
%%
@@ -109,5 +109,5 @@ Identifier = {Name}
{SpaceChar} { return WHITESPACE; }
{NewLineChar} {}
-<<EOF>> { return EOF; }
+<<EOF>> { return null; }
. { return BAD_CHARACTER; }
View
182 test/com/maddyhome/idea/vim/lang/lexer/VimScriptLexerTest.java
@@ -0,0 +1,182 @@
+package com.maddyhome.idea.vim.lang.lexer;
+
+import com.intellij.psi.tree.IElementType;
+import org.junit.*;
+
+import java.io.*;
+import java.util.ArrayList;
+
+/**
+ * <p>Date: 02.11.11</p>
+ * <p>Test class for VimScriptLexer.</p>
+ *
+ * @author Ksenia V. Mamich
+ * @version 1.0
+ */
+public class VimScriptLexerTest {
+ String dir = "test/com/maddyhome/idea/vim/lang/lexer/files/";
+
+ /* Tests only separate tokens */
+ String testTokensFile = "testTokens";
+
+ /* Pattern for more advanced tests */
+ String test = "test";
+
+ @Test
+ public void testTokenFile() {
+ final IElementType [] expected = {
+ VimScriptTokenTypes.OP_EQUAL_TO,
+ VimScriptTokenTypes.OP_NOT_EQUAL_TO,
+ VimScriptTokenTypes.OP_GT_EQ,
+ VimScriptTokenTypes.OP_GT,
+ VimScriptTokenTypes.OP_LT_EQ,
+ VimScriptTokenTypes.OP_LT,
+ VimScriptTokenTypes.OP_MATCHES,
+ VimScriptTokenTypes.OP_NOT_MATCHES,
+ VimScriptTokenTypes.OP_LOGICAL_OR,
+ VimScriptTokenTypes.OP_LOGICAL_AND,
+ VimScriptTokenTypes.OP_PLUS,
+ VimScriptTokenTypes.OP_MINUS,
+ VimScriptTokenTypes.OP_MULT,
+ VimScriptTokenTypes.OP_DIV,
+ VimScriptTokenTypes.OP_MOD,
+ VimScriptTokenTypes.OP_ASSIGN,
+ VimScriptTokenTypes.COMMENT,
+ VimScriptTokenTypes.INTEGER,
+ VimScriptTokenTypes.INTEGER,
+ VimScriptTokenTypes.WHITESPACE,
+ VimScriptTokenTypes.INTEGER,
+ VimScriptTokenTypes.COMMENT,
+ VimScriptTokenTypes.FLOAT,
+ VimScriptTokenTypes.FLOAT,
+ VimScriptTokenTypes.FLOAT,
+ VimScriptTokenTypes.FLOAT,
+ VimScriptTokenTypes.FLOAT,
+ VimScriptTokenTypes.FLOAT,
+ VimScriptTokenTypes.FLOAT,
+ VimScriptTokenTypes.INTEGER,
+ VimScriptTokenTypes.DOT,
+ VimScriptTokenTypes.WHITESPACE,
+ VimScriptTokenTypes.COMMENT,
+ VimScriptTokenTypes.INTEGER,
+ VimScriptTokenTypes.IDENTIFIER,
+ VimScriptTokenTypes.WHITESPACE,
+ VimScriptTokenTypes.COMMENT,
+ VimScriptTokenTypes.COMMENT,
+ VimScriptTokenTypes.VARIABLE_WITH_PREFIX,
+ VimScriptTokenTypes.VARIABLE_WITH_PREFIX,
+ VimScriptTokenTypes.VARIABLE_WITH_PREFIX,
+ VimScriptTokenTypes.IDENTIFIER,
+ VimScriptTokenTypes.COLON,
+ VimScriptTokenTypes.IDENTIFIER,
+ VimScriptTokenTypes.WHITESPACE,
+ VimScriptTokenTypes.COMMENT,
+ VimScriptTokenTypes.ENVIRONMENT_VARIABLE,
+ VimScriptTokenTypes.OPTION,
+ VimScriptTokenTypes.REGISTER,
+ VimScriptTokenTypes.IDENTIFIER,
+ VimScriptTokenTypes.IDENTIFIER,
+ VimScriptTokenTypes.IDENTIFIER,
+ VimScriptTokenTypes.STRING,
+ VimScriptTokenTypes.STRING,
+ VimScriptTokenTypes.LEFT_ROUND_BRACKET,
+ VimScriptTokenTypes.RIGHT_ROUND_BRACKET,
+ VimScriptTokenTypes.LEFT_SQUARE_BRACKET,
+ VimScriptTokenTypes.RIGHT_SQUARE_BRACKET,
+ VimScriptTokenTypes.LEFT_CURLY_BRACKET,
+ VimScriptTokenTypes.RIGHT_CURLY_BRACKET,
+ VimScriptTokenTypes.COLON,
+ VimScriptTokenTypes.DOT,
+ VimScriptTokenTypes.BAD_CHARACTER,
+ VimScriptTokenTypes.WHITESPACE,
+ VimScriptTokenTypes.COMMENT,
+ VimScriptTokenTypes.QUESTION_MARK,
+ VimScriptTokenTypes.EXCLAMATION_MARK,
+ };
+
+ try {
+ File file = new File(dir + testTokensFile + ".vim");
+ ArrayList<IElementType> actual = new ArrayList<IElementType>();
+
+ VimScriptFlexLexer lexer = new VimScriptFlexLexer();
+ final String data = read(file);
+ lexer.start(data);
+ while (true) {
+ IElementType token = lexer.getTokenType();
+ actual.add(token);
+ if (token == null) {
+ break;
+ }
+ lexer.advance();
+ }
+
+ Assert.assertArrayEquals(expected, actual.toArray());
+
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testExpression() {
+ IElementType [] expected = {
+ VimScriptTokenTypes.IDENTIFIER,
+ VimScriptTokenTypes.WHITESPACE,
+ VimScriptTokenTypes.VARIABLE_WITH_PREFIX,
+ VimScriptTokenTypes.WHITESPACE,
+ VimScriptTokenTypes.OP_ASSIGN,
+ VimScriptTokenTypes.WHITESPACE,
+ VimScriptTokenTypes.INTEGER,
+ };
+ ArrayList<IElementType> actual = new ArrayList<IElementType>();
+ try {
+ File file = new File(dir + test + "1.vim");
+
+ VimScriptFlexLexer lexer = new VimScriptFlexLexer();
+ final String data = readFile(file);
+
+ lexer.start(data);
+
+ while (true) {
+ IElementType token = lexer.getTokenType();
+ actual.add(token);
+ if (token == null) {
+ break;
+ }
+ lexer.advance();
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ Assert.assertArrayEquals(expected, actual.toArray());
+ }
+
+ private static String readFile(File file) throws IOException {
+ StringBuilder b = new StringBuilder();
+ FileReader fr = new FileReader(file);
+ char[] buf = new char[4096];
+ while (true) {
+ int n = fr.read(buf);
+ if (n < 0) {
+ break;
+ }
+ b.append(buf, 0, n);
+ }
+ return b.toString();
+ }
+
+ private static String read(File file) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ BufferedReader br = new BufferedReader(new FileReader(file));
+ while (true) {
+ String line = br.readLine();
+ if (line == null) {
+ break;
+ }
+ sb.append(line).append('\n');
+ }
+ return sb.toString();
+ }
+}
View
1 test/com/maddyhome/idea/vim/lang/lexer/files/test1.vim
@@ -0,0 +1 @@
+set b:var = 1
View
60 test/com/maddyhome/idea/vim/lang/lexer/files/testTokens.vim
@@ -0,0 +1,60 @@
+==
+!=
+>=
+>
+<=
+<
+=~
+!~
+||
+&&
++
+-
+*
+/
+%
+=
+
+" integers
+-123
+0x10 0177
+
+" floats
+123.456
++0.0001
+55.0
+-0.123
+1.234e03
+1.0E-6
+-3.1416e+88
+3. "empty {M}
+1e40 "missing .{M}
+
+" prefix:var
+a:var
+b:var
+t:var
+m:var " invalid
+
+$env
+&opt
+@reg
+
+Count
+let
+while
+
+"Hello, world!"
+'Tested.'
+
+()
+[]
+{}
+
+:
+.
+; "bad character
+?
+!
+
+

0 comments on commit 9e65bff

Please sign in to comment.