01: package gnu.q2.lang;
02:
03: import gnu.mapping.*;
04: import kawa.standard.Scheme;
05: import gnu.lists.*;
06: import gnu.xml.*;
07: import gnu.expr.*;
08: import gnu.kawa.lispexpr.ReadTable;
09:
10: /** Support for the experimental Q2 language.
11: * See the <a href="http://www.gnu.org/software/kawa/q2/">web site</a>
12: * for information.
13: */
14:
15: public class Q2 extends Scheme {
16: static Q2 instance;
17: static final Object emptyForm = new FString();
18:
19: public Q2() {
20: instance = this ;
21: ModuleBody.setMainPrintValues(true);
22: }
23:
24: public static Q2 getQ2Instance() {
25: if (instance == null)
26: new Q2();
27: return instance;
28: }
29:
30: public gnu.text.Lexer getLexer(InPort inp,
31: gnu.text.SourceMessages messages) {
32: Compilation.defaultCallConvention = Compilation.CALL_WITH_CONSUMER;
33: Q2Read lexer = new Q2Read(inp, messages);
34: return lexer;
35: }
36:
37: public Consumer getOutputConsumer(java.io.Writer out) {
38: return new XMLPrinter(out, false);
39: }
40:
41: /** The compiler insert calls to this method for applications and applets. */
42: public static void registerEnvironment() {
43: Language.setDefaults(new Q2());
44: }
45:
46: public Expression makeBody(Expression[] exps) {
47: return new ApplyExp(
48: gnu.kawa.functions.AppendValues.appendValues, exps);
49: }
50:
51: public Expression makeApply(Expression func, Expression[] args) {
52: /*
53: if (func instanceof QuoteExp
54: && ((QuoteExp) func).getValue() instanceof Procedure)
55: return super.makeApply(func, args);
56: */
57: Expression[] exps = new Expression[args.length + 1];
58: exps[0] = func;
59: System.arraycopy(args, 0, exps, 1, args.length);
60: return new ApplyExp(Q2Apply.q2Apply, exps);
61: }
62:
63: public Procedure getPrompter() {
64: return new Prompter();
65: }
66:
67: public ReadTable createReadTable() {
68: ReadTable rt = ReadTable.createInitial();
69: rt.set('(', new Q2ReaderParens());
70: return rt;
71: }
72: }
73:
74: class Prompter extends Procedure1 {
75: public Object apply1(Object arg) {
76: InPort port = (InPort) arg;
77: int line = port.getLineNumber() + 1;
78: char state = port.readState;
79: if (state == ']')
80: return "<!--Q2:" + line + "-->";
81: else {
82: if (state == '\n')
83: state = '-';
84: return "#|--Q2:" + line + state + "|#";
85: }
86: }
87: }
|