source: branches/1.1.x/src/org/armedbear/lisp/FaslReadtable.java

Last change on this file was 13187, checked in by ehuelsmann, 14 years ago

Fix #125: FASL reader should not convert symbol case [Qi FASL loading issues].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1/*
2 * FaslReadtable.java
3 *
4 * Copyright (C) 2005 Peter Graves
5 * $Id: FaslReadtable.java 13187 2011-01-27 21:08:52Z ehuelsmann $
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 *
21 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36public final class FaslReadtable extends Readtable
37{
38    public FaslReadtable()
39    {
40        super();
41    }
42
43    @Override
44    protected void initialize()
45    {
46      Byte[] syntax = this.syntax.constants;
47        syntax[9]    = SYNTAX_TYPE_WHITESPACE; // tab
48        syntax[10]   = SYNTAX_TYPE_WHITESPACE; // linefeed
49        syntax[12]   = SYNTAX_TYPE_WHITESPACE; // form feed
50        syntax[13]   = SYNTAX_TYPE_WHITESPACE; // return
51        syntax[' ']  = SYNTAX_TYPE_WHITESPACE;
52
53        syntax['"']  = SYNTAX_TYPE_TERMINATING_MACRO;
54        syntax['\''] = SYNTAX_TYPE_TERMINATING_MACRO;
55        syntax['(']  = SYNTAX_TYPE_TERMINATING_MACRO;
56        syntax[')']  = SYNTAX_TYPE_TERMINATING_MACRO;
57        syntax[',']  = SYNTAX_TYPE_TERMINATING_MACRO;
58        syntax[';']  = SYNTAX_TYPE_TERMINATING_MACRO;
59        syntax['`']  = SYNTAX_TYPE_TERMINATING_MACRO;
60
61        syntax['#']  = SYNTAX_TYPE_NON_TERMINATING_MACRO;
62
63        syntax['\\'] = SYNTAX_TYPE_SINGLE_ESCAPE;
64        syntax['|']  = SYNTAX_TYPE_MULTIPLE_ESCAPE;
65
66        LispObject[] readerMacroFunctions = this.readerMacroFunctions.constants;
67        readerMacroFunctions[';']  = LispReader.READ_COMMENT;
68        readerMacroFunctions['"']  = FaslReader.FASL_READ_STRING;
69        readerMacroFunctions['(']  = FaslReader.FASL_READ_LIST;
70        readerMacroFunctions[')']  = LispReader.READ_RIGHT_PAREN;
71        readerMacroFunctions['\''] = FaslReader.FASL_READ_QUOTE;
72        readerMacroFunctions['#']  = FaslReader.FASL_READ_DISPATCH_CHAR;
73
74        // BACKQUOTE-MACRO and COMMA-MACRO are defined in backquote.lisp.
75        readerMacroFunctions['`']  = Symbol.BACKQUOTE_MACRO;
76        readerMacroFunctions[',']  = Symbol.COMMA_MACRO;
77
78        DispatchTable dt = new DispatchTable();
79        LispObject[] dtfunctions = dt.functions.constants;
80        dtfunctions['(']  = FaslReader.FASL_SHARP_LEFT_PAREN;
81        dtfunctions['*']  = FaslReader.FASL_SHARP_STAR;
82        dtfunctions['.']  = FaslReader.FASL_SHARP_DOT;
83        dtfunctions[':']  = FaslReader.FASL_SHARP_COLON;
84        dtfunctions['A']  = FaslReader.FASL_SHARP_A;
85        dtfunctions['B']  = FaslReader.FASL_SHARP_B;
86        dtfunctions['C']  = FaslReader.FASL_SHARP_C;
87        dtfunctions['O']  = FaslReader.FASL_SHARP_O;
88        dtfunctions['P']  = FaslReader.FASL_SHARP_P;
89        dtfunctions['R']  = FaslReader.FASL_SHARP_R;
90        dtfunctions['S']  = FaslReader.FASL_SHARP_S;
91        dtfunctions['X']  = FaslReader.FASL_SHARP_X;
92        dtfunctions['\''] = FaslReader.FASL_SHARP_QUOTE;
93        dtfunctions['\\'] = FaslReader.FASL_SHARP_BACKSLASH;
94        dtfunctions['|']  = LispReader.SHARP_VERTICAL_BAR;
95        dtfunctions[')']  = LispReader.SHARP_ILLEGAL;
96        dtfunctions['<']  = LispReader.SHARP_ILLEGAL;
97        dtfunctions[' ']  = LispReader.SHARP_ILLEGAL;
98        dtfunctions[8]    = LispReader.SHARP_ILLEGAL; // backspace
99        dtfunctions[9]    = LispReader.SHARP_ILLEGAL; // tab
100        dtfunctions[10]   = LispReader.SHARP_ILLEGAL; // newline, linefeed
101        dtfunctions[12]   = LispReader.SHARP_ILLEGAL; // page
102        dtfunctions[13]   = LispReader.SHARP_ILLEGAL; // return
103        dtfunctions['?']  = FaslReader.FASL_SHARP_QUESTION_MARK;
104        dispatchTables.constants['#'] = dt;
105
106        readtableCase = Keyword.PRESERVE;
107        // after all, all symbols will have been uppercased by the reader,
108        // if applicable, when reading the source file; so, any lower-case
109        // symbols are really meant to be lower case, even if printed without
110        // pipe characters, which may happen if  the READTABLE-CASE of the
111        // current readtable is :PRESERVE when printing the symbols
112    }
113
114    private static final FaslReadtable instance = new FaslReadtable();
115
116    public static final FaslReadtable getInstance()
117    {
118        return instance;
119    }
120}
Note: See TracBrowser for help on using the repository browser.