Esempio n. 1
0
        public static Object Read(TextReader textReader, ReadTable readTable, object eofValue)
        {
            int c = textReader.Read();

            if (c == -1)
            {
                // End of file
                return(EOFVALUE);
            }

            while (Char.IsWhiteSpace((Char)c))
            {
                c = textReader.Read();
            }

            Object f = readTable.GetMacroCharacter(c);

            if (f != null)
            {
                return(((ReaderMacro)f)(textReader, readTable));
            }
            else
            {
                return(AtomReader(c, textReader));
            }
        }
Esempio n. 2
0
        public static Object BackQuoteReader(params Object[] args)
        {
            TextReader textReader = (TextReader)args[0];
            ReadTable  readTable  = (ReadTable)args[1];

            return(new Cons(Symbol.FromName("backquote"), new Cons(Read(textReader, readTable, null), null)));
        }
Esempio n. 3
0
        public static object ReadString(string expression, Environment environment)
        {
            ReadTable readTable = (ReadTable)environment.GetValue(Symbol.FromName("*readtable*"));
            object    input     = Reader.Read(new StringReader(expression), readTable);

            return(input);
        }
Esempio n. 4
0
        public static Object ReadString(Cons args, Environment environment)
        {
            ReadTable readTable = (ReadTable)environment.GetValue(Symbol.FromName("*readtable*"));

            TextReader textReader = new StringReader((string)args.First());

            return(Reader.Read(textReader, readTable));
        }
Esempio n. 5
0
        public static Object CharacterReader(params Object[] args)
        {
            TextReader textReader = (TextReader)args[0];
            ReadTable  readTable  = (ReadTable)args[1];

            int c;

            c = textReader.Read();

            return((char)c);
        }
Esempio n. 6
0
        public static Object UnQuoteReader(params Object[] args)
        {
            TextReader textReader = (TextReader)args[0];
            ReadTable  readTable  = (ReadTable)args[1];

            if (textReader.Peek() == '@')
            {
                textReader.Read();
                return(new Cons(Symbol.FromName("splice"), new Cons(Read(textReader, readTable, null), null)));
            }
            return(new Cons(Symbol.FromName("unquote"), new Cons(Read(textReader, readTable, null), null)));
        }
Esempio n. 7
0
        public static Object LineCommentReader(params Object[] args)
        {
            TextReader textReader = (TextReader)args[0];
            ReadTable  readTable  = (ReadTable)args[1];

            int c;

            do
            {
                c = textReader.Read();
            } while (c != -1 && c != '\n' && c != '\r');

            return(Read(textReader, readTable, null));
        }
Esempio n. 8
0
        public static Object Read(Cons args, Environment environment)
        {
            ReadTable readTable = (ReadTable)environment.GetValue(Symbol.FromName("*readtable*"));

            TextReader textReader = args.First() as TextReader;

            object eofValue = Reader.EOFVALUE;

            if (args.Length() > 1)
            {
                eofValue = args.Second();
            }

            return(Reader.Read(textReader, readTable, eofValue));
        }
Esempio n. 9
0
		public static ReadTable DefaultReadTable() 
		{
			ReadTable readTable = new ReadTable();

			readTable.SetMacroCharacter('(',new ReaderMacro(Reader.LParReader));
			readTable.SetMacroCharacter('\"',new ReaderMacro(Reader.StringReader));
			readTable.SetMacroCharacter(';',new ReaderMacro(Reader.LineCommentReader));
			readTable.SetMacroCharacter('#',new ReaderMacro(Reader.DispatchReader));
			readTable.SetMacroCharacter('\'',new ReaderMacro(Reader.QuoteReader));

			readTable.SetMacroCharacter('`',new ReaderMacro(Reader.BackQuoteReader));
			readTable.SetMacroCharacter(',',new ReaderMacro(Reader.UnQuoteReader));
            
			readTable.SetDispatchCharacter('|',new ReaderMacro(Reader.MultiLineCommentReader));
			readTable.SetDispatchCharacter('\\',new ReaderMacro(Reader.CharacterReader));

			return readTable;
		}
Esempio n. 10
0
        public static ReadTable DefaultReadTable()
        {
            ReadTable readTable = new ReadTable();

            readTable.SetMacroCharacter('(', new ReaderMacro(Reader.LParReader));
            readTable.SetMacroCharacter('\"', new ReaderMacro(Reader.StringReader));
            readTable.SetMacroCharacter(';', new ReaderMacro(Reader.LineCommentReader));
            readTable.SetMacroCharacter('#', new ReaderMacro(Reader.DispatchReader));
            readTable.SetMacroCharacter('\'', new ReaderMacro(Reader.QuoteReader));

            readTable.SetMacroCharacter('`', new ReaderMacro(Reader.BackQuoteReader));
            readTable.SetMacroCharacter(',', new ReaderMacro(Reader.UnQuoteReader));

            readTable.SetDispatchCharacter('|', new ReaderMacro(Reader.MultiLineCommentReader));
            readTable.SetDispatchCharacter('\\', new ReaderMacro(Reader.CharacterReader));

            return(readTable);
        }
Esempio n. 11
0
        public static Object DispatchReader(params Object[] args)
        {
            TextReader textReader = (TextReader)args[0];
            ReadTable  readTable  = (ReadTable)args[1];

            int c = textReader.Read();


            Object f = readTable.GetDispatchCharacter(c);

            if (f != null)
            {
                return(((ReaderMacro)f)(textReader, readTable));
            }
            else
            {
                return(AtomReader(c, textReader));
            }
        }
Esempio n. 12
0
		public static ReadTable DefaultReadTable() 
		{
			ReadTable readTable = new ReadTable();

			readTable.SetMacroCharacter('(',new ReaderMacro(Reader.LParReader));
			readTable.SetMacroCharacter('\"',new ReaderMacro(Reader.StringReader));
			readTable.SetMacroCharacter(';',new ReaderMacro(Reader.LineCommentReader));
			readTable.SetMacroCharacter('#',new ReaderMacro(Reader.DispatchReader));
			readTable.SetMacroCharacter('\'',new ReaderMacro(Reader.QuoteReader));

			readTable.SetMacroCharacter('`',new ReaderMacro(Reader.BackQuoteReader));
			readTable.SetMacroCharacter(',',new ReaderMacro(Reader.UnQuoteReader));
            
			readTable.SetDispatchCharacter('|',new ReaderMacro(Reader.MultiLineCommentReader));
			readTable.SetDispatchCharacter('\\',new ReaderMacro(Reader.CharacterReader));

			readTable.SetMacroCharacter('~', new ReaderMacro(Reader.AssemblyDefinitionReader));
			// example: ~namespace=LSharp.ExampleClass1~
			
			return readTable;
		}
Esempio n. 13
0
        public static Object LParReader(params Object[] args)
        {
            TextReader textReader = (TextReader)args[0];
            ReadTable  readTable  = (ReadTable)args[1];
            int        c;


            while (Char.IsWhiteSpace((Char)textReader.Peek()))
            {
                c = textReader.Read();
            }

            object o = Read(textReader, readTable, null);


            if (recdepth < RECURSEDEPTH)
            {
                if (o as Symbol != (Symbol)")")
                {
                    try
                    {
                        recdepth++;
                        if (recdepth > maxdepth)
                        {
                            maxdepth = recdepth;
                        }
                        return(new Cons(o, LParReader(textReader, readTable)));
                    }
                    finally
                    {
                        recdepth--;
                    }
                }
            }
            else
            {
                System.Diagnostics.Trace.WriteLine("Recursion depth reached: " + recdepth);
            }
            return(null);
        }
Esempio n. 14
0
        public static Object Load(Cons args, Environment environment)
        {
            object filename = args.First();

            if (filename is string)
            {
                TextReader textReader = new StreamReader((string)filename);

                string buffer = textReader.ReadToEnd();

                textReader.Close();

                // We want to evaluate the whole file, so there is an implicit do
                // which we now make explicit
                string expression = string.Format("(do {0})", buffer);

                object input  = Reader.Read(new StringReader(expression), ReadTable.DefaultReadTable());
                object output = Runtime.Eval(input, environment);

                return(output);
            }
            throw new LSharpException(String.Format("Using: {0} is not a string", filename));
        }
Esempio n. 15
0
        public void InitialiseLSharpBindings()
        {
            isresetting = true;

            foreach (Extension e in extensions)
            {
                InitSymbols(e.type, e.delegatetype);
                extmark++;
            }

            // leppie: should this not be Assign() ?
            // read table
            Assign(Symbol.FromName("*readtable*"), ReadTable.DefaultReadTable());

            // Macros
            foreach (Type t in macroextensions)
            {
                InitMacros(t);
            }


            isresetting = false;
        }
Esempio n. 16
0
		public static Object Read(TextReader textReader, ReadTable readTable) 
		{
			return Read(textReader, readTable, null);
		}
Esempio n. 17
0
		public static Object Read(TextReader textReader, ReadTable readTable, object eofValue) 
		{
			int c = textReader.Read();


			while (Char.IsWhiteSpace((Char)c)) 
			{
				c = textReader.Read();
			}

			if (c == -1) 
			{
				// End of file
				return eofValue;
			}

			Object f = readTable.GetMacroCharacter(c);

			if (f != null) 
			{
				return ((ReaderMacro) f)(textReader, readTable);
			} 
			else 
			{
				return AtomReader(c, textReader);
			}
		}
Esempio n. 18
0
 public static Object Read(TextReader textReader, ReadTable readTable)
 {
     return(Read(textReader, readTable, EOFVALUE));
 }