Permalink
Browse files

Create 'new file' wizards for Alex, Happy and UUAGC.

  • Loading branch information...
1 parent b99400f commit b85ee2f37274195dc3991b029c7ea46117fc9f4c @serras serras committed Aug 12, 2011
@@ -5,6 +5,7 @@ bin.includes = plugin.xml,\
META-INF/,\
icons/,\
plugin.properties,\
- templates/
+ templates/,\
+ newFiles/
src.includes = hs-src/
@@ -0,0 +1,34 @@
+{
+module Tokens (Token(..), alexScanTokens) where
+}
+
+%wrapper "basic"
+
+$digit = 0-9 -- digits
+$alpha = [a-zA-Z] -- alphabetic characters
+
+tokens :-
+
+ $white+ { \s -> White }
+ "--".* { \s -> Comment }
+ let { \s -> Let }
+ in { \s -> In }
+ $digit+ { \s -> Int (read s) }
+ [\=\+\-\*\/\(\)] { \s -> Sym (head s) }
+ $alpha [$alpha $digit \_ \']* { \s -> Var s }
+
+{
+-- Each right-hand side has type :: String -> Token
+
+-- The token type:
+data Token =
+ White |
+ Comment |
+ Let |
+ In |
+ Sym Char |
+ Var String |
+ Int Int |
+ Err
+ deriving (Eq,Show)
+}
@@ -0,0 +1,89 @@
+{
+module Calc where
+import Char
+}
+
+%name calc
+%tokentype { Token }
+
+%token
+ let { TokenLet }
+ in { TokenIn }
+ int { TokenInt $$ }
+ var { TokenVar $$ }
+ '=' { TokenEq }
+ '+' { TokenPlus }
+ '-' { TokenMinus }
+ '*' { TokenTimes }
+ '/' { TokenDiv }
+ '(' { TokenOB }
+ ')' { TokenCB }
+
+%%
+
+Exp :: { Exp }
+Exp : let var '=' Exp in Exp { Let $2 $4 $6 }
+ | Exp1 { Exp1 $1 }
+
+Exp1 : Exp1 '+' Term { Plus $1 $3 }
+ | Exp1 '-' Term { Minus $1 $3 }
+ | Term { Term $1 }
+
+Term : Term '*' Factor { Times $1 $3 }
+ | Term '/' Factor { Div $1 $3 }
+ | Factor { Factor $1 }
+
+Factor : int { Int $1 }
+ | var { Var $1 }
+ | '(' Exp ')' { Brack $2 }
+
+{
+
+happyError :: [Token] -> a
+happyError _ = error ("Parse error\n")
+
+data Exp = Let String Exp Exp | Exp1 Exp1
+data Exp1 = Plus Exp1 Term | Minus Exp1 Term | Term Term
+data Term = Times Term Factor | Div Term Factor | Factor Factor
+data Factor = Int Int | Var String | Brack Exp
+
+data Token
+ = TokenLet
+ | TokenIn
+ | TokenInt Int
+ | TokenVar String
+ | TokenEq
+ | TokenPlus
+ | TokenMinus
+ | TokenTimes
+ | TokenDiv
+ | TokenOB
+ | TokenCB
+
+lexer :: String -> [Token]
+lexer [] = []
+lexer (c:cs)
+ | isSpace c = lexer cs
+ | isAlpha c = lexVar (c:cs)
+ | isDigit c = lexNum (c:cs)
+lexer ('=':cs) = TokenEq : lexer cs
+lexer ('+':cs) = TokenPlus : lexer cs
+lexer ('-':cs) = TokenMinus : lexer cs
+lexer ('*':cs) = TokenTimes : lexer cs
+lexer ('/':cs) = TokenDiv : lexer cs
+lexer ('(':cs) = TokenOB : lexer cs
+lexer (')':cs) = TokenCB : lexer cs
+
+lexNum cs = TokenInt (read num) : lexer rest
+ where (num,rest) = span isDigit cs
+
+lexVar cs =
+ case span isAlpha cs of
+ ("let",rest) -> TokenLet : lexer rest
+ ("in",rest) -> TokenIn : lexer rest
+ (var,rest) -> TokenVar var : lexer rest
+
+runCalc :: String -> Exp
+runCalc = calc . lexer
+
+}
@@ -0,0 +1,24 @@
+DATA Tree
+ | Node left: Tree right: Tree
+ | Tip value: Int
+
+ATTR Tree [
+ |
+ | sum: Int
+ ]
+
+SEM Tree
+ | Node lhs.sum = @left.sum + @right.sum
+ | Tip lhs.sum = @value
+
+{
+main :: IO ()
+main = print (show test)
+
+testTree :: Tree
+testTree = Node (Tip 1) (Node (Tip 2) (Tip 3))
+
+test :: Int
+test = sem_Tree testTree
+}
+-- output of the program will be "6"
@@ -168,3 +168,6 @@ sourcegraph_run = Run SourceGraph
alexEditor_name = Alex Lexer Editor
happyEditor_name = Happy Parser Editor
uuagcEditor_name = UU Attribute Grammar Editor
+contenttype_alex_name = Alex Lexer
+contenttype_happy_name = Happy Parser
+contenttype_uuagc_name = UU Attribute Grammar
@@ -1028,4 +1028,31 @@
extensions="x,y,ag">
</participant>
</extension>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <wizard
+ category="net.sf.eclipsefp.haskell.ui.newWizardCategory"
+ class="net.sf.eclipsefp.haskell.ui.wizards.NewAlexWizard"
+ finalPerspective="net.sf.eclipsefp.haskell.ui.HaskellPerspective"
+ id="net.sf.eclipsefp.haskell.ui.wizards.NewAlexWizard"
+ name="%contenttype_alex_name"
+ project="false">
+ </wizard>
+ <wizard
+ category="net.sf.eclipsefp.haskell.ui.newWizardCategory"
+ class="net.sf.eclipsefp.haskell.ui.wizards.NewHappyWizard"
+ finalPerspective="net.sf.eclipsefp.haskell.ui.HaskellPerspective"
+ id="net.sf.eclipsefp.haskell.ui.wizards.NewHappyWizard"
+ name="%contenttype_happy_name"
+ project="false">
+ </wizard>
+ <wizard
+ category="net.sf.eclipsefp.haskell.ui.newWizardCategory"
+ class="net.sf.eclipsefp.haskell.ui.wizards.NewUuagcWizard"
+ finalPerspective="net.sf.eclipsefp.haskell.ui.HaskellPerspective"
+ id="net.sf.eclipsefp.haskell.ui.wizards.NewUuagcWizard"
+ name="%contenttype_uuagc_name"
+ project="false">
+ </wizard>
+ </extension>
</plugin>
@@ -497,6 +497,18 @@
public static String hoogle_dataNotPresent_title;
public static String hoogle_dataNotPresent_message;
+ public static String alex_newFile;
+ public static String happy_newFile;
+ public static String uuagc_newFile;
+
+ public static String contenttype_alex_name;
+ public static String contenttype_happy_name;
+ public static String contenttype_uuagc_name;
+
+ public static String new_alex;
+ public static String new_happy;
+ public static String new_uuagc;
+
private static final String BUNDLE_NAME = UITexts.class.getPackage().getName() + ".uitexts"; //$NON-NLS-1$
static {
@@ -512,3 +512,13 @@ runSourceGraph_errorTitle=Error running SourceGraph
hoogle_downloadingData=Downloading Hoogle data
hoogle_dataNotPresent_title=Hoogle data not present
hoogle_dataNotPresent_message=The Hoogle database is empty. Do yu want to download the required information?
+
+alex_newFile=Create new Alex Lexer
+happy_newFile=Create new Happy Parser
+uuagc_newFile=Create new UU Attribute Grammar
+contenttype_alex_name = Alex Lexer
+contenttype_happy_name = Happy Parser
+contenttype_uuagc_name = UU Attribute Grammar
+new_alex = New Alex Lexer
+new_happy = New Happy Parser
+new_uuagc = New UU Attribute Grammar
@@ -0,0 +1,36 @@
+package net.sf.eclipsefp.haskell.ui.wizards;
+
+import java.io.IOException;
+import java.io.InputStream;
+import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
+import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+
+
+public class NewAlexPage extends WizardNewFileCreationPage {
+
+ static final String FILE_NAME = "/newFiles/alex.x";
+
+ public NewAlexPage( final IStructuredSelection selection ) {
+ super("NewAlexPage", selection);
+ setTitle(UITexts.new_alex);
+ setDescription(UITexts.alex_newFile);
+ setFileExtension("x");
+ }
+
+ @Override
+ protected String getNewFileLabel() {
+ return UITexts.new_alex;
+ }
+
+ @Override
+ protected InputStream getInitialContents() {
+ try {
+ return HaskellUIPlugin.getDefault().getBundle().getEntry(FILE_NAME).openStream();
+ } catch( IOException ex ) {
+ // This should never happen
+ return null;
+ }
+ }
+}
@@ -0,0 +1,43 @@
+package net.sf.eclipsefp.haskell.ui.wizards;
+
+import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+
+
+public class NewAlexWizard extends RevealAtEndWizard implements INewWizard {
+
+ private IStructuredSelection selection;
+ private WizardNewFileCreationPage mainPage;
+
+ public NewAlexWizard() {
+ super();
+ }
+
+ public void init( final IWorkbench workbench, final IStructuredSelection selection ) {
+ this.selection = selection;
+ setWindowTitle(UITexts.new_alex);
+ }
+
+ @Override
+ public void addPages() {
+ mainPage = new NewAlexPage(selection);
+ addPage(mainPage);
+ }
+
+ @Override
+ public boolean performFinish() {
+ IFile file = mainPage.createNewFile();
+ if (file != null) {
+ selectAndReveal( file );
+ openResource( file );
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
@@ -0,0 +1,36 @@
+package net.sf.eclipsefp.haskell.ui.wizards;
+
+import java.io.IOException;
+import java.io.InputStream;
+import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
+import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+
+
+public class NewHappyPage extends WizardNewFileCreationPage {
+
+ static final String FILE_NAME = "/newFiles/happy.y";
+
+ public NewHappyPage( final IStructuredSelection selection ) {
+ super("NewHappyPage", selection);
+ setTitle(UITexts.new_happy);
+ setDescription(UITexts.happy_newFile);
+ setFileExtension("y");
+ }
+
+ @Override
+ protected String getNewFileLabel() {
+ return UITexts.new_happy;
+ }
+
+ @Override
+ protected InputStream getInitialContents() {
+ try {
+ return HaskellUIPlugin.getDefault().getBundle().getEntry(FILE_NAME).openStream();
+ } catch( IOException ex ) {
+ // This should never happen
+ return null;
+ }
+ }
+}
@@ -0,0 +1,43 @@
+package net.sf.eclipsefp.haskell.ui.wizards;
+
+import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+
+
+public class NewHappyWizard extends RevealAtEndWizard implements INewWizard {
+
+ private IStructuredSelection selection;
+ private WizardNewFileCreationPage mainPage;
+
+ public NewHappyWizard() {
+ super();
+ }
+
+ public void init( final IWorkbench workbench, final IStructuredSelection selection ) {
+ this.selection = selection;
+ setWindowTitle(UITexts.new_happy);
+ }
+
+ @Override
+ public void addPages() {
+ mainPage = new NewHappyPage(selection);
+ addPage(mainPage);
+ }
+
+ @Override
+ public boolean performFinish() {
+ IFile file = mainPage.createNewFile();
+ if (file != null) {
+ selectAndReveal( file );
+ openResource( file );
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
Oops, something went wrong.

0 comments on commit b85ee2f

Please sign in to comment.