1 package gnu.kawa.brl;
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.io.InPort;
8 import gnu.kawa.lispexpr.ReadTable;
9 
10 public class BRL extends Scheme
11 {
12   // The following two fields need to be public so that the findLiteral
13   // method in gnu.expr.LitTable can find them.
14   /** Language instance for KRL dialect. */
15   public static final BRL krl_instance;
16   /** Language instance for BRL dialect. */
17   public static final BRL brl_instance;
18   static final Object emptyForm = new FString();
19 
20   protected static final SimpleEnvironment brlEnvironment
21     = Environment.make("brl-environment", Scheme.kawaEnvironment);
22 
23   static BRLReaderString brlReader =  new BRLReaderString();
24 
25   static
26   {
27     krl_instance = new BRL(brlEnvironment);
28     brl_instance = new BRL(brlEnvironment);
29     brl_instance.setBrlCompatible(true);
30     Environment saveEnv = Environment.setSaveCurrent(brlEnvironment);
31     try
32       {
krl_instance.initBRL()33         krl_instance.initBRL();
34       }
35     finally
36       {
37         Environment.restoreCurrent(saveEnv);
38       }
39   }
40 
BRL(Environment env)41   protected BRL (Environment env)
42   {
43     super(env);
44   }
45 
initBRL()46   void initBRL ()
47   {
48     ModuleBody.setMainPrintValues(true);
49     try
50       {
51 	loadClass("gnu.brl.stringfun");
52 	loadClass("gnu.kawa.brl.progfun");
53 	loadClass("gnu.kawa.servlet.HTTP");
54       }
55     catch (Exception ex)
56       {
57 	System.err.println("caught "+ex);
58       }
59   }
60 
getInstance(boolean brlCompatible)61   public static Language getInstance(boolean brlCompatible)
62   {
63     return brlCompatible ? getBrlInstance() : getBrlInstance();
64   }
65 
getKrlInstance()66   public static BRL getKrlInstance()
67   {
68     return krl_instance;
69   }
70 
getBrlInstance()71   public static BRL getBrlInstance()
72   {
73     return brl_instance;
74   }
75 
76   boolean brlCompatible = false;
77 
isBrlCompatible()78   public boolean isBrlCompatible() { return brlCompatible; }
setBrlCompatible(boolean compat)79   public void setBrlCompatible(boolean compat) {  brlCompatible = compat; }
80 
appendBodyValues()81   public boolean appendBodyValues () { return ! isBrlCompatible(); }
82 
getLexer(InPort inp, gnu.text.SourceMessages messages)83   public gnu.kawa.lispexpr.LispReader getLexer(InPort inp, gnu.text.SourceMessages messages)
84   {
85     Compilation.defaultCallConvention = Compilation.CALL_WITH_CONSUMER;
86     BRLRead lexer = new BRLRead(inp, messages);
87     lexer.setBrlCompatible(isBrlCompatible());
88     return lexer;
89   }
90 
getOutputConsumer(java.io.Writer out)91   public Consumer getOutputConsumer(java.io.Writer out)
92   {
93     if (isBrlCompatible())
94       return super.getOutputConsumer(out);
95     return new XMLPrinter(out, false);
96   }
97 
98   /** The compiler insert calls to this method for applications and applets. */
registerEnvironment()99   public static void registerEnvironment()
100   {
101     Language.setDefaults(getKrlInstance());
102   }
103 
createReadTable()104   public ReadTable createReadTable ()
105   {
106     ReadTable rt = super.createReadTable();
107     if (isBrlCompatible())
108       rt.setInitialColonIsKeyword(true);
109     rt.setBracketMode(1);
110     rt.set(']', brlReader);
111     return rt;
112   }
113 
114     @Override
getPrimaryPrompt()115     public String getPrimaryPrompt() { return "<!--BRL:%N-->"; }
116 
117     @Override
getSecondaryPrompt()118     public String getSecondaryPrompt() { return  "<!--%P.:%N-->"; }
119 }
120 
121