Esempio n. 1
0
        static void Main(string[] args)
        {
            if(args.Length == 0) {
                Console.WriteLine("Parsing from console...");

                var executionContext = new ExecutionContext();

                while(true) {
                    try {
                        using(var console = Console.OpenStandardInput())
                        using(var reader = new LocatedTextReaderWrapper(console)) {
                            var parser = new Parser(reader);

                            foreach(var node in parser.ReadNodes()) {
                                string output = node.Execute(executionContext);

                                Console.Write(output);
                            }
                        }
                    } catch(Exception e) {
                        Console.WriteLine("Error: " + e);
                    }
                }
            } else {
                watchers = new Dictionary<FileCollectionWatcher, string>();

                foreach(var filename in args) {
                    var watcher = new FileCollectionWatcher();
                    watcher.Changed += FileChanged;
                    watchers[watcher] = filename;

                    ParseFile(watcher, filename);

                    Console.WriteLine("Watching " + filename + " for changes...");
                }

                Thread.Sleep(-1);
            }
        }
Esempio n. 2
0
        private static void ParseFile(FileCollectionWatcher watcher, string filename)
        {
            Console.Write("Parsing " + filename + "...");

            using(var inputFile = File.Open(filename, FileMode.Open, FileAccess.Read))
            using(var outputFile = File.Open(Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)) + ".osb", FileMode.Create, FileAccess.Write)) {
                var executionContext = new ExecutionContext();

                using(var reader = new LocatedTextReaderWrapper(inputFile, new Location(filename)))
                using(var writer = new StreamWriter(outputFile)) {
                    try {
                        var parser = new Parser(reader);

                        foreach(var node in parser.ReadNodes()) {
                            string output = node.Execute(executionContext);

                            writer.Write(output);
                        }

                        watcher.Clear();
                    } catch(Exception e) {
                        Console.WriteLine("\nError: " + e);

                        return;
                    } finally {
                        if(!watcher.Contains(filename)) {
                            watcher.Add(filename);
                        }

                        foreach(string file in executionContext.Dependencies.Where((file) => !watcher.Contains(file))) {
                            watcher.Add(file);
                        }
                    }
                }
            }

            Console.WriteLine("  Done!");
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Encoder"/> class.
 /// </summary>
 /// <param name="parser">The parser.</param>
 /// <param name="context">The execution context.</param>
 public Encoder(Parser parser, ExecutionContext context)
 {
     Parser = parser;
     ExecutionContext = context;
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Encoder"/> class with sensible defaults.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <remarks>The <see cref="Encoder"/> instance created is readily usable with a default <see cref="Parser"/> and <see cref="ExecutionContext"/>.</remarks>
 public Encoder(LocatedTextReaderWrapper reader)
 {
     Parser = new Parser.Parser(reader);
     ExecutionContext = new ExecutionContext();
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Encoder"/> class.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="context">The execution context.</param>
 public Encoder(LocatedTextReaderWrapper reader, ExecutionContext context)
     : this(new Parser(reader), context)
 {
 }