Changeset 420
- Timestamp:
- Jun 11, 2010 9:40:39 AM (14 years ago)
- Location:
- MetaXa/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
MetaXa/src/MagnoliaCompile.rsc
r403 r420 1 1 module MagnoliaCompile 2 import MagnoliaFront;3 import Magnolia;4 2 import String; 5 3 import IO; … … 8 6 import XaLib; 9 7 import XaTree; 10 import MagnoliaCxxBack;11 8 12 9 data MagnoliaEnv = environ(rel[Name, XaTree] members); … … 35 32 } 36 33 37 public Tree compileMagnolia(loc file) { 38 Tree parsed = parseMagnolia(file); 39 //Tree desugared = desugarMagnolia(parsed); 40 41 decls = loadTree(parsed, file); 42 return flattenConcepts(parsed, decls); 43 } 44 public str flattenModule(loc path, str project) { 45 <tree, ctx> = loadFile(path, project); 46 path.path = replaceLast(path.path, "\\.mg", "-flattened.mg"); 34 //public Tree compileMagnolia(loc file) { 35 // Tree parsed = parseMagnolia(file); 36 // //Tree desugared = desugarMagnolia(parsed); 37 // 38 // decls = loadTree(parsed, file); 39 // return flattenConcepts(parsed, decls); 40 //} 41 //public str flattenModule(loc path, str project) { 42 // <tree, ctx> = loadFile(path, project); 43 // return unparse(reindent(flattenConcepts(tree, ctx))); 44 //} 45 public str flattenModule(XaTree tree, MagnoliaEnv ctx) { 47 46 return unparse(reindent(flattenConcepts(tree, ctx))); 48 47 } 49 50 public void flattenModule(str moduleName, str project) { 51 path = findInPath("<moduleName>.mg", project); 52 <tree, ctx> = loadFile(path); 53 path.path = replaceLast(path.path, "\\.mg", "-flattened.mg"); 54 println("Writing flattened module to <path>"); 55 writeFile(path, unparse(reindent(flattenConcepts(tree, ctx)))); 56 } 57 58 public void flattenModuleToCxx(str moduleName, str project) { 59 path = findInPath("<moduleName>.mg", project); 60 <tree, ctx> = loadFile(path, project); 61 path.path = replaceLast(path.path, "\\.mg", ".cc"); 62 println("Writing flattened module to <path>"); 63 writeFile(path, unparse(reindent(cxxFormat(flattenConcepts(tree, ctx))))); 64 } 65 66 public tuple[XaTree, MagnoliaEnv] loadModule(str moduleName, str project) { 67 path = findInPath("<moduleName>.mg", project); 68 println("Loading module <moduleName> from <path>"); 69 return loadFile(path, project); 70 } 71 72 public tuple[XaTree, MagnoliaEnv] loadFile(loc moduleLoc, str project) { 48 //public void flattenModule(str moduleName, str project) { 49 // path = findInPath("<moduleName>.mg", project); 50 // <tree, ctx> = loadFile(path); 51 // path.path = replaceLast(path.path, "\\.mg", "-flattened.mg"); 52 // println("Writing flattened module to <path>"); 53 // writeFile(path, unparse(reindent(flattenConcepts(tree, ctx)))); 54 //} 55 56 //public void flattenModuleToCxx(str moduleName, str project) { 57 // path = findInPath("<moduleName>.mg", project); 58 // <tree, ctx> = loadFile(path, project); 59 // path.path = replaceLast(path.path, "\\.mg", ".cc"); 60 // println("Writing flattened module to <path>"); 61 // writeFile(path, unparse(reindent(cxxFormat(flattenConcepts(tree, ctx))))); 62 //} 63 64 //public tuple[XaTree, MagnoliaEnv] loadModule(str moduleName, str project) { 65 // path = findInPath("<moduleName>.mg", project); 66 // println("Loading module <moduleName> from <path>"); 67 // return loadFile(path, project); 68 //} 69 70 //public tuple[XaTree, MagnoliaEnv] loadFile(loc moduleLoc, str project) { 71 // result = newEnv(); 72 // XaTree tree = parseMagnolia(moduleLoc); 73 // if(cons("MagnoliaTree", [cons("ModuleHead", [NAME, seq(CLAUSES,_)], _), seq(DECLS,_)], _) := tree) { 74 // for(clause <- CLAUSES) { 75 // switch(clause) { 76 // case cons("Imports", [seq(MODULES, _)], _): 77 // for(cons("ImportAll", [m], _) <- MODULES) { 78 // result = joinEnv(result, loadModule(unparse(m), project)[1]); 79 // } 80 // } 81 // } 82 // for(decl <- DECLS) { 83 // // println(decl); 84 // switch(decl) { 85 // case cons("DefDecl", [cons("ConceptClause", [CONCEPT], _), _, cons(_, [seq(CONTENTS,_)], _)], _): { 86 // result.members += {name(unparse(CONCEPT))} * toSet(CONTENTS); 87 // } 88 // } 89 // } 90 // } 91 // return <tree, result>; 92 //} 93 94 public MagnoliaEnv loadTrees(list[XaTree] trees) { 73 95 result = newEnv(); 74 XaTree tree = parseMagnolia(moduleLoc); 96 for(tree <- trees) 97 result = loadTree(tree, result); 98 return result; 99 } 100 101 public MagnoliaEnv loadTree(XaTree tree, MagnoliaEnv result) { 75 102 if(cons("MagnoliaTree", [cons("ModuleHead", [NAME, seq(CLAUSES,_)], _), seq(DECLS,_)], _) := tree) { 76 for(clause <- CLAUSES) {77 switch(clause) {78 case cons("Imports", [seq(MODULES, _)], _):79 for(cons("ImportAll", [m], _) <- MODULES) {80 result = joinEnv(result, loadModule(unparse(m), project)[1]);81 }82 }83 }84 103 for(decl <- DECLS) { 85 104 // println(decl); 86 105 switch(decl) { 87 106 case cons("DefDecl", [cons("ConceptClause", [CONCEPT], _), _, cons(_, [seq(CONTENTS,_)], _)], _): { 107 println(name(unparse(CONCEPT))); 88 108 result.members += {name(unparse(CONCEPT))} * toSet(CONTENTS); 89 109 } … … 91 111 } 92 112 } 93 return <tree, result>;113 return result; 94 114 } 95 115 96 116 public XaTree flattenConcepts(XaTree tree, MagnoliaEnv env) { 97 117 return top-down-break visit(tree) { 98 case cDecl : cons("DefDecl", [cons("ConceptClause", [CONCEPT], ccsort), seq(SUBCLAUSES,scsort), cons("DeclBody", [seq(CONTENTS,_)], _)], _) : {99 //println("Looking at <unparse(CONCEPT)>: ");118 case cDecl : cons("DefDecl", [cons("ConceptClause", [CONCEPT], _), seq(SUBCLAUSES,_), cons("DeclBody", [seq(CONTENTS,_)], _)], _) : { 119 println("Looking at <unparse(CONCEPT)>: "); 100 120 set[XaTree] decls = {}; 101 121 for(decl <- CONTENTS) { 102 //println(" Decl: ", decl);122 println(" Decl: ", decl); 103 123 switch(decl) { 104 124 case cons("Requires", [seq(reqs, _)], _): 105 125 for(req <- reqs) { 106 //println(" <unparse(CONCEPT)> requires <unparse(req)>:");126 println(" <unparse(CONCEPT)> requires <unparse(req)>:"); 107 127 <ds, env> = getConcept(req, env); 108 128 decls += ds; … … 140 160 insert decl; 141 161 } 142 case cDecl: cons(c,as,"Decl") => cDecl162 //case cDecl: cons(c,as,"Decl") => cDecl 143 163 } 144 164 } -
MetaXa/src/XaTree.rsc
r413 r420 31 31 implodeOptions(bool foldInjections, bool addConcrete, bool addLocation, list[str] varConses); 32 32 33 XaImplodeOpts defaultOpts = implodeOptions(true, true, false, ["RascalVar", "RascalListVar"]);33 XaImplodeOpts defaultOpts = implodeOptions(true, false, false, ["RascalVar", "RascalListVar"]); 34 34 35 35 public XaTree implodeTree(Tree t) { return implodeTree(t, defaultOpts); } … … 138 138 case cf(opt(layout())): { 139 139 l = unparse(ts[i]); 140 if( /^<before:\s*><com:\S(.|\r|\n)*\S><after:\s*>$/ := l) {140 if(false && /^<before:\s*><com:\S(.|\r|\n)*\S><after:\s*>$/ := l) { 141 141 if(before != "") 142 142 cstArgs += layout(before); -
MetaXa/src/gen-tbl
r407 r420 1 LD_LIBRARY_PATH=/home/anya/eclipse/plugins/rascal_fragment_linux_0.1.5/installed/lib/ /home/anya/eclipse/plugins/rascal_fragment_linux_0.1.5/installed/bin/sdf2table -c -m Magnolia -o Magnolia.tbl 1 if [ -d /home/anya/eclipse/ ]; then 2 ECLIPSE=/home/anya/eclipse 3 elif [ -d /usr/local/eclipse/ ]; then 4 ECLIPSE=/usr/local/eclipse 5 fi 6 7 LD_LIBRARY_PATH=$ECLIPSE/plugins/rascal_fragment_linux_0.1.5/installed/lib/ $ECLIPSE/plugins/rascal_fragment_linux_0.1.5/installed/bin/sdf2table -c -m Magnolia -o Magnolia.tbl 8
Note:
See TracChangeset
for help on using the changeset viewer.