Skip to content

Commit

Permalink
Fixed highlight for "switch" keyword (#5)
Browse files Browse the repository at this point in the history
* 1. Fixed highlight for "switch" keyword
2. Updated readme to expand information about how to start develop the Zephir plugin
3. Changed depended lib to support by now days IDE

* Removed extra gitignore files

* removed extra space

* Added empty line

* Syntax fix

* Added empty line to xml file
  • Loading branch information
Alexandr Baranezky authored and sergeyklay committed May 6, 2017
1 parent d483961 commit 07a947d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 92 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/out/
/gen/
src/com/zephir/lexer/ZephirLexer.java
*~
*.jar
59 changes: 0 additions & 59 deletions META-INF/plugin.xml

This file was deleted.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@ Zephir IntelliJ IDEA plugin
==========================

Plugin page: http://plugins.jetbrains.com/plugin/7558

`Start develop the Zephir plugin`

1. Install next plugins for Intellij

https://plugins.jetbrains.com/plugin/6606-grammar-kit
https://plugins.jetbrains.com/plugin/227-psiviewer


2. Go to Zephir.bnf file and run "Generate parser code" through context menu
3. Go to src/com/zephir/Zephir.flex and run "Run JFlex generator" through context menu


4. Run the plugin by Menu->Run->Run

To automatically detect "Zephir plugin" in the debugged IDE, uncomment next lines in the `resources/META-INF/plugin.xml`

<!--<lang.parserDefinition language="Zephir" implementationClass="com.zephir.ZephirParserDefinition"/>-->
11 changes: 5 additions & 6 deletions Zephir.iml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PLUGIN_MODULE" version="4">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/META-INF/plugin.xml" />
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
</component>
</module>

</module>
Binary file removed lib/JFlex.jar
Binary file not shown.
47 changes: 22 additions & 25 deletions lib/idea-flex.skeleton
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

/** 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 = ...;

Expand All @@ -8,18 +12,18 @@
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",
private static final String[] ZZ_ERROR_MSG = {
"Unknown fileTemplates scanner error",
"Error: could not match input",
"Error: pushback value was too large"
};

--- isFinal list
/** the input device */
private java.io.Reader zzReader;

/** the current state of the DFA */
private int zzState;

Expand All @@ -30,15 +34,9 @@
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;

Expand All @@ -57,23 +55,24 @@
/** 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 class code

--- constructor declaration

public final int getTokenStart(){
public final int getTokenStart() {
return zzStartRead;
}

public final int getTokenEnd(){
public final int getTokenEnd() {
return getTokenStart() + yylength();
}

public void reset(CharSequence buffer, int start, int end,int initialState){
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;
Expand Down Expand Up @@ -130,7 +129,7 @@
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos);
return zzBuffer.charAt(zzStartRead+pos);
}


Expand Down Expand Up @@ -202,8 +201,6 @@
int zzMarkedPosL;
int zzEndReadL = zzEndRead;
CharSequence zzBufferL = zzBuffer;
char[] zzBufferArrayL = zzBufferArray;
char [] zzCMapL = ZZ_CMAP;

--- local declarations

Expand Down Expand Up @@ -233,13 +230,13 @@
zzMarkedPos = zzMarkedPosL;
--- char count update

--- actions
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
--- eofvalue
}
else {
}
else {
--- actions
default:
--- no match
}
}
Expand Down
62 changes: 62 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<idea-plugin url="https://github.com/zephir-lang/idea-plugin">
<id>com.zephir</id>
<name>Zephir</name>
<version>0.2.5</version>
<vendor email="[email protected]" url="http://zephir-lang.com">Zephir Team</vendor>

<description><![CDATA[
Language support for the <a href="http://zephir-lang.com">Zephir Language</a>
<p>Zephir - Ze(nd Engine) Ph(p) I(nt)r(mediate) - is a high level language that eases the creation and maintainability
of extensions for PHP. Zephir extensions are exported to C code that can be compiled and optimized by major C compilers
such as gcc/clang/vc++. Functionality is exposed to the PHP language.</p>
]]></description>

<change-notes><![CDATA[
<li><b>0.2.5</b>: Fixed "switch" keyword detection</li>
<li><b>0.2.4</b>: Added brace matching</li>
<li><b>0.2.3</b>: Fixed build</li>
<li><b>0.2.2</b>: Improve highlighter, added color settings page</li>
<li><b>0.2.1</b>: Disabled "New Zephir class" dialog</li>
<li><b>0.2.0</b>: Added lexer and simple syntax highlighter</li>
<li><b>0.1.0</b>: Initial plugin</li>
]]></change-notes>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
<idea-version since-build="130.1"/>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
on how to target different products -->
<depends>com.intellij.modules.lang</depends>

<extensions defaultExtensionNs="com.intellij">

<!--<lang.parserDefinition language="Zephir" implementationClass="com.zephir.ZephirParserDefinition"/>-->

<fileTypeFactory implementation="com.zephir.ZephirFileTypeFactory"/>
<lang.commenter language="Zephir" implementationClass="com.zephir.lang.ZephirCommenter"/>
<lang.braceMatcher language="Zephir" implementationClass="com.zephir.lang.ZephirBraceMatcher"/>
<!--<lang.formatter language="Zephir" implementationClass="com.zephir.formatting.ZephirFormattingModelBuilder"/>-->
<lang.syntaxHighlighterFactory key="Zephir" implementationClass="com.zephir.highlight.ZephirSyntaxHighlighterFactory"/>
<colorSettingsPage implementation="com.zephir.highlight.ZephirColorSettingsPage"/>

<!--<completion.contributor language="Zephir" implementationClass="com.zephir.completion.ZephirClassCompletion"/>-->
<completion.contributor language="Zephir" implementationClass="com.zephir.completion.ZephirKeywordCompletionContributor"/>
<internalFileTemplate name="Zephir Class"/>
<internalFileTemplate name="Zephir Interface"/>
</extensions>

<application-components>
<!-- Add your application components here -->
</application-components>

<project-components>
<!-- Add your project components here -->
</project-components>

<actions>
<action id="Zephir.NewClass" class="com.zephir.actions.ZephirNewClassAction">
<add-to-group group-id="NewGroup" relative-to-action="NewFromTemplate" anchor="before"/>
</action>
</actions>

</idea-plugin>
2 changes: 2 additions & 0 deletions src/com/zephir/Zephir.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
parserClass="com.zephir.parser.ZephirParser"
parserUtilClass="com.zephir.parser.ZephirParserUtil"

extends="com.intellij.extapi.psi.ASTWrapperPsiElement"

Expand All @@ -11,6 +12,7 @@
elementTypeHolderClass="com.zephir.psi.ZephirTypes"
elementTypeClass="com.zephir.psi.ZephirElementType"
tokenTypeClass="com.zephir.psi.ZephirTokenType"
psiImplUtilClass="com.zephir.psi.impl.ZephirPsiImplUtil"
tokens = [
// regex
comment='regexp://.*'
Expand Down
2 changes: 1 addition & 1 deletion src/com/zephir/lexer/Zephir.flex
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ STRING = {DOUBLE_QUOTE} ( [^\"\\] | "\\" ( {DOUBLE_QUOTE} | {SINGLE_QUOTE} | {CO
"if" { yybegin(YYINITIAL); return ZephirTypes.IF; }
"else" { yybegin(YYINITIAL); return ZephirTypes.ELSE; }
"elseif" { yybegin(YYINITIAL); return ZephirTypes.ELSEIF; }
"swith" { yybegin(YYINITIAL); return ZephirTypes.SWITCH; }
"switch" { yybegin(YYINITIAL); return ZephirTypes.SWITCH; }
"case" { yybegin(YYINITIAL); return ZephirTypes.CASE; }
"default" { yybegin(YYINITIAL); return ZephirTypes.DEFAULT; }
"do" { yybegin(YYINITIAL); return ZephirTypes.DO; }
Expand Down

0 comments on commit 07a947d

Please sign in to comment.