Add com.wudsn.ide.pas to sharing.

This commit is contained in:
peterdell 2019-09-02 23:34:50 +02:00
parent 038943c9eb
commit f2f1e5a598
13 changed files with 604 additions and 0 deletions

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
com.wudsn.ide.pas/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/bin/

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.wudsn.ide.pas</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,15 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: WUDSN IDE Pascal Plug-in
Bundle-SymbolicName: com.wudsn.ide.pas;singleton:=true
Bundle-Version: 1.7.1.qualifier
Bundle-Activator: com.wudsn.ide.pas.Activator
Bundle-Vendor: Peter Dell
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.jface.text,
org.eclipse.ui,
org.eclipse.ui.editors
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: com.wudsn.ide.pas

View File

@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions="pas"
base-type="org.eclipse.core.runtime.text"
name="%com.wudsn.ide.pas.compiler.PascalSourceFile.name"
id="com.wudsn.ide.pas.compiler.PascalSourceFile">
</content-type>
</extension>
<extension
point="org.eclipse.ui.editors">
<editorContentTypeBinding
contentTypeId="com.wudsn.ide.pas.compiler.PascalSourceFile"
editorId="org.eclipse.ui.genericeditor.GenericEditor">
</editorContentTypeBinding>
</extension>
<extension
point="org.eclipse.ui.genericeditor.presentationReconcilers">
<presentationReconciler
class="com.wudsn.ide.pas.editor.PascalReconciler"
contentType="com.wudsn.ide.pas.compiler.PascalSourceFile">
</presentationReconciler>
</extension>
<extension
point="org.eclipse.ui.genericeditor.hoverProviders">
<hoverProvider
class="com.wudsn.ide.pas.editor.PascalHoverProvider"
contentType="com.wudsn.ide.pas.compiler.PascalSourceFile">
</hoverProvider>
</extension>
<extension
point="org.eclipse.ui.genericeditor.contentAssistProcessors">
<contentAssistProcessor
class="com.wudsn.ide.pas.editor.PascalContentAssistProcessor"
contentType="com.wudsn.ide.pas.compiler.PascalSourceFile">
</contentAssistProcessor>
</extension>
<extension
point="org.eclipse.core.filebuffers.documentSetup">
<participant
contentTypeId="com.wudsn.ide.pas.compiler.PascalSourceFile"
extensions="pas"
class="com.wudsn.ide.pas.editor.ValidatorDocumentSetupParticipant">
</participant>
</extension>
</plugin>

View File

@ -0,0 +1,76 @@
/**
* Copyright (C) 2009 - 2019 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* This file is part of WUDSN IDE.
*
* WUDSN IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* WUDSN IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wudsn.ide.pas;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*
* @since 1.7.1
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "com.wudsn.ide.pas"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.
* BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.
* BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}

View File

@ -0,0 +1,92 @@
/**
* Copyright (C) 2009 - 2019 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* This file is part of WUDSN IDE.
*
* WUDSN IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* WUDSN IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wudsn.ide.pas.editor;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNatureDescriptor;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
/**
*
* @author Peter Dell
* @since 1.7.1
*/
public class PascalContentAssistProcessor implements IContentAssistProcessor {
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
// TODO this is logic for .project file to complete on nature and project references. Replace with your language logic!
String text = viewer.getDocument().get();
String natureTag= "<nature>";
String projectReferenceTag="<project>";
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if (text.length() >= natureTag.length() && text.substring(offset - natureTag.length(), offset).equals(natureTag)) {
IProjectNatureDescriptor[] natureDescriptors= workspace.getNatureDescriptors();
ICompletionProposal[] proposals = new ICompletionProposal[natureDescriptors.length];
for (int i= 0; i < natureDescriptors.length; i++) {
IProjectNatureDescriptor descriptor= natureDescriptors[i];
proposals[i] = new CompletionProposal(descriptor.getNatureId(), offset, 0, descriptor.getNatureId().length());
}
return proposals;
}
if (text.length() >= projectReferenceTag.length() && text.substring(offset - projectReferenceTag.length(), offset).equals(projectReferenceTag)) {
IProject[] projects= workspace.getRoot().getProjects();
ICompletionProposal[] proposals = new ICompletionProposal[projects.length];
for (int i= 0; i < projects.length; i++) {
proposals[i]=new CompletionProposal(projects[i].getName(), offset, 0, projects[i].getName().length());
}
return proposals;
}
return new ICompletionProposal[0];
}
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
}
@Override
public char[] getCompletionProposalAutoActivationCharacters() {
return new char[] { '"' }; //NON-NLS-1
}
@Override
public char[] getContextInformationAutoActivationCharacters() {
return null;
}
@Override
public String getErrorMessage() {
return null;
}
@Override
public IContextInformationValidator getContextInformationValidator() {
return null;
}
}

View File

@ -0,0 +1,60 @@
/**
* Copyright (C) 2009 - 2019 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* This file is part of WUDSN IDE.
*
* WUDSN IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* WUDSN IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wudsn.ide.pas.editor;
//import org.eclipse.core.resources.IProjectNatureDescriptor;
//import org.eclipse.core.resources.IWorkspace;
//import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
/**
*
* @author Peter Dell
* @since 1.7.1
*/
public class PascalHoverProvider implements ITextHover {
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
// TODO this is logic for .project file to show nature description on hover. Replace with your language logic!
// String contents= textViewer.getDocument().get();
// int offset= hoverRegion.getOffset();
// int endIndex= contents.indexOf("</nature>", offset);
// if (endIndex==-1) return "";
// int startIndex= contents.substring(0, offset).lastIndexOf("<nature>");
// if (startIndex==-1) return "";
// String selection = contents.substring(startIndex+"<nature>".length(), endIndex);
//
// IWorkspace workspace = ResourcesPlugin.getWorkspace();
// IProjectNatureDescriptor[] natureDescriptors= workspace.getNatureDescriptors();
// for (int i= 0; i < natureDescriptors.length; i++) {
// if (natureDescriptors[i].getNatureId().equals(selection))
// return natureDescriptors[i].getLabel();
// }
return "";
}
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
return new Region(offset, 0);
}
}

View File

@ -0,0 +1,69 @@
/**
* Copyright (C) 2009 - 2019 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* This file is part of WUDSN IDE.
*
* WUDSN IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* WUDSN IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wudsn.ide.pas.editor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.NumberRule;
import org.eclipse.jface.text.rules.PatternRule;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
/**
*
* @author Peter Dell
* @since 1.7.1
*/
public class PascalReconciler extends PresentationReconciler {
private IToken quoteToken = new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(139, 69, 19))));
private IToken numberToken = new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 0, 255))));
private IToken commentToken = new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 100, 0))));
private IToken keywordToken = new Token(
new TextAttribute(new Color(Display.getCurrent(), new RGB(150, 0, 85)), null, SWT.BOLD));
public PascalReconciler() {
RuleBasedScanner scanner = new RuleBasedScanner();
List<IRule> rules = new ArrayList<IRule>();
rules.add(new SingleLineRule("'", "'", quoteToken));
rules.add(new PatternRule("//", null, commentToken, (char) 0, true));
rules.add(new NumberRule(numberToken));
rules.add(new PascalWordRule(keywordToken));
scanner.setRules(rules.toArray(new IRule[rules.size()]));
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
}
}

View File

@ -0,0 +1,38 @@
/**
* Copyright (C) 2009 - 2019 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* This file is part of WUDSN IDE.
*
* WUDSN IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* WUDSN IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wudsn.ide.pas.editor;
import org.eclipse.jface.text.rules.IWordDetector;
/**
*
* @author Peter Dell
* @since 1.7.1
*/
class PascalWordDetector implements IWordDetector {
@Override
public boolean isWordStart(char c) {
return Character.isLetter(c);
}
@Override
public boolean isWordPart(char c) {
return Character.isLetter(c) || Character.isDigit(c) || (c == '_');
}
}

View File

@ -0,0 +1,46 @@
/**
* Copyright (C) 2009 - 2019 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* This file is part of WUDSN IDE.
*
* WUDSN IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* WUDSN IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wudsn.ide.pas.editor;
import java.util.StringTokenizer;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WordRule;
/**
*
* @author Peter Dell
* @since 1.7.1
*/
public class PascalWordRule extends WordRule {
public PascalWordRule(IToken token) {
super(new PascalWordDetector(), new Token(""), true);
// From C:\jac\system\Atari800\Tools\PAS\MP\geany\data\filedefs\filetypes.pascal
String words = "absolute abstract add and array as asm assembler automated begin boolean break byte cardinal case cdecl char class const constructor contains default deprecated destructor dispid dispinterface div do downto dynamic dword else end except export exports external far file final finalization finally for forward function goto if implementation implements in index inherited initialization inline integer interface is label library longword longint message mod name near nil nodefault not object of on or out overload override package packed pascal platform private procedure program property protected public published raise read readonly real record register reintroduce remove repeat requires resourcestring safecall sealed set shl shortint smallint shr static stdcall stored strict string then threadvar to try tstring type uint32 unit unsafe until uses var varargs virtual while with word write writeonly xor";
StringTokenizer st = new StringTokenizer(words, " ");
while (st.hasMoreTokens()) {
addWord(st.nextToken(), token);
}
}
}

View File

@ -0,0 +1,116 @@
/**
* Copyright (C) 2009 - 2019 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* This file is part of WUDSN IDE.
*
* WUDSN IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* WUDSN IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wudsn.ide.pas.editor;
//import java.io.StringReader;
//
//import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.DocumentBuilderFactory;
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
//import org.xml.sax.InputSource;
//import org.xml.sax.SAXParseException;
/**
*
* @author Peter Dell
* @since 1.7.1
*/
public class ValidatorDocumentSetupParticipant
implements IDocumentSetupParticipant, IDocumentSetupParticipantExtension {
private final class DocumentValidator implements IDocumentListener {
private final IFile file;
private IMarker marker;
DocumentValidator(IFile file) {
this.file = file;
}
@Override
public void documentChanged(DocumentEvent event) {
if (this.marker != null) {
try {
this.marker.delete();
} catch (CoreException e) {
e.printStackTrace();
}
this.marker = null;
}
// try {
// String document=event.getDocument().get();
// if (document.length()==0) {
// document = "EMPTY";
// }
// // StringReader reader = new
// StringReader(event.getDocument().get());) {
// // DocumentBuilder documentBuilder =
// // DocumentBuilderFactory.newInstance().newDocumentBuilder();
// // documentBuilder.parse(new InputSource(reader));
// } catch (Exception ex) {
// try {
// this.marker = file.createMarker(IMarker.PROBLEM);
// this.marker.setAttribute(IMarker.SEVERITY,
// IMarker.SEVERITY_ERROR);
// this.marker.setAttribute(IMarker.MESSAGE, ex.getMessage());
// if (ex instanceof SAXParseException) {
// SAXParseException saxParseException = (SAXParseException) ex;
// int lineNumber = saxParseException.getLineNumber();
// int offset = event.getDocument().getLineInformation(lineNumber -
// 1).getOffset()
// + saxParseException.getColumnNumber() - 1;
// this.marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
// this.marker.setAttribute(IMarker.CHAR_START, offset);
// this.marker.setAttribute(IMarker.CHAR_END, offset + 1);
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
}
}
@Override
public void setup(IDocument document) {
}
@Override
public void setup(IDocument document, IPath location, LocationKind locationKind) {
if (locationKind == LocationKind.IFILE) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(location);
document.addDocumentListener(new DocumentValidator(file));
}
}
}