Changeset 448


Ignore:
Timestamp:
Jun 24, 2010 3:43:46 PM (14 years ago)
Author:
Anya Helene Bagge
Message:
  • Report ambiguities as errors with hover text
  • Schedule static checker while editing
  • Setup stuff for hover help and reference resolving
Location:
trunk/MagnoliaPlugin
Files:
6 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagnoliaPlugin/META-INF/MANIFEST.MF

    r442 r448  
    2525 org.eclipse.imp.smapifier,
    2626 lpg.runtime
    27 Import-Package: org.junit
    2827Bundle-RequiredExecutionEnvironment: JavaSE-1.6
     28Import-Package: org.junit;version="4.5.0";resolution:=optional
  • trunk/MagnoliaPlugin/plugin.xml

    r446 r448  
    1717         point="org.eclipse.imp.runtime.languageDescription">
    1818      <language
     19            extensions="mxa"
    1920            description="Experimental language specification language"
    20             extensions="mxa"
    2121            language="MetaXa">
    2222      </language>
     
    211211      </page>
    212212   </extension>
     213   <extension
     214         id="ambiguityMarker"
     215         name="Ambiguity"
     216         point="org.eclipse.core.resources.markers">
     217      <super
     218            type="org.eclipse.core.resources.problemmarker">
     219      </super>
     220      <persistent
     221            value="false">
     222      </persistent>
     223   </extension>
     224   <extension
     225         id="hoverHelper"
     226         name="Magnolia Hover Helper"
     227         point="org.eclipse.imp.runtime.hoverHelper">
     228      <hoverHelper
     229            class="org.magnolialang.eclipse.hoverHelper.MagnoliaHoverHelper"
     230            language="MetaXa">
     231      </hoverHelper>
     232   </extension>
     233   <extension
     234         id="referenceResolver"
     235         name="Magnolia Reference Resolver"
     236         point="org.eclipse.imp.runtime.referenceResolvers">
     237      <referenceResolver
     238            class="org.magnolialang.eclipse.hoverHelper.HelperReferenceResolver"
     239            language="Magnolia">
     240      </referenceResolver>
     241   </extension>
     242   <extension
     243         point="org.eclipse.imp.runtime.editorService">
     244      <editorService
     245            class="org.magnolialang.eclipse.editor.StaticCheckModelListener"
     246            language="Magnolia">
     247      </editorService>
     248   </extension>
     249   <extension
     250         point="org.eclipse.imp.runtime.editorService">
     251      <editorService
     252            class="org.magnolialang.eclipse.editor.AmbiguityMarkerModelListener"
     253            language="Magnolia">
     254      </editorService>
     255   </extension>
     256   <extension
     257         point="org.eclipse.imp.runtime.editorService">
     258      <editorService
     259            class="org.magnolialang.eclipse.editor.AmbiguityMarkerModelListener"
     260            language="MetaXa">
     261      </editorService>
     262   </extension>
    213263
    214264</plugin>
  • trunk/MagnoliaPlugin/src/org/magnolialang/eclipse/MagnoliaPlugin.java

    r426 r448  
    1313import org.osgi.framework.Bundle;
    1414import org.osgi.framework.BundleContext;
    15 import org.magnolialang.uri.*;
    1615import sglr.LegacySGLRInvoker;
    1716import sglr.SGLRInvoker;
  • trunk/MagnoliaPlugin/src/org/magnolialang/eclipse/editor/MagnoliaEditor.java

    r428 r448  
    1111    public MagnoliaEditor() {
    1212        super();
     13     //   ((ParseController)getParseController()).setEditor(this);
    1314        // used for the expression breakpoints management
    1415        //setEditorContextMenuId("rascal.editor.contextMenu");
  • trunk/MagnoliaPlugin/src/org/magnolialang/eclipse/editor/ParseController.java

    r446 r448  
    2323import org.magnolialang.load.ProjectURIResolver;
    2424import org.magnolialang.manager.MagnoliaProjectManager;
     25import org.magnolialang.xatree.TreeImploder;
    2526import org.rascalmpl.interpreter.staticErrors.SyntaxError;
    2627import org.rascalmpl.values.errors.SummaryAdapter;
     
    4041
    4142        private Language language;
     43
     44
     45        private MagnoliaEditor editor;
    4246
    4347        public ParseController() {
     
    7377        }
    7478
     79        public IMessageHandler getMessageHandler() {
     80                return handler;
     81        }
     82       
    7583        public ILanguageSyntaxProperties getSyntaxProperties() {
    7684                return new MagnoliaSyntaxProperties();
     
    149157        }
    150158
     159        public void setEditor(MagnoliaEditor magnoliaEditor) {
     160                this.editor = magnoliaEditor;
     161               
     162        }
     163       
     164        public MagnoliaEditor getEditor() {
     165                return editor;
     166        }
     167
     168        public MagnoliaProjectManager getManager() {
     169                return manager;
     170        }
     171
    151172       
    152173}
  • trunk/MagnoliaPlugin/src/org/magnolialang/eclipse/editor/StaticCheckModelListener.java

    r361 r448  
    11package org.magnolialang.eclipse.editor;
    2 /*
     2
    33import org.eclipse.core.runtime.IProgressMonitor;
    44import org.eclipse.imp.parser.IModelListener;
    55import org.eclipse.imp.parser.IParseController;
    66import org.eclipse.imp.pdb.facts.IConstructor;
    7 import org.eclipse.imp.pdb.facts.IList;
    8 import org.rascalmpl.checker.StaticChecker;
    9 import org.rascalmpl.eclipse.Activator;
    10 import org.rascalmpl.values.uptr.ParsetreeAdapter;
    11 import org.rascalmpl.values.uptr.TreeAdapter;
     7import org.magnolialang.env.MagnoliaEnvironment;
     8import org.magnolialang.magnolia.StaticChecker;
     9import org.magnolialang.manager.MagnoliaProjectManager;
    1210
    1311public class StaticCheckModelListener implements IModelListener {
    1412        private final StaticChecker checker = StaticChecker.getInstance();
    15         private final MarkerModelListener marker = new MarkerModelListener();
    1613
    1714        public AnalysisRequired getAnalysisRequired() {
     
    2118        public void update(final IParseController parseController,
    2219                        final IProgressMonitor monitor) {
    23                 Thread x = new Thread("Rascal Static Checker") {
     20                Thread x = new Thread("Magnolia Static Checker") {
    2421                        @Override
    2522                        public void run() {
    26                                 monitor.beginTask("Checking Rascal module " + parseController.getPath().toString(), 1);
    27                                 IConstructor parseTree = (IConstructor) parseController.getCurrentAst();
    28                                
    29                                 if (parseTree == null) {
    30                                         return;
    31                                 }
    32                                
    33                                 try {
    34                                         IConstructor newTree = checker.checkModule((IConstructor) TreeAdapter.getArgs(ParsetreeAdapter.getTop(parseTree)).get(1));
    35                                         if (newTree != null) {
    36                                                 IConstructor treeTop = ParsetreeAdapter.getTop(parseTree);
    37                                                 IList treeArgs = TreeAdapter.getArgs(treeTop).put(1, newTree);
    38                                                 IConstructor newTreeTop = treeTop.set("args", treeArgs).setAnnotation("loc", treeTop.getAnnotation("loc"));
    39                                                 parseTree = parseTree.set("top", newTreeTop);
    40                                                 ((ParseController) parseController).setCurrentAst(parseTree);
    41                                                 marker.update(parseTree, parseController, monitor);
    42                                         }
    43                                         else {
    44                                                 Activator.getInstance().logException("static checker returned null", new RuntimeException());
    45                                         }
    46                                 }
    47                                 catch (Throwable e) {
    48                                         Activator.getInstance().logException("static checker failed", e);
    49                                 }
     23                                monitor.beginTask("Checking Magnolia module " + parseController.getPath().toString(), 3);
     24
     25                                ParseController ctrl = (ParseController)parseController;
     26                                MagnoliaProjectManager manager = ctrl.getManager();
     27                                String moduleName = manager.findEditedModule(ctrl);
     28                                IConstructor tree = manager.getModuleTree(moduleName, true);
     29                                monitor.worked(1);
     30                                MagnoliaEnvironment env = manager.getModuleEnv(moduleName);
     31                                monitor.worked(1);
     32
     33                                checker.checkModule(tree, env);
    5034                                monitor.worked(1);
    5135                        }
     
    5842        }
    5943}
    60 */
  • trunk/MagnoliaPlugin/src/org/magnolialang/eclipse/editor/TokenColorer.java

    r446 r448  
    11package org.magnolialang.eclipse.editor;
     2
    23
    34import java.util.HashMap;
     
    1112import org.eclipse.jface.text.TextAttribute;
    1213import org.eclipse.swt.SWT;
     14import org.eclipse.swt.graphics.Color;
    1315import org.eclipse.swt.widgets.Display;
    1416
     
    4244                super();
    4345                normal = new TextAttribute(Display.getDefault().getSystemColor(SWT.COLOR_BLACK), null, SWT.NONE);
    44                
     46
    4547                Display display = Display.getDefault();
    4648            map.put(KEYWORD, new TextAttribute(display.getSystemColor(SWT.COLOR_DARK_MAGENTA), null, SWT.BOLD));
     
    5557                map.put(AMBIGUOUS,new TextAttribute(null, display.getSystemColor(SWT.COLOR_YELLOW), SWT.NONE));
    5658                map.put(ERROR,new TextAttribute(null, display.getSystemColor(SWT.COLOR_RED), SWT.NONE));
    57                 map.put(MXAID,new TextAttribute(display.getSystemColor(SWT.COLOR_BLACK), null, SWT.NONE));
    58                 map.put(MXASTRINGLITERAL,new TextAttribute(display.getSystemColor(SWT.COLOR_DARK_RED), null, SWT.NONE));
    59                 map.put(MXATRANSITION,new TextAttribute(display.getSystemColor(SWT.COLOR_DARK_BLUE), null, SWT.NONE));
    60                 map.put(MXATOKEN,new TextAttribute(display.getSystemColor(SWT.COLOR_BLACK), null, SWT.BOLD));
    61                 map.put(MXAMETAVAR,new TextAttribute(display.getSystemColor(SWT.COLOR_DARK_CYAN), null, SWT.BOLD));
    62                 map.put(MXAVAR,new TextAttribute(display.getSystemColor(SWT.COLOR_DARK_CYAN), null, SWT.BOLD));
     59
     60                Color mxaCol1 = new Color(Display.getDefault(), 95, 35, 20);
     61                Color mxaCol2 = new Color(Display.getDefault(), 120, 25, 15);
     62                Color mxaCol3 = new Color(Display.getDefault(), 60, 45, 20);
     63                map.put(MXAID,new TextAttribute(mxaCol1, null, SWT.NONE));
     64                map.put(MXASTRINGLITERAL,new TextAttribute(mxaCol3, null, SWT.NONE));
     65                map.put(MXATRANSITION,new TextAttribute(mxaCol1, null, SWT.NONE));
     66                map.put(MXATOKEN,new TextAttribute(mxaCol3, null, SWT.BOLD));
     67                map.put(MXAMETAVAR,new TextAttribute(mxaCol2, null, SWT.ITALIC));
     68                map.put(MXAVAR,new TextAttribute(mxaCol1, null, SWT.NONE));
    6369        }
    6470
  • trunk/MagnoliaPlugin/src/org/magnolialang/eclipse/editor/TokenIterator.java

    r446 r448  
    55import java.util.List;
    66
     7import org.eclipse.core.resources.IFile;
     8import org.eclipse.core.resources.IMarker;
     9import org.eclipse.core.resources.IResource;
     10import org.eclipse.core.runtime.CoreException;
     11import org.eclipse.core.runtime.IPath;
     12import org.eclipse.imp.model.ISourceProject;
     13import org.eclipse.imp.parser.IMessageHandler;
     14import org.eclipse.imp.parser.IMessageHandlerExtension;
    715import org.eclipse.imp.pdb.facts.IConstructor;
     16import org.eclipse.imp.pdb.facts.ISet;
     17import org.eclipse.imp.pdb.facts.ISourceLocation;
    818import org.eclipse.imp.pdb.facts.IValue;
    919import org.eclipse.imp.pdb.facts.visitors.VisitorException;
     20import org.magnolialang.load.ProjectURIResolver;
    1021import org.rascalmpl.values.uptr.ProductionAdapter;
    1122import org.rascalmpl.values.uptr.TreeAdapter;
     
    1526        private final List<Token> tokenList;
    1627        private final Iterator<Token> tokenIterator;
    17 
     28       
    1829        public TokenIterator(IConstructor parseTree) {
    1930                this.tokenList = new LinkedList<Token>();
     
    2738                }
    2839                tokenIterator = tokenList.iterator();
     40
    2941        }
    3042
     
    4557                public IConstructor visitTreeAmb(IConstructor arg) throws VisitorException {
    4658                        // we just go into the first, it's arbitrary but at least we'll get some nice highlighting
     59                        return (IConstructor) TreeAdapter.getAlternatives(arg).iterator().next().accept(this);
    4760//                      TreeAdapter.getAlternatives(arg).iterator().next().accept(this);
    48                         tokenList.add(new Token(TokenColorer.AMBIGUOUS, TreeAdapter.getLocation((IConstructor)TreeAdapter.getAlternatives(arg).iterator().next())));
    49                         return arg;
     61                        //ISourceLocation loc = TreeAdapter.getLocation((IConstructor)TreeAdapter.getAlternatives(arg).iterator().next());
     62                        //tokenList.add(new Token(TokenColorer., loc));
     63
     64                /*      ISet alts = TreeAdapter.getAlternatives(arg);
     65                        String message = "Ambiguity:\n";
     66                        for(IValue alt : alts) {
     67                                IConstructor prod = TreeAdapter.getProduction((IConstructor)alt);
     68                                message += "    " + ProductionAdapter.getSortName(prod) + " ::= " + ProductionAdapter.getLhs(prod) + "\n";
     69                        }
     70                       
     71                        if(msgHandler != null) {
     72                                msgHandler.handleSimpleMessage(message, loc.getOffset(), loc.getOffset()+loc.getLength(), 0, 0, 0, 0);
     73                        }
     74                        System.out.println(message);
     75*/
     76                //      return arg;
    5077                }
    5178
     
    5885                                IConstructor prod = TreeAdapter.getProduction(arg);
    5986                                String sort = ProductionAdapter.getSortName(prod);
    60                                 if(TokenColorer.categories.contains(sort))
     87                                category = ProductionAdapter.getCategory(prod);
     88                                //String code = TreeAdapter.yield(arg);
     89                               
     90                                if(category == null && TokenColorer.categories.contains(sort))
    6191                                        category = sort;
    62                                 else
    63                                         category = ProductionAdapter.getCategory(prod);
     92
    6493                                if(TokenColorer.ERROR.equals(ProductionAdapter.getConstructorName(prod)))
    6594                                        category = TokenColorer.ERROR;
  • trunk/MagnoliaPlugin/src/org/magnolialang/manager/MagnoliaProjectManager.java

    r442 r448  
    200200                }
    201201        }
     202
     203        public String findEditedModule(ParseController ctrl) {
     204                // TODO: Handle multiple editors for same module
     205                ModuleInfo info = ctrlMap.get(ctrl);
     206                if(info != null) {
     207                        ModuleInfo info2 = moduleMap.get(info.moduleName);
     208                        if(info2 != info)
     209                                throw new ImplementationError("Find-by-controller does not match find-by-name");
     210                        return info.moduleName;
     211                }
     212                else
     213                        return null;
     214        }
     215
    202216        public boolean dataInvariant() {
    203217                return loader != null && buildPath != null;
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/TreeImplodeVisitor.java

    r442 r448  
    44import java.util.regex.Pattern;
    55
     6import org.eclipse.core.resources.IFile;
     7import org.eclipse.core.resources.IMarker;
     8import org.eclipse.core.resources.IResource;
     9import org.eclipse.core.resources.IResourceRuleFactory;
     10import org.eclipse.core.runtime.CoreException;
     11import org.eclipse.imp.parser.IMessageHandler;
    612import org.eclipse.imp.pdb.facts.IConstructor;
    713import org.eclipse.imp.pdb.facts.IList;
    814import org.eclipse.imp.pdb.facts.IListWriter;
    915import org.eclipse.imp.pdb.facts.INode;
     16import org.eclipse.imp.pdb.facts.ISet;
     17import org.eclipse.imp.pdb.facts.ISourceLocation;
    1018import org.eclipse.imp.pdb.facts.IString;
    1119import org.eclipse.imp.pdb.facts.ITuple;
     
    1725import org.eclipse.imp.pdb.facts.type.TypeStore;
    1826import org.eclipse.imp.pdb.facts.visitors.VisitorException;
     27import org.magnolialang.eclipse.editor.Token;
     28import org.magnolialang.eclipse.editor.TokenColorer;
     29import org.magnolialang.load.ProjectURIResolver;
    1930import org.rascalmpl.values.ValueFactoryFactory;
    2031import org.rascalmpl.values.uptr.Factory;
     
    3445        public static final Type Attr = tf.abstractDataType(uptr, "Attr");
    3546        public static final Type Attr_Abstract = tf.constructor(uptr, Attr, "selectable");
    36 
     47        private static final String AMB_MARKER = "magnolia_eclipse.ambiguityMarker";
     48        private IMessageHandler handler;
     49       
     50       
     51        /**
     52         * Create a new tree imploder, not attached to a message handler.
     53         */
     54        public TreeImplodeVisitor() {
     55                this.handler = null;
     56        }
     57       
     58        /**
     59         * Create a new tree imploder, attached to the file.
     60         * @param handler Message handler for reporting errors
     61         */
     62        public TreeImplodeVisitor(IMessageHandler handler) {
     63                this.handler = handler;
     64        }
     65       
     66       
    3767        @Override
    3868        public IConstructor visitTreeAmb(IConstructor tree) throws VisitorException {
    39                 // TODO Auto-generated method stub
    40                 return null;
     69                IConstructor result = (IConstructor)TreeAdapter.getAlternatives(tree).iterator().next();
     70
     71                return result;
    4172        }
    4273
     
    163194                        assert v instanceof IConstructor;
    164195                        IConstructor tree = (IConstructor)v;
    165                        
     196                        if(TreeAdapter.isAmb(tree))
     197                                tree = visitTreeAmb(tree);
    166198                        if(TreeAdapter.isCfOptLayout(tree)) {
    167199                                String chars = TreeAdapter.yield(tree);
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/TreeImploder.java

    r439 r448  
    11package org.magnolialang.xatree;
    22
     3import org.eclipse.core.resources.IFile;
     4import org.eclipse.imp.parser.IMessageHandler;
    35import org.eclipse.imp.pdb.facts.IValue;
    46import org.eclipse.imp.pdb.facts.visitors.VisitorException;
     
    79public class TreeImploder {
    810
     11        /**
     12         * Implode an AsFix tree to an XaTree.
     13         * @param tree A tree in AsFix format
     14         * @return An imploded XaTree
     15         */
    916        public static IValue implodeTree(IValue tree) {
    1017                try {
     
    1421                }       
    1522        }
     23
     24        /**
     25         * Implode an AsFix tree to an XaTree, annotating the given file with any errors encountered.
     26         * @param tree A tree in AsFix format
     27         * @param file A file, for marker annotations
     28         * @return An imploded XaTree
     29         */
     30        public static IValue implodeTree(IValue tree, IMessageHandler handler) {
     31                try {
     32                        return tree.accept(new TreeImplodeVisitor(handler));
     33                } catch (VisitorException e) {
     34                        throw new ImplementationError("Failed to implode parse tree", e);
     35                }       
     36        }
     37
    1638}
Note: See TracChangeset for help on using the changeset viewer.