A whole lot of code formatting, unused import removal and other readability fixes.

Syntax checking should now stop from generating errors with passed jME3 built-in vars. Those variables are only accepted used with "in" or "uniform".

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9346 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
dan..om 13 years ago
parent cd010fa5e7
commit 690915870c
  1. 4
      sdk/jme3-glsl-support/nbproject/project.properties
  2. 27
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslCompletionProvider.java
  3. 15
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslShaderFileObserver.java
  4. 46
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslVocabularyManager.java
  5. 44
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslFragmentShaderDataObject.java
  6. 35
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslGeometryShaderDataObject.java
  7. 42
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslVertexShaderDataObject.java
  8. 1
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/glsl/GLSL_130.nbs
  9. 156
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/glsl/Glsl.java
  10. 10
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/Glsl.java
  11. 156
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/GlslLexer.java
  12. 1
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/GlslTokenId.java
  13. 10
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/vocabulary/GLSLElementDescriptor.java
  14. 3
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/vocabulary/GLSLVocabulary.java

@ -2,5 +2,5 @@ javac.compilerargs=-Xlint -Xlint:-serial
javac.source=1.5 javac.source=1.5
license.file=license.txt license.file=license.txt
nbm.homepage=http://kenai.com/projects/netbeans-opengl-pack nbm.homepage=http://kenai.com/projects/netbeans-opengl-pack
nbm.module.author=Mathias Henze, Michael Bien nbm.module.author=Mathias Henze, Michael Bien, Dany Rioux
spec.version.base=3.0.0 spec.version.base=3.0.1.0

@ -23,7 +23,6 @@ import java.awt.Graphics;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.net.URL; import java.net.URL;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import net.java.nboglpack.glsleditor.dataobject.GlslFragmentShaderDataLoader; import net.java.nboglpack.glsleditor.dataobject.GlslFragmentShaderDataLoader;
import net.java.nboglpack.glsleditor.dataobject.GlslGeometryShaderDataLoader; import net.java.nboglpack.glsleditor.dataobject.GlslGeometryShaderDataLoader;
import net.java.nboglpack.glsleditor.dataobject.GlslVertexShaderDataLoader; import net.java.nboglpack.glsleditor.dataobject.GlslVertexShaderDataLoader;
@ -31,7 +30,6 @@ import net.java.nboglpack.glsleditor.glsl.Glsl;
import net.java.nboglpack.glsleditor.vocabulary.GLSLElementDescriptor; import net.java.nboglpack.glsleditor.vocabulary.GLSLElementDescriptor;
import org.netbeans.spi.editor.completion.support.CompletionUtilities; import org.netbeans.spi.editor.completion.support.CompletionUtilities;
/** /**
* Completion provider for the OpenGL Shading Language editor. * Completion provider for the OpenGL Shading Language editor.
* *
@ -41,7 +39,6 @@ import org.netbeans.spi.editor.completion.support.CompletionUtilities;
public class GlslCompletionProvider implements CompletionProvider { public class GlslCompletionProvider implements CompletionProvider {
private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslCompletionProvider.class.getName()); private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslCompletionProvider.class.getName());
private final String mimeType; private final String mimeType;
private GlslCompletionProvider(String mimeType) { private GlslCompletionProvider(String mimeType) {
@ -56,19 +53,18 @@ public class GlslCompletionProvider implements CompletionProvider {
return 0; return 0;
} }
public static GlslCompletionProvider createVSCompletionProvider(){ public static GlslCompletionProvider createVSCompletionProvider() {
return new GlslCompletionProvider(GlslVertexShaderDataLoader.REQUIRED_MIME); return new GlslCompletionProvider(GlslVertexShaderDataLoader.REQUIRED_MIME);
} }
public static GlslCompletionProvider createGSCompletionProvider(){ public static GlslCompletionProvider createGSCompletionProvider() {
return new GlslCompletionProvider(GlslGeometryShaderDataLoader.REQUIRED_MIME); return new GlslCompletionProvider(GlslGeometryShaderDataLoader.REQUIRED_MIME);
} }
public static GlslCompletionProvider createFSCompletionProvider(){ public static GlslCompletionProvider createFSCompletionProvider() {
return new GlslCompletionProvider(GlslFragmentShaderDataLoader.REQUIRED_MIME); return new GlslCompletionProvider(GlslFragmentShaderDataLoader.REQUIRED_MIME);
} }
private static class GlslCompletionQuery extends AsyncCompletionQuery { private static class GlslCompletionQuery extends AsyncCompletionQuery {
private GlslVocabularyManager vocabulary; private GlslVocabularyManager vocabulary;
@ -99,7 +95,7 @@ public class GlslCompletionProvider implements CompletionProvider {
} }
// add user declared functions first // add user declared functions first
synchronized(Glsl.declaredFunctions) { synchronized (Glsl.declaredFunctions) {
Set<Entry<String, GLSLElementDescriptor>> entrySet = Glsl.declaredFunctions.entrySet(); Set<Entry<String, GLSLElementDescriptor>> entrySet = Glsl.declaredFunctions.entrySet();
for (Entry<String, GLSLElementDescriptor> entry : entrySet) { for (Entry<String, GLSLElementDescriptor> entry : entrySet) {
@ -126,10 +122,11 @@ public class GlslCompletionProvider implements CompletionProvider {
GLSLElementDescriptor[] elements = vocabulary.getDesc(name); GLSLElementDescriptor[] elements = vocabulary.getDesc(name);
if (elements != null) { if (elements != null) {
for (GLSLElementDescriptor element : elements) for (GLSLElementDescriptor element : elements) {
completionResultSet.addItem(new GlslCompletionItem(name, element, prefix, pos)); completionResultSet.addItem(new GlslCompletionItem(name, element, prefix, pos));
} }
} }
}
} }
} }
@ -141,14 +138,11 @@ public class GlslCompletionProvider implements CompletionProvider {
private GLSLElementDescriptor content; private GLSLElementDescriptor content;
private int carretPosition = 0; private int carretPosition = 0;
private String prefix; private String prefix;
private String leftText; private String leftText;
private String rightText; private String rightText;
private String ARGUMENTS_COLOR = "<font color=#b28b00>"; private String ARGUMENTS_COLOR = "<font color=#b28b00>";
private String BUILD_IN_VAR_COLOR = "<font color=#ce7b00>"; private String BUILD_IN_VAR_COLOR = "<font color=#ce7b00>";
private String KEYWORD_COLOR = "<font color=#000099>"; private String KEYWORD_COLOR = "<font color=#000099>";
private int priority; private int priority;
public GlslCompletionItem(String key, GLSLElementDescriptor content, String prefix, int carretPosition) { public GlslCompletionItem(String key, GLSLElementDescriptor content, String prefix, int carretPosition) {
@ -224,8 +218,8 @@ public class GlslCompletionProvider implements CompletionProvider {
Completion.get().hideAll(); Completion.get().hideAll();
// replace prefix with key // replace prefix with key
try { try {
component.getDocument().remove(carretPosition-prefix.length(), prefix.length()); component.getDocument().remove(carretPosition - prefix.length(), prefix.length());
component.getDocument().insertString(carretPosition-prefix.length(), key, null); component.getDocument().insertString(carretPosition - prefix.length(), key, null);
} catch (BadLocationException e) { } catch (BadLocationException e) {
LOGGER.notify(e); LOGGER.notify(e);
} }
@ -252,6 +246,7 @@ public class GlslCompletionProvider implements CompletionProvider {
} }
return new AsyncCompletionTask(new AsyncCompletionQuery() { return new AsyncCompletionTask(new AsyncCompletionQuery() {
private GlslDocItem item = new GlslDocItem(key, content); private GlslDocItem item = new GlslDocItem(key, content);
protected void query(CompletionResultSet completionResultSet, Document document, int i) { protected void query(CompletionResultSet completionResultSet, Document document, int i) {
@ -291,14 +286,14 @@ public class GlslCompletionProvider implements CompletionProvider {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("<code>"); sb.append("<code>");
if(content.type != null) { if (content.type != null) {
sb.append(content.type); sb.append(content.type);
sb.append(" "); sb.append(" ");
} }
sb.append("<b>"); sb.append("<b>");
sb.append(item); sb.append(item);
sb.append("</b>"); sb.append("</b>");
if(content.arguments != null) { if (content.arguments != null) {
sb.append(content.arguments); sb.append(content.arguments);
} }
sb.append("</code><p>"); sb.append("</code><p>");

@ -4,12 +4,9 @@ package net.java.nboglpack.glsleditor;
* Created on 26. March 2007, 00:49 * Created on 26. March 2007, 00:49
* *
*/ */
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
//import net.java.nboglpack.glslcompiler.GLSLCompilerService;
import org.openide.loaders.DataObject; import org.openide.loaders.DataObject;
import org.openide.util.Lookup;
import org.openide.util.RequestProcessor; import org.openide.util.RequestProcessor;
/** /**
@ -28,6 +25,7 @@ public class GlslShaderFileObserver implements DocumentListener {
observedDao = dao; observedDao = dao;
compilerTask = RP.create(new Runnable() { compilerTask = RP.create(new Runnable() {
public void run() { public void run() {
// GLSLCompilerService compiler = Lookup.getDefault().lookup(GLSLCompilerService.class); // GLSLCompilerService compiler = Lookup.getDefault().lookup(GLSLCompilerService.class);
// compiler.compileShader(new DataObject[] {observedDao}, false); // compiler.compileShader(new DataObject[] {observedDao}, false);
@ -36,19 +34,21 @@ public class GlslShaderFileObserver implements DocumentListener {
compilerTask.setPriority(Thread.MIN_PRIORITY); compilerTask.setPriority(Thread.MIN_PRIORITY);
} }
// DocumentListener // DocumentListener
public void insertUpdate(DocumentEvent arg0) { public void insertUpdate(DocumentEvent arg0) {
if(runOnDocUpdate) if (runOnDocUpdate) {
runCompileTask(); runCompileTask();
} }
}
public void removeUpdate(DocumentEvent arg0) { public void removeUpdate(DocumentEvent arg0) {
if(runOnDocUpdate) if (runOnDocUpdate) {
runCompileTask(); runCompileTask();
} }
public void changedUpdate(DocumentEvent arg0) {
} }
public void changedUpdate(DocumentEvent arg0) {
}
public final void runCompileTask() { public final void runCompileTask() {
compilerTask.schedule(compileDelay); compilerTask.schedule(compileDelay);
@ -61,5 +61,4 @@ public class GlslShaderFileObserver implements DocumentListener {
public void setRunOnDocUpdate(boolean runOnDocUpdate) { public void setRunOnDocUpdate(boolean runOnDocUpdate) {
this.runOnDocUpdate = runOnDocUpdate; this.runOnDocUpdate = runOnDocUpdate;
} }
} }

@ -4,7 +4,6 @@
* Created on 12. Februar 2006, 03:37 * Created on 12. Februar 2006, 03:37
* *
*/ */
package net.java.nboglpack.glsleditor; package net.java.nboglpack.glsleditor;
import java.io.InputStream; import java.io.InputStream;
@ -34,31 +33,33 @@ public class GlslVocabularyManager {
private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslVocabularyManager.class.getName()); private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslVocabularyManager.class.getName());
private static final HashMap<String, GlslVocabularyManager> instances = new HashMap<String, GlslVocabularyManager>(); private static final HashMap<String, GlslVocabularyManager> instances = new HashMap<String, GlslVocabularyManager>();
private static GLSLVocabulary vocabulary = null; private static GLSLVocabulary vocabulary = null;
private final String mimetype; private final String mimetype;
private final Set<String> keySet; private final Set<String> keySet;
private final Map<String, GLSLElementDescriptor[]> vocabularyExtention; private final Map<String, GLSLElementDescriptor[]> vocabularyExtention;
/** Creates a new instance of GlslVocabularyManager */ /**
* Creates a new instance of GlslVocabularyManager
*/
private GlslVocabularyManager(String mimetype) { private GlslVocabularyManager(String mimetype) {
if( !mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME) if (!mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)
&& !mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME) && !mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)
&& !mimetype.equals(GlslGeometryShaderDataLoader.REQUIRED_MIME)) { && !mimetype.equals(GlslGeometryShaderDataLoader.REQUIRED_MIME)) {
throw new IllegalArgumentException(mimetype+" is no GLSL mime type"); throw new IllegalArgumentException(mimetype + " is no GLSL mime type");
} }
this.mimetype = mimetype; this.mimetype = mimetype;
if(vocabulary == null) if (vocabulary == null) {
loadVocabulary(); loadVocabulary();
}
if(mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)) { if (mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)) {
vocabularyExtention = vocabulary.fragmentShaderVocabulary; vocabularyExtention = vocabulary.fragmentShaderVocabulary;
}else if(mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)) { } else if (mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)) {
vocabularyExtention = vocabulary.vertexShaderVocabulary; vocabularyExtention = vocabulary.vertexShaderVocabulary;
}else { } else {
vocabularyExtention = vocabulary.geometryShaderVocabulary; vocabularyExtention = vocabulary.geometryShaderVocabulary;
} }
@ -68,9 +69,8 @@ public class GlslVocabularyManager {
private final Set<String> mainSet = vocabulary.mainVocabulary.keySet(); private final Set<String> mainSet = vocabulary.mainVocabulary.keySet();
private final Set<String> extSet = vocabularyExtention.keySet(); private final Set<String> extSet = vocabularyExtention.keySet();
public Iterator<String> iterator() { public Iterator<String> iterator() {
return new Iterator<String>(){ return new Iterator<String>() {
Iterator<String> mainIt = mainSet.iterator(); Iterator<String> mainIt = mainSet.iterator();
Iterator<String> extIt = extSet.iterator(); Iterator<String> extIt = extSet.iterator();
@ -80,23 +80,22 @@ public class GlslVocabularyManager {
} }
public String next() { public String next() {
if(mainIt.hasNext()) if (mainIt.hasNext()) {
return mainIt.next(); return mainIt.next();
else } else {
return extIt.next(); return extIt.next();
} }
}
public void remove() { public void remove() {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
}; };
} }
public int size() { public int size() {
return mainSet.size()+extSet.size(); return mainSet.size() + extSet.size();
} }
}; };
} }
@ -105,9 +104,9 @@ public class GlslVocabularyManager {
GlslVocabularyManager instance = instances.get(mimetype); GlslVocabularyManager instance = instances.get(mimetype);
if(instance == null) { if (instance == null) {
instance = new GlslVocabularyManager(mimetype); instance = new GlslVocabularyManager(mimetype);
instances.put(mimetype,instance); instances.put(mimetype, instance);
} }
return instance; return instance;
@ -115,7 +114,7 @@ public class GlslVocabularyManager {
private void loadVocabulary() { private void loadVocabulary() {
FileObject vocabularyfile = FileUtil.getConfigFile("Editors/"+mimetype+"/vocabulary.xml"); FileObject vocabularyfile = FileUtil.getConfigFile("Editors/" + mimetype + "/vocabulary.xml");
if (vocabularyfile != null) { if (vocabularyfile != null) {
@ -130,7 +129,7 @@ public class GlslVocabularyManager {
JAXBContext jc = JAXBContext.newInstance("net.java.nboglpack.glsleditor.vocabulary", this.getClass().getClassLoader()); JAXBContext jc = JAXBContext.newInstance("net.java.nboglpack.glsleditor.vocabulary", this.getClass().getClassLoader());
Unmarshaller unmarshaller = jc.createUnmarshaller(); Unmarshaller unmarshaller = jc.createUnmarshaller();
vocabulary = (GLSLVocabulary)unmarshaller.unmarshal(is); vocabulary = (GLSLVocabulary) unmarshaller.unmarshal(is);
} catch (Exception ex) { } catch (Exception ex) {
@ -140,7 +139,7 @@ public class GlslVocabularyManager {
} finally { } finally {
if(is != null) { if (is != null) {
try { try {
is.close(); is.close();
} catch (Exception e) { } catch (Exception e) {
@ -162,11 +161,10 @@ public class GlslVocabularyManager {
GLSLElementDescriptor[] desc = vocabulary.mainVocabulary.get(key); GLSLElementDescriptor[] desc = vocabulary.mainVocabulary.get(key);
if(desc == null) if (desc == null) {
desc = vocabularyExtention.get(key); desc = vocabularyExtention.get(key);
}
return desc; return desc;
} }
} }

@ -13,8 +13,6 @@ import org.openide.nodes.Node;
import org.openide.text.CloneableEditorSupport; import org.openide.text.CloneableEditorSupport;
import org.openide.text.DataEditorSupport; import org.openide.text.DataEditorSupport;
public class GlslFragmentShaderDataObject extends MultiDataObject { public class GlslFragmentShaderDataObject extends MultiDataObject {
private final GlslShaderFileObserver observer; private final GlslShaderFileObserver observer;
@ -24,34 +22,38 @@ public class GlslFragmentShaderDataObject extends MultiDataObject {
super(pf, loader); super(pf, loader);
CookieSet cookies = getCookieSet(); CookieSet cookies = getCookieSet();
observer= new GlslShaderFileObserver(this); observer = new GlslShaderFileObserver(this);
final CloneableEditorSupport support= DataEditorSupport.create(this, getPrimaryEntry(), cookies); final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
support.addPropertyChangeListener( support.addPropertyChangeListener(
new PropertyChangeListener(){ new PropertyChangeListenerImpl(support));
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslFragmentShaderDataNode(this);
}
private class PropertyChangeListenerImpl implements PropertyChangeListener {
private final CloneableEditorSupport support;
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
this.support = support;
}
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
if("document".equals(event.getPropertyName())){ if ("document".equals(event.getPropertyName())) {
if(event.getNewValue()!=null) if (event.getNewValue() != null) {
{
support.getDocument().addDocumentListener(observer); support.getDocument().addDocumentListener(observer);
observer.runCompileTask(); observer.runCompileTask();
} } else if (event.getOldValue() != null) {
else if(event.getOldValue()!=null)
{
// cylab: I think this is never called. // cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference... // But I don't know if unregistering the observer makes any difference...
((Document)event.getOldValue()).removeDocumentListener(observer); ((Document) event.getOldValue()).removeDocumentListener(observer);
} }
} }
} }
} }
);
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslFragmentShaderDataNode(this);
}
} }

@ -14,7 +14,6 @@ import org.openide.text.CloneableEditorSupport;
import org.openide.util.Lookup; import org.openide.util.Lookup;
import org.openide.text.DataEditorSupport; import org.openide.text.DataEditorSupport;
/** /**
* @author Michael Bien * @author Michael Bien
*/ */
@ -30,7 +29,27 @@ public class GlslGeometryShaderDataObject extends MultiDataObject {
observer = new GlslShaderFileObserver(this); observer = new GlslShaderFileObserver(this);
final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies); final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
support.addPropertyChangeListener(new PropertyChangeListener() { support.addPropertyChangeListener(new PropertyChangeListenerImpl(support));
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslGeometryShaderDataNode(this, getLookup());
}
@Override
public Lookup getLookup() {
return getCookieSet().getLookup();
}
private class PropertyChangeListenerImpl implements PropertyChangeListener {
private final CloneableEditorSupport support;
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
this.support = support;
}
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
if ("document".equals(event.getPropertyName())) { if ("document".equals(event.getPropertyName())) {
@ -44,17 +63,5 @@ public class GlslGeometryShaderDataObject extends MultiDataObject {
} }
} }
} }
});
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslGeometryShaderDataNode(this, getLookup());
}
@Override
public Lookup getLookup() {
return getCookieSet().getLookup();
} }
} }

@ -1,6 +1,5 @@
package net.java.nboglpack.glsleditor.dataobject; package net.java.nboglpack.glsleditor.dataobject;
import net.java.nboglpack.glsleditor.GlslShaderFileObserver;
import net.java.nboglpack.glsleditor.GlslShaderFileObserver; import net.java.nboglpack.glsleditor.GlslShaderFileObserver;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
@ -22,33 +21,38 @@ public class GlslVertexShaderDataObject extends MultiDataObject {
super(pf, loader); super(pf, loader);
CookieSet cookies = getCookieSet(); CookieSet cookies = getCookieSet();
observer= new GlslShaderFileObserver(this); observer = new GlslShaderFileObserver(this);
final CloneableEditorSupport support= DataEditorSupport.create(this, getPrimaryEntry(), cookies); final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
support.addPropertyChangeListener( support.addPropertyChangeListener(
new PropertyChangeListener(){ new PropertyChangeListenerImpl(support));
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslVertexShaderDataNode(this);
}
private class PropertyChangeListenerImpl implements PropertyChangeListener {
private final CloneableEditorSupport support;
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
this.support = support;
}
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
if("document".equals(event.getPropertyName())){ if ("document".equals(event.getPropertyName())) {
if(event.getNewValue()!=null) if (event.getNewValue() != null) {
{
support.getDocument().addDocumentListener(observer); support.getDocument().addDocumentListener(observer);
observer.runCompileTask(); observer.runCompileTask();
} } else if (event.getOldValue() != null) {
else if(event.getOldValue()!=null)
{
// cylab: I think this is never called. // cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference... // But I don't know if unregistering the observer makes any difference...
((Document)event.getOldValue()).removeDocumentListener(observer); ((Document) event.getOldValue()).removeDocumentListener(observer);
}
}
} }
} }
);
cookies.add((Node.Cookie) support);
} }
@Override
protected Node createNodeDelegate() {
return new GlslVertexShaderDataNode(this);
} }
} }

@ -284,6 +284,7 @@ global_identifier_list = global_declared_identifier [array_index] (<COMMA> globa
global_declared_identifier = <IDENTIFIER>; global_declared_identifier = <IDENTIFIER>;
global_preprocessor = <PREPROCESSOR>; global_preprocessor = <PREPROCESSOR>;
field_declaration = ("in" | "uniform") type_specifier_or_identifier <BUILD_IN_VAR> ;
field_declaration = global_type_qualifier struct_declaration; field_declaration = global_type_qualifier struct_declaration;
field_declaration = global_type_qualifier global_type_declaration [assignment2]; field_declaration = global_type_qualifier global_type_declaration [assignment2];

@ -4,7 +4,6 @@
* Created on 24.09.2007, 00:46:53 * Created on 24.09.2007, 00:46:53
* *
*/ */
package net.java.nboglpack.glsleditor.glsl; package net.java.nboglpack.glsleditor.glsl;
import java.util.HashMap; import java.util.HashMap;
@ -29,10 +28,10 @@ import org.netbeans.api.lexer.TokenUtilities;
public final class Glsl { public final class Glsl {
private final static String KEYWORD_FONT_COLOR = "<font color=808080>"; private final static String KEYWORD_FONT_COLOR = "<font color=808080>";
public final static Map<String, GLSLElementDescriptor> declaredFunctions = new HashMap<String, GLSLElementDescriptor>(); public final static Map<String, GLSLElementDescriptor> declaredFunctions = new HashMap<String, GLSLElementDescriptor>();
private Glsl() {} private Glsl() {
}
/** /**
* Assembles a human readable String containing the declaraton of a function. * Assembles a human readable String containing the declaraton of a function.
@ -40,7 +39,7 @@ public final class Glsl {
*/ */
public static final String createFunctionDeclarationString(SyntaxContext context) { public static final String createFunctionDeclarationString(SyntaxContext context) {
AbstractDocument document = (AbstractDocument)context.getDocument(); AbstractDocument document = (AbstractDocument) context.getDocument();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -55,52 +54,59 @@ public final class Glsl {
sb.append("<html>"); sb.append("<html>");
int moved = 0; int moved = 0;
while(sequence.movePrevious() && isIgnoredToken(sequence.token())) while (sequence.movePrevious() && isIgnoredToken(sequence.token())) {
moved++; moved++;
}
String type = sequence.token().toString(); String type = sequence.token().toString();
while(moved-- >= 0) while (moved-- >= 0) {
sequence.moveNext(); sequence.moveNext();
}
// append function name // append function name
sb.append(sequence.token().text()); sb.append(sequence.token().text());
while(!TokenUtilities.equals(sequence.token().text(), "(")) while (!TokenUtilities.equals(sequence.token().text(), "(")) {
sequence.moveNext(); sequence.moveNext();
}
sb.append("("); sb.append("(");
Token token; Token token;
boolean first = true; boolean first = true;
while(sequence.moveNext() && !TokenUtilities.equals(sequence.token().text(), ")")) { while (sequence.moveNext() && !TokenUtilities.equals(sequence.token().text(), ")")) {
token = sequence.token(); token = sequence.token();
if(!isIgnoredToken(token)) { if (!isIgnoredToken(token)) {
if(first) { if (first) {
sb.append(KEYWORD_FONT_COLOR); sb.append(KEYWORD_FONT_COLOR);
}else if(token.id() != GlslTokenId.COMMA && token.id() != GlslTokenId.BRACKET && token.id() != GlslTokenId.INTEGER_LITERAL) { } else if (token.id() != GlslTokenId.COMMA && token.id() != GlslTokenId.BRACKET && token.id() != GlslTokenId.INTEGER_LITERAL) {
sb.append(" "); sb.append(" ");
} }
if(!TokenUtilities.equals(token.text(), "void")) { if (!TokenUtilities.equals(token.text(), "void")) {
moved = 0; moved = 0;
while(sequence.moveNext() && isIgnoredToken(sequence.token())) while (sequence.moveNext() && isIgnoredToken(sequence.token())) {
moved++; moved++;
}
if(sequence.token().id() == GlslTokenId.COMMA || TokenUtilities.equals(sequence.token().text(), ")")) if (sequence.token().id() == GlslTokenId.COMMA || TokenUtilities.equals(sequence.token().text(), ")")) {
sb.append("</font>"); sb.append("</font>");
}
while(moved-- >= 0) while (moved-- >= 0) {
sequence.movePrevious(); sequence.movePrevious();
}
sb.append(token.text()); sb.append(token.text());
if(token.id() == GlslTokenId.COMMA) if (token.id() == GlslTokenId.COMMA) {
sb.append(KEYWORD_FONT_COLOR); sb.append(KEYWORD_FONT_COLOR);
} }
}
first = false; first = false;
} }
@ -109,7 +115,7 @@ public final class Glsl {
sb.append("</font>)"); sb.append("</font>)");
if(!"void".equals(type)) { if (!"void".equals(type)) {
sb.append(" : "); sb.append(" : ");
sb.append(KEYWORD_FONT_COLOR); sb.append(KEYWORD_FONT_COLOR);
sb.append(type); sb.append(type);
@ -130,7 +136,7 @@ public final class Glsl {
*/ */
public static final String createFieldDeclarationString(SyntaxContext context) { public static final String createFieldDeclarationString(SyntaxContext context) {
AbstractDocument document = (AbstractDocument)context.getDocument(); AbstractDocument document = (AbstractDocument) context.getDocument();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -152,53 +158,55 @@ public final class Glsl {
// read forward // read forward
int moved = 0; int moved = 0;
Token token; Token token;
while( sequence.moveNext() while (sequence.moveNext()
&& sequence.token().id() != GlslTokenId.SEMICOLON && sequence.token().id() != GlslTokenId.SEMICOLON
&& sequence.token().id() != GlslTokenId.COMMA && sequence.token().id() != GlslTokenId.COMMA
&& sequence.token().id() != GlslTokenId.EQ ) { && sequence.token().id() != GlslTokenId.EQ) {
token = sequence.token(); token = sequence.token();
if(!isIgnoredToken(token)) if (!isIgnoredToken(token)) {
sb.append(token); sb.append(token);
}
moved++; moved++;
} }
while(moved-- >= 0) while (moved-- >= 0) {
sequence.movePrevious(); sequence.movePrevious();
}
// read backwards throw the declaration // read backwards throw the declaration
boolean skipToken = false; boolean skipToken = false;
while( sequence.movePrevious() while (sequence.movePrevious()
&& sequence.token().id() != GlslTokenId.SEMICOLON && sequence.token().id() != GlslTokenId.SEMICOLON
&& sequence.token().id() != GlslTokenId.END_OF_LINE ) { && sequence.token().id() != GlslTokenId.END_OF_LINE) {
token = sequence.token(); token = sequence.token();
if(!isIgnoredToken(token)) { if (!isIgnoredToken(token)) {
// we have a struct declaration; skip everything between { } // we have a struct declaration; skip everything between { }
if(token.id() == GlslTokenId.BRACE && TokenUtilities.equals(token.text(), "}")) { if (token.id() == GlslTokenId.BRACE && TokenUtilities.equals(token.text(), "}")) {
movePreviousUntil(sequence, GlslTokenId.BRACE, "}", "{"); movePreviousUntil(sequence, GlslTokenId.BRACE, "}", "{");
continue; continue;
} }
// skip token in case of an comma seperated identifier list // skip token in case of an comma seperated identifier list
if(skipToken) { if (skipToken) {
if( token.id() == GlslTokenId.BRACKET if (token.id() == GlslTokenId.BRACKET
&& TokenUtilities.equals(token.text(), "]") ) { && TokenUtilities.equals(token.text(), "]")) {
movePreviousUntil(sequence, GlslTokenId.BRACKET, "]", "["); movePreviousUntil(sequence, GlslTokenId.BRACKET, "]", "[");
skipToken = false; skipToken = false;
}else { } else {
skipToken = false; skipToken = false;
} }
continue; continue;
} }
if(token.id() == GlslTokenId.COMMA) { if (token.id() == GlslTokenId.COMMA) {
skipToken = true; skipToken = true;
continue; continue;
} }
if(!TokenUtilities.equals(token.text(), "struct")) { if (!TokenUtilities.equals(token.text(), "struct")) {
sb.insert(insertIndex, token.text()); sb.insert(insertIndex, token.text());
sb.insert(insertIndex, " "); sb.insert(insertIndex, " ");
} }
@ -215,27 +223,31 @@ public final class Glsl {
return sb.toString(); return sb.toString();
} }
public static final String createPreprocessorString(SyntaxContext context) { public static final String createPreprocessorString(SyntaxContext context) {
ASTNode node = (ASTNode)context.getASTPath().getLeaf(); ASTNode node = (ASTNode) context.getASTPath().getLeaf();
List<ASTItem> children = node.getChildren(); List<ASTItem> children = node.getChildren();
String str = null; String str = null;
for (ASTItem item : children) for (ASTItem item : children) {
if (isTokenType(item, GlslTokenId.PREPROCESSOR.name())) if (isTokenType(item, GlslTokenId.PREPROCESSOR.name())) {
str = ((ASTToken)item).getIdentifier(); str = ((ASTToken) item).getIdentifier();
}
}
for(int i = 0; i < str.length(); i++) { for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i); char c = str.charAt(i);
if(c != '#' && !Character.isWhitespace(c)) if (c != '#' && !Character.isWhitespace(c)) {
for(int j = str.length()-1; j > i; j--) for (int j = str.length() - 1; j > i; j--) {
if(!Character.isWhitespace(str.charAt(j))) if (!Character.isWhitespace(str.charAt(j))) {
return str.substring(i, j+1); return str.substring(i, j + 1);
}
}
}
} }
@ -243,16 +255,16 @@ public final class Glsl {
} }
/** /**
* called from withen GLSL_*.nbs each time the document has been modified. * Called from withen GLSL_*.nbs each time the document has been modified.
*/ */
public static void process(SyntaxContext context) { public static void process(SyntaxContext context) {
AbstractDocument document = (AbstractDocument)context.getDocument(); AbstractDocument document = (AbstractDocument) context.getDocument();
try{ try {
document.readLock(); document.readLock();
// remember all declared funktions for auto completion // remember all declared functions for auto-completion
synchronized(declaredFunctions) { synchronized (declaredFunctions) {
declaredFunctions.clear(); declaredFunctions.clear();
} }
@ -262,28 +274,29 @@ public final class Glsl {
for (ASTItem declarationItem : declaration.getChildren()) { for (ASTItem declarationItem : declaration.getChildren()) {
if(isNode(declarationItem, "function")) { if (isNode(declarationItem, "function")) {
List<ASTItem> functionItems = declarationItem.getChildren(); List<ASTItem> functionItems = declarationItem.getChildren();
if(functionItems.size() < 3) if (functionItems.size() < 3) {
break; break;
}
ASTItem nameToken = functionItems.get(0); ASTItem nameToken = functionItems.get(0);
if(isTokenType(nameToken, GlslTokenId.FUNCTION.name())) { if (isTokenType(nameToken, GlslTokenId.FUNCTION.name())) {
// determine return type // determine return type
StringBuilder returnType = new StringBuilder(); StringBuilder returnType = new StringBuilder();
for (ASTItem typeItem : declaration.getChildren()) { for (ASTItem typeItem : declaration.getChildren()) {
if(isNode(typeItem, "function")) if (isNode(typeItem, "function")) {
break; break;
}
if(typeItem instanceof ASTNode) { if (typeItem instanceof ASTNode) {
returnType.append(((ASTNode)typeItem).getAsText().trim()); returnType.append(((ASTNode) typeItem).getAsText().trim());
}else if(typeItem instanceof ASTToken) { } else if (typeItem instanceof ASTToken) {
final ASTToken t = (ASTToken) typeItem; final ASTToken t = (ASTToken) typeItem;
returnType.append(t.getIdentifier().trim()); returnType.append(t.getIdentifier().trim());
} }
@ -295,8 +308,9 @@ public final class Glsl {
name.append("("); name.append("(");
ASTItem parameterList = functionItems.get(2); ASTItem parameterList = functionItems.get(2);
if(isNode(parameterList, "parameter_declaration_list")) if (isNode(parameterList, "parameter_declaration_list")) {
name.append(((ASTNode)parameterList).getAsText()); name.append(((ASTNode) parameterList).getAsText());
}
name.append(")"); name.append(")");
GLSLElementDescriptor elementDesc = new GLSLElementDescriptor( GLSLElementDescriptor elementDesc = new GLSLElementDescriptor(
@ -308,7 +322,7 @@ public final class Glsl {
name.insert(0, ((ASTToken) nameToken).getIdentifier()); name.insert(0, ((ASTToken) nameToken).getIdentifier());
synchronized(declaredFunctions) { synchronized (declaredFunctions) {
declaredFunctions.put(name.toString(), elementDesc); declaredFunctions.put(name.toString(), elementDesc);
} }
@ -319,43 +333,41 @@ public final class Glsl {
} }
} }
} }
}finally{ } finally {
document.readUnlock(); document.readUnlock();
} }
} }
private static final void movePreviousUntil(TokenSequence sequence, GlslTokenId id, String countToken, String stopToken) { private static void movePreviousUntil(TokenSequence sequence, GlslTokenId id, String countToken, String stopToken) {
int counter = 1; int counter = 1;
while(sequence.movePrevious() && counter > 0) { while (sequence.movePrevious() && counter > 0) {
if(sequence.token().id() == id) { if (sequence.token().id() == id) {
if(TokenUtilities.equals(sequence.token().text(), stopToken)) { if (TokenUtilities.equals(sequence.token().text(), stopToken)) {
counter--; counter--;
}else if(TokenUtilities.equals(sequence.token().text(), countToken)){ } else if (TokenUtilities.equals(sequence.token().text(), countToken)) {
counter++; counter++;
} }
} }
} }
} }
private static final boolean isIgnoredToken(Token token) { private static boolean isIgnoredToken(Token token) {
return token.id() == GlslTokenId.WHITESPACE return token.id() == GlslTokenId.WHITESPACE
|| token.id() == GlslTokenId.COMMENT || token.id() == GlslTokenId.COMMENT
|| token.id() == GlslTokenId.PREPROCESSOR; || token.id() == GlslTokenId.PREPROCESSOR;
} }
private static final boolean isNode(ASTItem item, String nodeToken) { private static boolean isNode(ASTItem item, String nodeToken) {
return item != null && item instanceof ASTNode && ((ASTNode)item).getNT().equals(nodeToken); return item != null && item instanceof ASTNode && ((ASTNode) item).getNT().equals(nodeToken);
} }
private static final boolean isToken(ASTItem item, String id) { private static boolean isToken(ASTItem item, String id) {
return item != null && item instanceof ASTToken && ((ASTToken)item).getIdentifier().equals(id); return item != null && item instanceof ASTToken && ((ASTToken) item).getIdentifier().equals(id);
} }
private static final boolean isTokenType(ASTItem item, String type) { private static boolean isTokenType(ASTItem item, String type) {
return item != null && item instanceof ASTToken && ((ASTToken) item).getTypeName().equals(type); return item != null && item instanceof ASTToken && ((ASTToken) item).getTypeName().equals(type);
} }
} }

@ -4,7 +4,6 @@
* Created on 19.08.2007, 18:25:24 * Created on 19.08.2007, 18:25:24
* *
*/ */
package net.java.nboglpack.glsleditor.lexer; package net.java.nboglpack.glsleditor.lexer;
import java.util.Collection; import java.util.Collection;
@ -27,7 +26,6 @@ public class Glsl extends LanguageHierarchy<GlslTokenId> {
public static final Glsl VERTEX_LANGUAGE = new Glsl(GlslVertexShaderDataLoader.REQUIRED_MIME); public static final Glsl VERTEX_LANGUAGE = new Glsl(GlslVertexShaderDataLoader.REQUIRED_MIME);
public static final Glsl GEOMETRY_LANGUAGE = new Glsl(GlslGeometryShaderDataLoader.REQUIRED_MIME); public static final Glsl GEOMETRY_LANGUAGE = new Glsl(GlslGeometryShaderDataLoader.REQUIRED_MIME);
public static final Glsl FRAGMENT_LANGUAGE = new Glsl(GlslFragmentShaderDataLoader.REQUIRED_MIME); public static final Glsl FRAGMENT_LANGUAGE = new Glsl(GlslFragmentShaderDataLoader.REQUIRED_MIME);
private final String mimeType; private final String mimeType;
private Glsl(String mimeType) { private Glsl(String mimeType) {
@ -49,13 +47,15 @@ public class Glsl extends LanguageHierarchy<GlslTokenId> {
return new GlslLexer(info, GlslVocabularyManager.getInstance(mimeType())); return new GlslLexer(info, GlslVocabularyManager.getInstance(mimeType()));
} }
public static Language<GlslTokenId> vertexLanguage(){ public static Language<GlslTokenId> vertexLanguage() {
return VERTEX_LANGUAGE.language(); return VERTEX_LANGUAGE.language();
} }
public static Language<GlslTokenId> fragmentLanguage(){
public static Language<GlslTokenId> fragmentLanguage() {
return FRAGMENT_LANGUAGE.language(); return FRAGMENT_LANGUAGE.language();
} }
public static Language<GlslTokenId> geometryLanguage(){
public static Language<GlslTokenId> geometryLanguage() {
return GEOMETRY_LANGUAGE.language(); return GEOMETRY_LANGUAGE.language();
} }
} }

@ -4,7 +4,6 @@
* Created on 19.08.2007, 18:31:16 * Created on 19.08.2007, 18:31:16
* *
*/ */
package net.java.nboglpack.glsleditor.lexer; package net.java.nboglpack.glsleditor.lexer;
import net.java.nboglpack.glsleditor.GlslVocabularyManager; import net.java.nboglpack.glsleditor.GlslVocabularyManager;
@ -15,7 +14,6 @@ import org.netbeans.spi.lexer.LexerInput;
import org.netbeans.spi.lexer.LexerRestartInfo; import org.netbeans.spi.lexer.LexerRestartInfo;
import org.netbeans.spi.lexer.TokenFactory; import org.netbeans.spi.lexer.TokenFactory;
/** /**
* Lexer for the OpenGL Shading Language. * Lexer for the OpenGL Shading Language.
* @author Michael Bien * @author Michael Bien
@ -27,7 +25,6 @@ public class GlslLexer implements Lexer<GlslTokenId> {
private final GlslVocabularyManager manager; private final GlslVocabularyManager manager;
private final StringBuilder stringBuilder; private final StringBuilder stringBuilder;
public GlslLexer(LexerRestartInfo<GlslTokenId> info, GlslVocabularyManager manager) { public GlslLexer(LexerRestartInfo<GlslTokenId> info, GlslVocabularyManager manager) {
this.input = info.input(); this.input = info.input();
this.factory = info.tokenFactory(); this.factory = info.tokenFactory();
@ -39,9 +36,7 @@ public class GlslLexer implements Lexer<GlslTokenId> {
public Token<GlslTokenId> nextToken() { public Token<GlslTokenId> nextToken() {
int character = input.read(); int character = input.read();
switch (character) {
switch(character) {
case '(': case '(':
case ')': case ')':
return factory.createToken(GlslTokenId.PAREN); return factory.createToken(GlslTokenId.PAREN);
@ -64,76 +59,76 @@ public class GlslLexer implements Lexer<GlslTokenId> {
case '~': case '~':
return factory.createToken(GlslTokenId.TILDE); return factory.createToken(GlslTokenId.TILDE);
case '*': case '*':
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.MUL_ASSIGN); return factory.createToken(GlslTokenId.MUL_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.STAR); return factory.createToken(GlslTokenId.STAR);
} }
case '%': case '%':
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.MOD_ASSIGN); return factory.createToken(GlslTokenId.MOD_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.PERCENT); return factory.createToken(GlslTokenId.PERCENT);
} }
case '!': case '!':
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.NE); return factory.createToken(GlslTokenId.NE);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.BANG); return factory.createToken(GlslTokenId.BANG);
} }
case '=': case '=':
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.EQEQ); return factory.createToken(GlslTokenId.EQEQ);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.EQ); return factory.createToken(GlslTokenId.EQ);
} }
case '^': case '^':
switch(input.read()) { switch (input.read()) {
case('^'): case ('^'):
return factory.createToken(GlslTokenId.CARETCARET); return factory.createToken(GlslTokenId.CARETCARET);
case('='): case ('='):
return factory.createToken(GlslTokenId.XOR_ASSIGN); return factory.createToken(GlslTokenId.XOR_ASSIGN);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.CARET); return factory.createToken(GlslTokenId.CARET);
} }
case '+': case '+':
switch(input.read()) { switch (input.read()) {
case('+'): case ('+'):
return factory.createToken(GlslTokenId.PLUSPLUS); return factory.createToken(GlslTokenId.PLUSPLUS);
case('='): case ('='):
return factory.createToken(GlslTokenId.ADD_ASSIGN); return factory.createToken(GlslTokenId.ADD_ASSIGN);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.PLUS); return factory.createToken(GlslTokenId.PLUS);
} }
case '-': case '-':
switch(input.read()) { switch (input.read()) {
case('-'): case ('-'):
return factory.createToken(GlslTokenId.MINUSMINUS); return factory.createToken(GlslTokenId.MINUSMINUS);
case('='): case ('='):
return factory.createToken(GlslTokenId.SUB_ASSIGN); return factory.createToken(GlslTokenId.SUB_ASSIGN);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.MINUS); return factory.createToken(GlslTokenId.MINUS);
} }
case '&': case '&':
switch(input.read()) { switch (input.read()) {
case('&'): case ('&'):
return factory.createToken(GlslTokenId.AMPAMP); return factory.createToken(GlslTokenId.AMPAMP);
case('='): case ('='):
return factory.createToken(GlslTokenId.AND_ASSIGN); return factory.createToken(GlslTokenId.AND_ASSIGN);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.AMP); return factory.createToken(GlslTokenId.AMP);
} }
case '|': case '|':
switch(input.read()) { switch (input.read()) {
case('|'): case ('|'):
return factory.createToken(GlslTokenId.BARBAR); return factory.createToken(GlslTokenId.BARBAR);
case ('='): case ('='):
return factory.createToken(GlslTokenId.OR_ASSIGN); return factory.createToken(GlslTokenId.OR_ASSIGN);
@ -142,30 +137,30 @@ public class GlslLexer implements Lexer<GlslTokenId> {
return factory.createToken(GlslTokenId.BAR); return factory.createToken(GlslTokenId.BAR);
} }
case '<': case '<':
switch(input.read()) { switch (input.read()) {
case('<'): case ('<'):
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.LEFT_BITSHIFT_ASSIGN); return factory.createToken(GlslTokenId.LEFT_BITSHIFT_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.LEFT_BITSHIFT); return factory.createToken(GlslTokenId.LEFT_BITSHIFT);
} }
case('='): case ('='):
return factory.createToken(GlslTokenId.LE); return factory.createToken(GlslTokenId.LE);
default: default:
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.LEFT_ANGLE); return factory.createToken(GlslTokenId.LEFT_ANGLE);
} }
case '>': case '>':
switch(input.read()) { switch (input.read()) {
case('>'): case ('>'):
if(input.read() == '=') { if (input.read() == '=') {
return factory.createToken(GlslTokenId.RIGHT_BITSHIFT_ASSIGN); return factory.createToken(GlslTokenId.RIGHT_BITSHIFT_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.RIGHT_BITSHIFT); return factory.createToken(GlslTokenId.RIGHT_BITSHIFT);
} }
case('='): case ('='):
return factory.createToken(GlslTokenId.GE); return factory.createToken(GlslTokenId.GE);
default: default:
input.backup(1); input.backup(1);
@ -173,14 +168,14 @@ public class GlslLexer implements Lexer<GlslTokenId> {
} }
case '/': case '/':
int c = input.read(); int c = input.read();
if(c == '/') { if (c == '/') {
readRemainingLine(); readRemainingLine();
return factory.createToken(GlslTokenId.COMMENT); return factory.createToken(GlslTokenId.COMMENT);
}else if(c == '*') { } else if (c == '*') {
return tokenizeMLComment(); return tokenizeMLComment();
}else if(c == '=') { } else if (c == '=') {
return factory.createToken(GlslTokenId.DIV_ASSIGN); return factory.createToken(GlslTokenId.DIV_ASSIGN);
}else{ } else {
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.SLASH); return factory.createToken(GlslTokenId.SLASH);
} }
@ -189,24 +184,25 @@ public class GlslLexer implements Lexer<GlslTokenId> {
return factory.createToken(GlslTokenId.PREPROCESSOR); return factory.createToken(GlslTokenId.PREPROCESSOR);
case ' ': case ' ':
case '\t': case '\t':
do{ do {
character = input.read(); character = input.read();
}while(character == ' ' || character == '\t'); } while (character == ' ' || character == '\t');
input.backup(1); input.backup(1);
return factory.createToken(GlslTokenId.WHITESPACE); return factory.createToken(GlslTokenId.WHITESPACE);
case '\r': case '\r':
input.consumeNewline(); input.consumeNewline();
case LexerInput.EOF: case LexerInput.EOF:
if(input.readLength() == 0) if (input.readLength() == 0) {
return null; return null;
}
case '\n': case '\n':
return factory.createToken(GlslTokenId.END_OF_LINE); return factory.createToken(GlslTokenId.END_OF_LINE);
default: default:
if(Character.isDigit(character)) { if (Character.isDigit(character)) {
return tokenizeNumber(); return tokenizeNumber();
}else if(Character.isUnicodeIdentifierStart(character)) { } else if (Character.isUnicodeIdentifierStart(character)) {
return tokenizeName(); return tokenizeName();
}else{ } else {
return factory.createToken(GlslTokenId.error); return factory.createToken(GlslTokenId.error);
} }
} }
@ -214,11 +210,11 @@ public class GlslLexer implements Lexer<GlslTokenId> {
} }
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
private final void readRemainingLine() { private void readRemainingLine() {
int character = input.read(); int character = input.read();
while(character != LexerInput.EOF) { while (character != LexerInput.EOF) {
switch (character) { switch (character) {
case '\r': case '\r':
input.consumeNewline(); input.consumeNewline();
@ -231,12 +227,12 @@ public class GlslLexer implements Lexer<GlslTokenId> {
} }
private final Token<GlslTokenId> tokenizeMLComment() { private Token<GlslTokenId> tokenizeMLComment() {
int character = input.read(); int character = input.read();
while(character != LexerInput.EOF) { while (character != LexerInput.EOF) {
if(character == '*' && input.read() == '/') { if (character == '*' && input.read() == '/') {
return factory.createToken(GlslTokenId.ML_COMMENT); return factory.createToken(GlslTokenId.ML_COMMENT);
} }
character = input.read(); character = input.read();
@ -245,67 +241,68 @@ public class GlslLexer implements Lexer<GlslTokenId> {
} }
private final Token<GlslTokenId> tokenizeNumber() { private Token<GlslTokenId> tokenizeNumber() {
int character; int character;
do{ do {
character = input.read(); character = input.read();
}while(Character.isDigit(character)); } while (Character.isDigit(character));
if(character == '.') { if (character == '.') {
do{ do {
character = input.read(); character = input.read();
}while(Character.isDigit(character)); } while (Character.isDigit(character));
if(character != 'f' && character != 'F') if (character != 'f' && character != 'F') {
input.backup(1); input.backup(1);
}
return factory.createToken(GlslTokenId.FLOAT_LITERAL); return factory.createToken(GlslTokenId.FLOAT_LITERAL);
}else{ } else {
if(character != 'u' && character != 'U') if (character != 'u' && character != 'U') {
input.backup(1); input.backup(1);
}
// input.backup(1);
return factory.createToken(GlslTokenId.INTEGER_LITERAL); return factory.createToken(GlslTokenId.INTEGER_LITERAL);
} }
} }
private final Token<GlslTokenId> tokenizeName() { private Token<GlslTokenId> tokenizeName() {
if(stringBuilder.length() > 0) if (stringBuilder.length() > 0) {
stringBuilder.delete(0, stringBuilder.length()); stringBuilder.delete(0, stringBuilder.length());
}
// backup everything read // backup everything read
input.backup(input.readLength()); input.backup(input.readLength());
// assamble token // assamble token
char c; char c;
while(Character.isUnicodeIdentifierPart(c = ((char)input.read()))) while (Character.isUnicodeIdentifierPart(c = ((char) input.read()))) {
stringBuilder.append(c); stringBuilder.append(c);
}
if(stringBuilder.length() > 0) if (stringBuilder.length() > 0) {
input.backup(1); input.backup(1);
}
// categorise token // categorise token
GLSLElementDescriptor[] desc = manager.getDesc(stringBuilder.toString()); GLSLElementDescriptor[] desc = manager.getDesc(stringBuilder.toString());
if(desc != null) { if (desc != null) {
if (desc[0].category != null) {
if(desc[0].category != null) { if (desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_FUNC) {
if(desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_FUNC)
return factory.createToken(GlslTokenId.BUILD_IN_FUNC); return factory.createToken(GlslTokenId.BUILD_IN_FUNC);
}
if(desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_VAR) if (desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_VAR) {
return factory.createToken(GlslTokenId.BUILD_IN_VAR); return factory.createToken(GlslTokenId.BUILD_IN_VAR);
}
return factory.createToken(GlslTokenId.KEYWORD); return factory.createToken(GlslTokenId.KEYWORD);
} }
} }
@ -313,7 +310,7 @@ public class GlslLexer implements Lexer<GlslTokenId> {
int tokenEnd = input.readLength(); int tokenEnd = input.readLength();
int character = input.read(); int character = input.read();
while(true) { while (true) {
switch (character) { switch (character) {
case ' ': case ' ':
case '\t': case '\t':
@ -322,10 +319,10 @@ public class GlslLexer implements Lexer<GlslTokenId> {
character = input.read(); character = input.read();
break; break;
case '(': case '(':
input.backup(input.readLength()-tokenEnd); input.backup(input.readLength() - tokenEnd);
return factory.createToken(GlslTokenId.FUNCTION); return factory.createToken(GlslTokenId.FUNCTION);
default: default:
input.backup(input.readLength()-tokenEnd); input.backup(input.readLength() - tokenEnd);
return factory.createToken(GlslTokenId.IDENTIFIER); return factory.createToken(GlslTokenId.IDENTIFIER);
} }
} }
@ -339,5 +336,4 @@ public class GlslLexer implements Lexer<GlslTokenId> {
public void release() { public void release() {
} }
} }

@ -15,7 +15,6 @@ import org.netbeans.api.lexer.TokenId;
*/ */
public enum GlslTokenId implements TokenId { public enum GlslTokenId implements TokenId {
IDENTIFIER("glsl-name"), IDENTIFIER("glsl-name"),
INTEGER_LITERAL("glsl-literal"), INTEGER_LITERAL("glsl-literal"),
FLOAT_LITERAL("glsl-literal"), FLOAT_LITERAL("glsl-literal"),

@ -18,7 +18,9 @@ public class GLSLElementDescriptor {
@XmlType @XmlType
@XmlEnum(String.class) @XmlEnum(String.class)
public enum Category { BUILD_IN_FUNC, BUILD_IN_VAR, USER_FUNC, JUMP, ITERATION, SELECTION, QUALIFIER, TYPE, KEYWORD } public enum Category {
BUILD_IN_FUNC, BUILD_IN_VAR, USER_FUNC, JUMP, ITERATION, SELECTION, QUALIFIER, TYPE, KEYWORD
}
@XmlElement @XmlElement
public final Category category; public final Category category;
@ -35,7 +37,9 @@ public class GLSLElementDescriptor {
@XmlElement(required = true) @XmlElement(required = true)
public final String type; public final String type;
/*bean constructor, fields are directly injected*/ /**
* Bean constructor, fields are directly injected.
*/
public GLSLElementDescriptor() { public GLSLElementDescriptor() {
category = Category.KEYWORD; category = Category.KEYWORD;
tooltip = null; tooltip = null;
@ -51,6 +55,4 @@ public class GLSLElementDescriptor {
this.arguments = arguments; this.arguments = arguments;
this.type = type; this.type = type;
} }
} }

@ -21,13 +21,10 @@ public class GLSLVocabulary {
public final HashMap<String, GLSLElementDescriptor[]> vertexShaderVocabulary; public final HashMap<String, GLSLElementDescriptor[]> vertexShaderVocabulary;
public final HashMap<String, GLSLElementDescriptor[]> geometryShaderVocabulary; public final HashMap<String, GLSLElementDescriptor[]> geometryShaderVocabulary;
public GLSLVocabulary() { public GLSLVocabulary() {
mainVocabulary = new HashMap<String, GLSLElementDescriptor[]>(); mainVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
vertexShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>(); vertexShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
fragmentShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>(); fragmentShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
geometryShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>(); geometryShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
} }
} }

Loading…
Cancel
Save