Ejemplo n.º 1
0
 public IEnumerable <Token> Tokenize(TextReader textReader)
 {
     using (CharReader reader = new TextReaderCharReader(textReader))
         foreach (Token token in Tokenize(reader))
         {
             yield return(token);
         }
 }
Ejemplo n.º 2
0
        static int StreamInput(TextReader input, Encoding encoding, bool errorsWithStackTrace)
        {
            var builtinTypes = LoadBuiltinTypes();
            var charReader   = new TextReaderCharReader(input);
            var tokenizer    = new Tokenizer(charReader);
            var interpreter  = new DocumentProcessor(tokenizer, builtinTypes, new InstructionInterpreterFactory());

            try
            {
                var namespaces = interpreter.Read();
                var compiler   = new JavascriptCompiler("example", namespaces, builtinTypes);
                foreach (var f in LoadBuiltinFunctions())
                {
                    compiler.AddBuiltinFunction(f);
                }
                using (MemoryStream mem = new MemoryStream())
                    using (StreamWriter memW = new StreamWriter(mem, encoding))
                    {
                        compiler.Compile(memW);
                        memW.Flush();
                        Console.Out.Write(encoding.GetString(mem.ToArray()));
                    }
                return(0);
            }
            catch (SyntaxException ex)
            {
                Console.Error.WriteLine("Syntax error at " + ex.Position);
                Console.Error.WriteLine(ex.Message);
                if (errorsWithStackTrace)
                {
                    Console.Error.WriteLine(ex.StackTrace);
                }
                return(0x101);
            }
            catch (CompileException ex)
            {
                Console.Error.WriteLine("Compile error at " + ex.Position);
                Console.Error.WriteLine(ex.Message);
                if (errorsWithStackTrace)
                {
                    Console.Error.WriteLine(ex.StackTrace);
                }
                return(0x102);
            }
        }