Changeset 440


Ignore:
Timestamp:
Jun 21, 2010 12:11:57 PM (14 years ago)
Author:
Anya Helene Bagge
Message:
  • Handle newlines separately from other spaces
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagnoliaPlugin/src/org/magnolialang/xatree/TreeImplodeVisitor.java

    r439 r440  
    8888                        cons = cons != null ? cons : sort;
    8989                        result = (IConstructor) ((IList) t.get(0)).get(0);
    90                         concrete = ((IList) result.getAnnotation("concrete")).insert(concrete.get(0)).append(concrete.get(2));
     90                        IListWriter cst = vf.listWriter(Type_XaToken);
     91                        for(IValue tok : concrete) {
     92                                System.out.println(tok);
     93                                if(((IConstructor)tok).getConstructorType() == Type_Child)
     94                                        cst.appendAll((IList)result.getAnnotation("concrete"));
     95                                else
     96                                        cst.append(tok);
     97                        }
     98                        concrete = cst.done();
     99                        //concrete = ((IList) result.getAnnotation("concrete")).insert(concrete.get(0)).append(concrete.get(2));
    91100                }
    92101                else if(SymbolAdapter.isCf(rhs)) {
     
    147156
    148157        private final Pattern LAYOUT_PAT = Pattern.compile("^(\\s*)(\\S.*\\S)(\\s*)$", Pattern.DOTALL);
    149        
     158
    150159        public ITuple visitChildren(Iterable<IValue> trees) throws FactTypeUseException, VisitorException {
    151160                IListWriter ast = vf.listWriter(Type_XaTree);
     
    161170                                        Matcher m = LAYOUT_PAT.matcher(chars);
    162171                                        if(m.matches()) {
    163                                                 cst.append(space(m.group(1)));
     172                                                splitSpaces(m.group(1), cst);
    164173                                                cst.append(comment(m.group(2)));
    165                                                 cst.append(space(m.group(3)));
     174                                                splitSpaces(m.group(3), cst);
    166175                                        }
    167176                                        else
    168                                                 cst.append(space(chars));
     177                                                splitSpaces(chars, cst);
    169178                                }
    170179                        }
     
    182191                return vf.tuple(ast.done(), cst.done());
    183192        }
     193       
     194        private final Pattern PAT_SPACE = Pattern.compile("^([^\r\n]*)([\r\n]+)(.*)$", Pattern.DOTALL);
     195       
     196        private void splitSpaces(String chars, IListWriter cst) {
     197                Matcher m = PAT_SPACE.matcher(chars);
     198                while(m.matches()) {
     199                        if(m.group(1).length() > 0)
     200                                cst.append(space(m.group(1)));
     201                        cst.append(space(m.group(2)));
     202                        chars = m.group(3);
     203                        m = PAT_SPACE.matcher(chars);
     204                }
     205               
     206                if(chars.length() > 0)
     207                        cst.append(space(chars));
     208        }
    184209        @Override
    185210        public IConstructor visitTreeChar(IConstructor tree)
Note: See TracChangeset for help on using the changeset viewer.