Changeset 422
- Timestamp:
- Jun 12, 2010 11:07:43 PM (14 years ago)
- Location:
- MetaXa/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
MetaXa/src/MagnoliaCxxBack.rsc
r379 r422 6 6 public XaTree cxxFormat(XaTree tree) { 7 7 return visit(tree) { 8 case d: cons("Param", [ID, TYPE], s) => d[@concrete=[token("const"), layout(" "), child(1), token("&"), layout(" "), child(0)]]8 case d: cons("Param", [ID, TYPE], s) => d[@concrete=[token("const"), space(" "), child(1), token("&"), space(" "), child(0)]] 9 9 case d: cons("FunClause", [NAME, ARGS, TYPE], s) => 10 d[@concrete = [child(2), layout(" "), child(0), child(1)]]10 d[@concrete = [child(2), space(" "), child(0), child(1)]] 11 11 // case d: cons("PredClause", [NAME, ARGS], s) => 12 // d[@concrete = [token("predicate"), layout(" "), child(0), token("("), child(1), token(")")]]12 // d[@concrete = [token("predicate"), space(" "), child(0), token("("), child(1), token(")")]] 13 13 // case d: cons("AxiomClause", [NAME, ARGS], s) => 14 // d[@concrete = [token("axiom"), layout(" "), child(0), token("("), child(1), token(")")]]14 // d[@concrete = [token("axiom"), space(" "), child(0), token("("), child(1), token(")")]] 15 15 case d: cons("ProcClause", [NAME, ARGS], s) => 16 d[@concrete = [token("void"), layout(" "), child(0), child(1)]]16 d[@concrete = [token("void"), space(" "), child(0), child(1)]] 17 17 case d: cons("TypeClause", [NAME], s) => 18 d[@concrete = [token("struct"), layout(" "), child(0)]]18 d[@concrete = [token("struct"), space(" "), child(0)]] 19 19 case d: cons("VarClause", [NAME, TYPE], s) => 20 d[@concrete = [child(1), layout(" "), child(0)]]20 d[@concrete = [child(1), space(" "), child(0)]] 21 21 case n: cons("Name",[leaf(op, "ID")], "Identifier"): 22 22 if([opname] := getOpName(op)) -
MetaXa/src/MetaXa.rsc
r396 r422 120 120 } 121 121 default: 122 println("Unknown section '<S>'");122 println("Unknown section \'<S>\'"); 123 123 } 124 124 } … … 168 168 169 169 /** Compile a list of sugar definitions to Rascal desugar/ensugar rules */ 170 public str compileSugar(list[Tree] ss, str lang , bool concrete, str to, str from) {170 public str compileSugar(list[Tree] ss, str language, bool concrete, str to, str from) { 171 171 str treeType = concrete ? "Tree" : "XaTree"; 172 str desugar = "/** Returns a desugared tree. */\npublic <treeType> <to><lang >(<treeType> tree) {\n\treturn visit(tree) {\n";173 str ensugar = "/** Returns an ensugared tree. */\npublic <treeType> <from><lang >(<treeType> tree) {\n\treturn visit(tree) {\n";172 str desugar = "/** Returns a desugared tree. */\npublic <treeType> <to><language>(<treeType> tree) {\n\treturn visit(tree) {\n"; 173 str ensugar = "/** Returns an ensugared tree. */\npublic <treeType> <from><language>(<treeType> tree) {\n\treturn visit(tree) {\n"; 174 174 str sdf = ""; 175 175 int ruleCount = 0; … … 257 257 return; 258 258 else 259 throw UnboundVariable("Unbound variables in rule '<r>'", ["<v>" | v <- rhsVars-lhsVars]);259 throw UnboundVariable("Unbound variables in rule \'<r>\'", ["<v>" | v <- rhsVars-lhsVars]); 260 260 } 261 261 else if(arrow == "\<-") { … … 263 263 return; 264 264 else 265 throw UnboundVariable("Unbound variables in rule '<r>'", ["<v>" | v <- rhsVars-lhsVars]);265 throw UnboundVariable("Unbound variables in rule \'<r>\'", ["<v>" | v <- rhsVars-lhsVars]); 266 266 } 267 267 else 268 throw UnboundVariable("Unbound variables in rule '<r>'", ["<v>" | v <- (lhsVars-rhsVars)+(rhsVars-lhsVars)]);268 throw UnboundVariable("Unbound variables in rule \'<r>\'", ["<v>" | v <- (lhsVars-rhsVars)+(rhsVars-lhsVars)]); 269 269 } 270 270 … … 313 313 for(Tree t <- ts) { 314 314 //if(i > 0) 315 // ss += [ layout(" ")];315 // ss += [space(" ")]; 316 316 switch(t) { 317 317 case (MXaToken)`<VarToken v>`: { ss += [child(i)]; i += 1; } … … 319 319 case (MXaToken)`"<MXaSYMBOL s>"`: ss += [token("<s>")]; 320 320 case MXaToken _: ss += [token("<t>")]; 321 default: ss += [ layout("<t>")];321 default: ss += [space("<t>")]; 322 322 } 323 323 } -
MetaXa/src/RascalAbstractBackend.rsc
r392 r422 16 16 return ""; // "public " + rt + " " + n + "(" + strJoin([p | p <- ps], ", ") + ");"; 17 17 default: 18 throw IllegalASTFormat("Don 't know what to do with decl '<d>'");18 throw IllegalASTFormat("Don\'t know what to do with decl \'<d>\'"); 19 19 } 20 20 } … … 48 48 return "throw Failure();\n"; 49 49 default: 50 throw IllegalASTFormat("Don 't know what to do with clause '<s>'");50 throw IllegalASTFormat("Don\'t know what to do with clause \'<s>\'"); 51 51 } 52 52 } … … 77 77 return "[" + pp(r) + " | " + pp(v) + " \<- " + s + "]"; 78 78 default: 79 throw IllegalASTFormat("Don 't know what to do with expr '<e>'");79 throw IllegalASTFormat("Don\'t know what to do with expr \'<e>\'"); 80 80 } 81 81 } -
MetaXa/src/RascalBackend.rsc
r360 r422 15 15 return ""; // "public " + rt + " " + n + "(" + strJoin([p | p <- ps], ", ") + ");"; 16 16 default: 17 throw IllegalASTFormat("Don 't know what to do with decl '<d>'");17 throw IllegalASTFormat("Don\'t know what to do with decl \'<d>\'"); 18 18 } 19 19 } … … 47 47 return "throw Failure();\n"; 48 48 default: 49 throw IllegalASTFormat("Don 't know what to do with clause '<s>'");49 throw IllegalASTFormat("Don\'t know what to do with clause \'<s>\'"); 50 50 } 51 51 } … … 76 76 return "[" + pp(r) + " | " + pp(v) + " \<- " + s + "]"; 77 77 default: 78 throw IllegalASTFormat("Don 't know what to do with expr '<e>'");78 throw IllegalASTFormat("Don\'t know what to do with expr \'<e>\'"); 79 79 } 80 80 } -
MetaXa/src/XaLib.rsc
r413 r422 127 127 assert notAmb(t); 128 128 for(i <- [0 .. size(t.prod.lhs)]) 129 if(cf(opt( layout())) := t.prod.lhs[i])129 if(cf(opt(\layout())) := t.prod.lhs[i]) 130 130 ; 131 131 else if(cf(_) := t.prod.lhs[i]) { … … 172 172 173 173 public str varRename(str n) { 174 return replaceAll(n, " '", "_");174 return replaceAll(n, "\'", "_"); 175 175 } 176 176 … … 182 182 183 183 public str varUnrename(str n) { 184 return replaceAll(n, "_", " '");184 return replaceAll(n, "_", "\'"); 185 185 } 186 186 … … 243 243 } 244 244 a = getOneFrom(alts); 245 println(" In sentence: '<a>'");245 println(" In sentence: \'<a>\'"); 246 246 return false; 247 247 } -
MetaXa/src/XaRules.rsc
r396 r422 15 15 16 16 visit(rules) { 17 case cf(sort(s)):17 case \cf(sort(s)): 18 18 sorts += {s}; 19 19 } … … 25 25 case (MXaOpDecl)`<NAME>: <{MXaType ","}* TYPES> -> <TYPE>`: 26 26 rs += opDecl("<NAME>", "<TYPE>", ["<t>" | t <- TYPES]); 27 case appl(prod(_, cf(opt(layout())),_),_):27 case appl(prod(_,\cf(opt(\layout())),_),_): 28 28 ; 29 29 default: … … 94 94 case appl(prod(_,lit(_),_),_): 95 95 ; 96 case appl(prod(_, cf(opt(layout())),_),_):96 case appl(prod(_,\cf(opt(\layout())),_),_): 97 97 ; 98 98 default: … … 120 120 } 121 121 case ruleDef(ps,c): { 122 throw IllegalASTFormat("Don 't know what to do with rule conclusion <c>");122 throw IllegalASTFormat("Don\'t know what to do with rule conclusion <c>"); 123 123 } 124 124 } … … 299 299 return c1; 300 300 default: 301 throw IllegalASTFormat("Don 't know what to do with <d>");301 throw IllegalASTFormat("Don\'t know what to do with <d>"); 302 302 } 303 303 } … … 352 352 } 353 353 else 354 throw IllegalASTFormat("Don 't know what to do with <d>");354 throw IllegalASTFormat("Don\'t know what to do with <d>"); 355 355 } 356 356 … … 362 362 363 363 if(!typeEq(ptype, etype, ())[0]) 364 println("Pattern type doesn 't match expression: <ptype> := <etype> in <pat> := <expr>");364 println("Pattern type doesn\'t match expression: <ptype> := <etype> in <pat> := <expr>"); 365 365 366 366 env1 = env + envOf(pat); … … 404 404 return <failure(), "?">; 405 405 default: 406 throw IllegalASTFormat("Don 't know what to do with clause <c>");406 throw IllegalASTFormat("Don\'t know what to do with clause <c>"); 407 407 } 408 408 } … … 426 426 } 427 427 default: 428 throw IllegalASTFormat("Don 't know what to do with expr <e>");428 throw IllegalASTFormat("Don\'t know what to do with expr <e>"); 429 429 430 430 } … … 461 461 } 462 462 default: 463 throw IllegalASTFormat("Don 't know what to do with expr <e>");463 throw IllegalASTFormat("Don\'t know what to do with expr <e>"); 464 464 } 465 465 } -
MetaXa/src/XaTree.rsc
r420 r422 20 20 data XaToken = 21 21 token(str chars) // a literal 22 | layout(str chars) // whitespace22 | space(str chars) // whitespace 23 23 | comment(str chars) // non-whitespace layout 24 24 | child(int index); // reference to child node … … 40 40 switch(t) { 41 41 // leaf nodes 42 case appl(prod([\lex(_)],cf(s), _), args): {42 case \appl(\prod([\lex(_)], \cf(s), _), args): { 43 43 result = leaf(unparse(args[0]), sortName(s)); 44 44 concrete = [token(unparse(args[0]))]; … … 46 46 // injection 47 47 // TODO: should deal with attributes 48 case appl(prod([cf(_)],cf(s), \no-attrs()), args): {48 case \appl(\prod([\cf(_)], \cf(s), \no-attrs()), args): { 49 49 result = implodeTree(args[0], opts); 50 50 if(!opts.foldInjections) { … … 54 54 } 55 55 // an injection which gets the type of the outer production 56 case appl(prod([cf(_)], cf(s), attrs([_*,term(abstract()),_*])), args): {56 case \appl(\prod([\cf(_)], \cf(s), \attrs([_*,\term(\abstract()),_*])), args): { 57 57 result = implodeTree(args[0], opts); 58 58 if(opts.foldInjections) … … 64 64 } 65 65 // alternative choice 66 case appl(prod(_, cf(alt(_,_)), _), [arg]): {66 case \appl(\prod(_, \cf(\alt(_,_)), _), [arg]): { 67 67 return implodeTree(arg, opts); 68 68 } 69 69 // option -- none 70 case appl(prod([], cf(opt(s)), _), []): {70 case \appl(\prod([], \cf(\opt(s)), _), []): { 71 71 result = seq([], sortName(s)); 72 72 concrete = []; 73 73 } 74 74 // option -- some 75 case appl(prod([_], cf(opt(s)), _), [arg]): {75 case \appl(\prod([_], \cf(\opt(s)), _), [arg]): { 76 76 result = seq([implodeTree(arg, opts)], sortName(s)); 77 77 concrete = [child(0)]; 78 78 } 79 79 // normal node 80 case appl(prod(lhs,cf(s),_), args): {80 case \appl(\prod(\lhs,\cf(s),_), args): { 81 81 name = consOf(t) ? sortName(s); 82 82 if(name in opts.varConses) { … … 94 94 } 95 95 // list/sequence 96 case appl(list(s), args): {96 case \appl(\list(s), args): { 97 97 <astArgs, concrete> = implodeArgList(args); 98 98 result = seq(astArgs, sortOfList(s)); … … 100 100 // ambiguity 101 101 // TODO: don't use println for reporting 102 case amb(alts): {102 case \amb(alts): { 103 103 println("Ambiguity detected:"); 104 104 for(a <- alts) { … … 106 106 } 107 107 a = getOneFrom(alts); 108 println(" In sentence: '<a>'");108 println(" In sentence: \'<a>\'"); 109 109 println(" Proceeding with:\n <a.prod.rhs> ::= <a.prod.lhs ? a.prod>"); 110 110 result = implodeTree(getOneFrom(alts), opts); … … 136 136 try { 137 137 switch(ts[i].prod.rhs ? []) { 138 case cf(opt(layout())): {138 case \cf(opt(\layout())): { 139 139 l = unparse(ts[i]); 140 140 if(false && /^<before:\s*><com:\S(.|\r|\n)*\S><after:\s*>$/ := l) { 141 141 if(before != "") 142 cstArgs += layout(before);142 cstArgs += space(before); 143 143 if(com != "") 144 144 cstArgs += comment(com); 145 145 if(after != "") 146 cstArgs += layout(after);146 cstArgs += space(after); 147 147 } 148 148 else 149 cstArgs += layout(l);149 cstArgs += space(l); 150 150 } 151 151 case lit(_): … … 174 174 return toTerm(a); 175 175 case leaf(l, _): 176 return " '" + l + "'";176 return "\'" + l + "\'"; 177 177 } 178 178 } … … 196 196 case token(t): 197 197 result += t; 198 case layout(l):198 case space(l): 199 199 result += l; 200 200 case comment(c): … … 233 233 return <tree, substring(l, 0, 1) ? "", substring(l, size(l)-1) ? lastChar>; 234 234 default: 235 tree@concrete = [x | x <- tree@concrete, layout(_) !:= x];235 tree@concrete = [x | x <- tree@concrete, space(_) !:= x]; 236 236 } 237 237 … … 243 243 for(tok <- tree@concrete) { 244 244 if(concPat != []) 245 space = [ layout(" ")];245 space = [space(" ")]; 246 246 if(lastChar == "\n") { 247 247 if(indent != "") 248 concPat += [ layout(indent)];248 concPat += [space(indent)]; 249 249 space = []; 250 250 lastChar = "\t"; … … 256 256 257 257 switch(tok) { 258 case layout(l):258 case space(l): 259 259 space = []; 260 260 case comment(c): { 261 261 firstChar = firstChar ? "#"; 262 262 chars += "#"; 263 toks += layout("\n");263 toks += space("\n"); 264 264 lastChar = "\n"; 265 265 } … … 280 280 if(seq(_,s) := tree.args[i] && s in vertSorts) { 281 281 if(s in sectSorts) 282 toks = [ layout("\n"), tok];282 toks = [space("\n"), tok]; 283 283 <tree.args[i], fc, lastChar> = reindent(tree.args[i], indent + "\t", lastChar); 284 284 } 285 285 else if(cons(_,_,s) := tree.args[i] && s in vertSorts) { 286 286 if(lastChar != "\t") { // add newline and indent 287 toks = [ layout((lastChar == "\n") ? indent : "\n" + indent), tok];287 toks = [space((lastChar == "\n") ? indent : "\n" + indent), tok]; 288 288 space = []; 289 289 } 290 290 <tree.args[i], fc, _> = reindent(tree.args[i], indent, "\t"); 291 toks += layout("\n");291 toks += space("\n"); 292 292 if(s in sectSorts) 293 toks += layout("\n");293 toks += space("\n"); 294 294 lastChar = "\n"; 295 295 }
Note:
See TracChangeset
for help on using the changeset viewer.