Changeset 439


Ignore:
Timestamp:
Jun 21, 2010 2:17:31 AM (14 years ago)
Author:
Anya Helene Bagge
Message:
  • rename package parsetree -> xatree
  • add language skinning, with a bit of c++ support
  • separate whitespace from comments in layout
Location:
trunk/MagnoliaPlugin/src/org/magnolialang
Files:
2 added
14 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/MagnoliaPlugin/src/org/magnolialang/eclipse/commands/SelectConstruct.java

    r437 r439  
    2121import org.magnolialang.eclipse.editor.ParseController;
    2222import org.magnolialang.eclipse.rascal.RascalInterpreter;
    23 import org.magnolialang.parsetree.SortNameMatcher;
    24 import org.magnolialang.parsetree.TreeImplodeVisitor;
    25 import org.magnolialang.parsetree.TreeImploder;
    26 import org.magnolialang.parsetree.XaTreeAdapter;
    27 import org.magnolialang.parsetree.XaTreeFactory;
     23import org.magnolialang.xatree.SortNameMatcher;
     24import org.magnolialang.xatree.TreeImplodeVisitor;
     25import org.magnolialang.xatree.TreeImploder;
     26import org.magnolialang.xatree.XaTreeAdapter;
     27import org.magnolialang.xatree.XaTreeFactory;
    2828import org.rascalmpl.values.ValueFactoryFactory;
    2929import org.rascalmpl.values.uptr.TreeAdapter;
  • trunk/MagnoliaPlugin/src/org/magnolialang/eclipse/editor/NodeLocator.java

    r424 r439  
    1010import org.eclipse.imp.pdb.facts.ISourceLocation;
    1111import org.eclipse.imp.pdb.facts.IValue;
    12 import org.magnolialang.parsetree.INodePredicate;
     12import org.magnolialang.xatree.INodePredicate;
    1313import org.rascalmpl.ast.AbstractAST;
    1414//import org.rascalmpl.eclipse.outline.TreeModelBuilder.Group;
  • trunk/MagnoliaPlugin/src/org/magnolialang/env/MagnoliaEnvironment.java

    r419 r439  
    11package org.magnolialang.env;
    2 import static org.magnolialang.parsetree.XaTreeFactory.*;
     2import static org.magnolialang.xatree.XaTreeFactory.*;
    33
    44import java.util.Iterator;
  • trunk/MagnoliaPlugin/src/org/magnolialang/load/ModuleLoader.java

    r428 r439  
    11package org.magnolialang.load;
    22
    3 import static org.magnolialang.parsetree.XaTreeAdapter.getArg;
    4 import static org.magnolialang.parsetree.XaTreeAdapter.getArgs;
    5 import static org.magnolialang.parsetree.XaTreeAdapter.isCons;
    6 import static org.magnolialang.parsetree.XaTreeAdapter.yield;
     3import static org.magnolialang.xatree.XaTreeAdapter.getArg;
     4import static org.magnolialang.xatree.XaTreeAdapter.getArgs;
     5import static org.magnolialang.xatree.XaTreeAdapter.isCons;
     6import static org.magnolialang.xatree.XaTreeAdapter.yield;
    77
    88import java.io.ByteArrayOutputStream;
     
    1919import org.magnolialang.errors.ModuleLoadError;
    2020import org.magnolialang.manager.MagnoliaProjectManager;
    21 import org.magnolialang.parsetree.TreeImploder;
     21import org.magnolialang.xatree.TreeImploder;
    2222import org.rascalmpl.interpreter.staticErrors.SyntaxError;
    2323import org.rascalmpl.values.ValueFactoryFactory;
  • trunk/MagnoliaPlugin/src/org/magnolialang/manager/MagnoliaProjectManager.java

    r437 r439  
    3232import org.magnolialang.load.ModuleLoader;
    3333import org.magnolialang.load.ProjectURIResolver;
    34 import org.magnolialang.parsetree.TreeImploder;
    35 import org.magnolialang.parsetree.XaTreeAdapter;
    3634import org.magnolialang.programs.MagnoliaAdapter;
     35import org.magnolialang.xatree.CxxSkin;
     36import org.magnolialang.xatree.TreeImploder;
     37import org.magnolialang.xatree.XaTreeAdapter;
    3738import org.rascalmpl.values.uptr.ParsetreeAdapter;
    3839
     
    9192                info.tree = moduleTree;
    9293                info.parseTree = null;
    93                 String result = XaTreeAdapter.yield(moduleTree);
     94                String result = XaTreeAdapter.yield(moduleTree, new CxxSkin(), true);
    9495                if(result != null) {
    9596                        try {
  • trunk/MagnoliaPlugin/src/org/magnolialang/programs/MagnoliaAdapter.java

    r428 r439  
    11package org.magnolialang.programs;
    22
    3 import static org.magnolialang.parsetree.XaTreeAdapter.*;
    4 import static org.magnolialang.parsetree.XaTreeFactory.*;
     3import static org.magnolialang.xatree.XaTreeAdapter.*;
     4import static org.magnolialang.xatree.XaTreeFactory.*;
    55
    66import org.eclipse.imp.pdb.facts.*;
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/INodePredicate.java

    r405 r439  
    1 package org.magnolialang.parsetree;
     1package org.magnolialang.xatree;
    22
    33import org.eclipse.imp.pdb.facts.IConstructor;
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/ImploderTest.java

    r414 r439  
    1 package org.magnolialang.parsetree;
     1package org.magnolialang.xatree;
    22
    33import org.eclipse.imp.pdb.facts.IConstructor;
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/SortNameMatcher.java

    r437 r439  
    1 package org.magnolialang.parsetree;
     1package org.magnolialang.xatree;
    22
    33import java.util.Collections;
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/TestXaTree.java

    r418 r439  
    1 package org.magnolialang.parsetree;
     1package org.magnolialang.xatree;
    22
    33import static org.junit.Assert.*;
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/TreeImplodeVisitor.java

    r424 r439  
    1 package org.magnolialang.parsetree;
     1package org.magnolialang.xatree;
     2
     3import java.util.regex.Matcher;
     4import java.util.regex.Pattern;
    25
    36import org.eclipse.imp.pdb.facts.IConstructor;
     
    2124import org.rascalmpl.values.uptr.TreeAdapter;
    2225import org.rascalmpl.values.uptr.visitors.TreeVisitor;
    23 import static org.magnolialang.parsetree.XaTreeFactory.*;
     26
     27import static org.magnolialang.xatree.XaTreeFactory.*;
    2428
    2529public class TreeImplodeVisitor extends TreeVisitor {
     
    142146        }
    143147
     148        private final Pattern LAYOUT_PAT = Pattern.compile("^(\\s*)(\\S.*\\S)(\\s*)$", Pattern.DOTALL);
     149       
    144150        public ITuple visitChildren(Iterable<IValue> trees) throws FactTypeUseException, VisitorException {
    145151                IListWriter ast = vf.listWriter(Type_XaTree);
     
    152158                        if(TreeAdapter.isCfOptLayout(tree)) {
    153159                                String chars = TreeAdapter.yield(tree);
    154                                 if(!chars.equals(""))
    155                                         cst.append(space(chars));
     160                                if(!chars.equals("")) {
     161                                        Matcher m = LAYOUT_PAT.matcher(chars);
     162                                        if(m.matches()) {
     163                                                cst.append(space(m.group(1)));
     164                                                cst.append(comment(m.group(2)));
     165                                                cst.append(space(m.group(3)));
     166                                        }
     167                                        else
     168                                                cst.append(space(chars));
     169                                }
    156170                        }
    157171                        else if(TreeAdapter.isLiteral(tree)) {
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/TreeImploder.java

    r414 r439  
    1 package org.magnolialang.parsetree;
     1package org.magnolialang.xatree;
    22
    33import org.eclipse.imp.pdb.facts.IValue;
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/XaTreeAdapter.java

    r426 r439  
    1 package org.magnolialang.parsetree;
     1package org.magnolialang.xatree;
     2
     3import java.util.ArrayList;
     4import java.util.LinkedList;
     5import java.util.List;
    26
    37import org.eclipse.imp.pdb.facts.*;
     
    1418import org.rascalmpl.values.uptr.visitors.TreeVisitor;
    1519
    16 import static org.magnolialang.parsetree.XaTreeFactory.*;
     20import static org.magnolialang.xatree.XaTreeFactory.*;
    1721public class XaTreeAdapter {
    1822        public static TypeStore ts = new TypeStore(
     
    147151                        return null;
    148152        }
     153       
     154        public static IString getName(IValue tree) {
     155                return (IString) ((IConstructor)tree).get("name");
     156        }
     157
     158        public static IString getSort(IValue tree) {
     159                return (IString) ((IConstructor)tree).get("sort");
     160        }
     161
    149162        public static boolean isGround(IValue tree) {
    150163                try {
     
    226239                }
    227240        }
     241       
     242        public static String yield(IValue tree, final ILanguageSkin skin, final boolean fallback) {
     243                try {
     244                        return tree.accept(new NullVisitor<String>() {
     245                                private List<String> indentStack = new LinkedList<String>();
     246                                private List<IValue> contextStack = new LinkedList<IValue>();
     247                               
     248                                public String visitConstructor(IConstructor c) throws VisitorException {
     249                                        IList concrete = null;
     250                                       
     251                                        if(isCons(c))
     252                                                concrete = skin.getConcrete(getName(c), getSort(c), null);
     253                                        else if(isSeq(c)) {
     254                                                IListWriter lw = vf.listWriter(Type_XaToken);
     255                                                IConstructor sep = skin.getListSep(getSort(c), null);
     256                                                if(sep != null) {
     257                                                        for(int i = 0; i < getArgs(c).length(); i++) {
     258                                                                if(i > 0)
     259                                                                        lw.append(sep);
     260                                                                lw.append(child(i));
     261                                                        }
     262                                                        concrete = lw.done();
     263                                                }
     264                                        }
     265                                               
     266                                       
     267                                        if(concrete == null && fallback)
     268                                                concrete = (IList) c.getAnnotation("concrete");
     269                                       
     270                                        if(concrete == null || concrete.length() == 0) {
     271                                                if(isLeaf(c))
     272                                                        return ((IString)c.get("strVal")).getValue();
     273                                                else if(isVar(c))
     274                                                        return "<" + ((IString)c.get("name")).getValue() + ">";
     275                                                else {
     276                                                        StringBuffer result = new StringBuffer();
     277                                                        for(IValue child : getArgs(c))
     278                                                                result.append(child.accept(this));
     279                                                        return result.toString();
     280                                                }
     281                                        }
     282                                        IList args;
     283                                        if(isLeaf(c) || isVar(c))
     284                                                args = vf.list(c.removeAnnotation("concrete"));
     285                                        else
     286                                                args = getArgs(c);
     287                                       
     288                                        StringBuffer result = new StringBuffer();
     289                                        for(IValue token : concrete) {
     290                                                Type type = ((IConstructor)token).getConstructorType();
     291                                                if(type == Type_Token || type == Type_Comment) {
     292                                                        result.append(((IString)((IConstructor)token).get("chars")).getValue());
     293                                                }
     294                                                else if(type == Type_Space)
     295                                                        result.append(((IString)((IConstructor)token).get("chars")).getValue());
     296                                                else {
     297                                                        int index = ((IInteger)((IConstructor)token).get("index")).intValue();
     298                                                        result.append(args.get(index).accept(this));
     299                                                }
     300                                        }                                       
     301                                        return result.toString();
     302                                }});
     303                } catch (VisitorException e) {
     304                        return null;
     305                }
     306        }
     307
    228308}
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/XaTreeFactory.java

    r424 r439  
    1 package org.magnolialang.parsetree;
     1package org.magnolialang.xatree;
    22
    33import java.util.Random;
     
    5555        public static Type Type_Child = tf.constructor(ts, Type_XaToken, "child",
    5656                        tf.integerType(), "index");
     57        public static Type Type_CtxChild = tf.constructor(ts, Type_XaToken, "ctxchild",
     58                        tf.integerType(), "index", tf.valueType(), "context");
    5759       
    5860        public static IConstructor cons(String name, String sort, IList args) {
     
    103105        public static IConstructor child(int index) {
    104106                return vf.constructor(Type_Child, vf.integer(index));
     107        }
     108
     109        public static IConstructor child(int index, IValue context) {
     110                return vf.constructor(Type_CtxChild, vf.integer(index), context);
    105111        }
    106112
Note: See TracChangeset for help on using the changeset viewer.