1 package gnu.q2.lang; 2 import gnu.mapping.*; 3 import kawa.standard.Scheme; 4 import gnu.lists.*; 5 import gnu.xml.*; 6 import gnu.expr.*; 7 import gnu.kawa.lispexpr.ReadTable; 8 9 13 14 public class Q2 extends Scheme 15 { 16 static Q2 instance; 17 static final Object emptyForm = new FString(); 18 19 public Q2 () 20 { 21 instance = this; 22 ModuleBody.setMainPrintValues(true); 23 } 24 25 public static Q2 getQ2Instance() 26 { 27 if (instance == null) 28 new Q2 (); 29 return instance; 30 } 31 32 public gnu.text.Lexer getLexer(InPort inp, gnu.text.SourceMessages messages) 33 { 34 Compilation.defaultCallConvention = Compilation.CALL_WITH_CONSUMER; 35 Q2Read lexer = new Q2Read(inp, messages); 36 return lexer; 37 } 38 39 public Consumer getOutputConsumer(java.io.Writer out) 40 { 41 return new XMLPrinter(out, false); 42 } 43 44 45 public static void registerEnvironment() 46 { 47 Language.setDefaults(new Q2()); 48 } 49 50 public Expression makeBody(Expression[] exps) 51 { 52 return new ApplyExp(gnu.kawa.functions.AppendValues.appendValues, exps); 53 } 54 55 public Expression makeApply (Expression func, Expression[] args) 56 { 57 62 Expression[] exps = new Expression[args.length+1]; 63 exps[0] = func; 64 System.arraycopy(args, 0, exps, 1, args.length); 65 return new ApplyExp(Q2Apply.q2Apply, exps); 66 } 67 68 public Procedure getPrompter() 69 { 70 return new Prompter(); 71 } 72 73 public ReadTable createReadTable () 74 { 75 ReadTable rt = ReadTable.createInitial(); 76 rt.set('(', new Q2ReaderParens()); 77 return rt; 78 } 79 } 80 81 class Prompter extends Procedure1 82 { 83 public Object apply1 (Object arg) 84 { 85 InPort port = (InPort) arg; 86 int line = port.getLineNumber() + 1; 87 char state = port.readState; 88 if (state == ']') 89 return "<!--Q2:"+line+"-->"; 90 else 91 { 92 if (state == '\n') 93 state = '-'; 94 return "#|--Q2:"+line+state+"|#"; 95 } 96 } 97 } 98 | Popular Tags |