public void factory_should_throw_exception_if_arguments_are_invalid()
 {
     var factory = new ParserFactory();
     var contacts = string.Empty;
     Assert.Throws(typeof(ArgumentNullException),
                   () => factory.Create(contacts, null));
 }
Exemplo n.º 2
0
		/// <summary>
		/// The entry point method.
		/// </summary>
		/// <param name="args">The command line arguments.</param>
		private static void Main(string[] args)
		{
			var pargs = ProgramArguments.Parse(args);

			Contract.Assert(pargs.ParseTablePath != null);

			var termFactory = new TrivialTermFactory();

			var productionFormat = new TermProductionFormat(termFactory);

			var parserFactory = new ParserFactory(
				new SpoofaxParseTableFormat(termFactory, productionFormat),
				new TrivialParseNodeFactory(),
				new AsFixTreeBuilder(termFactory, productionFormat));
			
			var parser = parserFactory.Create(pargs.ParseTablePath);
			
			ITerm ast;
			using (var reader = new StreamReader(FileExt.OpenInput(pargs.InputPath)))
			{
				ast = parser.Parse(reader);
			}

			// TODO: Print the ast.


			Program.trace.TraceData(TraceEventType.Information, 0, ast);
		}
 public void factory_should_return_string_parser_if_contacts_are_passed_in()
 {
     var factory = new ParserFactory();
     var contacts = "*****@*****.**";
     var parser = factory.Create(contacts, null);
     Assert.IsInstanceOfType(typeof(StringParser), parser,
                             "Wrong parser type returned");
 }
Exemplo n.º 4
0
        public Parser(ParserFactory parserFactory)
        {
            this.parser = parserFactory.Create();
            this.store = new DefaultGraphStore();
            this.locations = new Dictionary<object, SourceSpan>();
            this.parser.GraphBuilder = new NodeGraphBuilder(store);

            this.parser.SyntaxMatched += new EventHandler<SyntaxMatchedEventArgs>(parser_SyntaxMatched);
        }
 public void factory_should_throw_exception_if_file_format_is_not_supported()
 {
     var factory = new ParserFactory();
     var contacts = string.Empty;
     var mockUploadedTextFile = new Mock<HttpPostedFileBase>();
     mockUploadedTextFile.Expect(f => f.FileName).Returns("textfile.xls");
     Assert.Throws(typeof(NotImplementedException),
                   () => factory.Create(contacts, mockUploadedTextFile.Object));
 }
 public void factory_should_return_text_file_parser_for_uploaded_text_files()
 {
     var factory = new ParserFactory();
     var contacts = string.Empty;
     var mockUploadedTextFile = new Mock<HttpPostedFileBase>();
     mockUploadedTextFile.Expect(f => f.FileName).Returns("textfile.txt");
     var parser = factory.Create(contacts, mockUploadedTextFile.Object);
     Assert.IsInstanceOfType(typeof(TextFileParser), parser,
                             "Wrong parser type returned");
 }
 /// <summary>
 /// Create a deserializer instance for specified type
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 public Deserializer(Type type)
     : this(type, ParserFactory <R> .Create(type))
 {
 }
Exemplo n.º 8
0
 public void Create_Parser_Incorrect_Type_Should_ArgumentException()
 {
     Assert.ThrowsException <ArgumentException>(() => ParserFactory.Create((ParserType)999));
 }
Exemplo n.º 9
0
        public void Create_TrxParser_Should_Be_Created()
        {
            var parser = ParserFactory.Create(ParserType.Trx);

            Assert.IsTrue(parser is TrxBuildResultParser);
        }
Exemplo n.º 10
0
 public Transcoder(Type type)
     : this(type, ParserFactory <R> .Create(type))
 {
 }
Exemplo n.º 11
0
 public Transcoder(RuntimeSchema schema)
     : this(schema, ParserFactory <R> .Create(schema))
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Create a deserializer instance for specified type, using a custom object factory
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="factory">Factory to create objects during deserialization</param>
 public Deserializer(Type type, IFactory factory)
     : this(type, ParserFactory <R> .Create(type), factory, inlineNested : true)
 {
 }
Exemplo n.º 13
0
 private static IParser CreateSharpParser(string fileName)
 {
     return(ParserFactory.Create(OpenSharpModel(fileName)));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Create a deserializer instance for specified type, using a custom object factory
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="factory">Factory providing expressions to create objects during deserialization</param>
 /// <param name="inlineNested">Inline nested types if possible (optimizes for reduction of execution time
 /// at the expense of initialization time and memory)</param>
 public Deserializer(Type type, Factory factory, bool inlineNested)
     : this(type, ParserFactory <R> .Create(type), null, factory, inlineNested)
 {
 }
Exemplo n.º 15
0
 public Transcoder <R, W> Transcoder <R, W>(RuntimeSchema schema)
 {
     return(new Transcoder <R, W>(schema, ParserFactory <R> .Create(schema, PayloadBondedFactory)));
 }
 /// <summary>
 /// Create a deserializer instance for specified type and payload schema
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="schema">Schema of the payload</param>
 public Deserializer(Type type, RuntimeSchema schema)
     : this(type, ParserFactory <R> .Create(schema))
 {
 }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            var solutionFiles =
                Directory.EnumerateFiles(".", "*.sln", SearchOption.TopDirectoryOnly).ToArray();

            if (1 != solutionFiles.Length)
            {
                Error("Needs to be run from a directory with exactly one *.sln file in it.");
            }
            var solutionPath = Path.GetFullPath(solutionFiles.First());

            switch (parseCommandLine())
            {
            case (_, HelpResult help):
                Console.WriteLine(help.Text);
                Environment.Exit(help.IsResultOfInvalidInput ? -1 : 0);
                break;

            case (var helpOverview, Configuration configuration):
                if (configuration.OldProjectName.Any(CommonExtensions.IsDirectorySeparator))
                {
                    Error(
                        $"Do not specify paths for input/'old' project names, please.{Environment.NewLine}{Environment.NewLine}{helpOverview}");
                }

                configuration.OldProjectName = removeProjectFileExtension(configuration.OldProjectName);
                configuration.NewProjectName = removeProjectFileExtension(configuration.NewProjectName);

                new Application(configuration, solutionPath).Run();
                break;

            default:
                Error(
                    "Something went seriously wrong. Please create an issue at https://github.com/ModernRonin/ProjectRenamer with as much detail as possible.");
                break;
            }

            (string, object) parseCommandLine()
            {
                var parser = ParserFactory.Create("renameproject",
                                                  "Rename C# projects comfortably, including renaming directories, updating references, keeping your git history intact, creating a git commit and updating paket, if needed.");
                var cfg = parser.DefaultVerb <Configuration>();

                cfg.Parameter(c => c.DontCreateCommit)
                .WithLongName("no-commit")
                .WithShortName("nc")
                .WithHelp("don't create a commit after renaming has finished");
                cfg.Parameter(c => c.DoRunBuild)
                .WithLongName("build")
                .WithShortName("b")
                .WithHelp(
                    "run a build after renaming (but before committing) to make sure everything worked fine.");
                cfg.Parameter(c => c.DontRunPaketInstall)
                .WithLongName("no-paket")
                .WithShortName("np")
                .WithHelp("don't run paket install (if your solution uses paket as a local tool)");
                cfg.Parameter(c => c.DontReviewSettings)
                .WithLongName("no-review")
                .WithShortName("nr")
                .WithHelp("don't review all settings before starting work");
                cfg.Parameter(c => c.OldProjectName)
                .WithLongName("old-name")
                .WithShortName("o")
                .ExpectAt(0)
                .WithHelp(
                    "the name of the existing project - don't provide path or extension, just the name as you see it in VS.");
                cfg.Parameter(c => c.NewProjectName)
                .WithLongName("new-name")
                .WithShortName("n")
                .ExpectAt(1)
                .WithHelp("the new desired project name, again without path or extension");
                cfg.Parameter(c => c.ExcludedDirectory)
                .MakeOptional()
                .ExpectAt(2)
                .WithLongName("exclude")
                .WithShortName("e")
                .WithHelp(
                    "exclude this directory from project reference updates; must be a relative path to the current directory");
                return(parser.HelpOverview, parser.Parse(args));
            }

            string removeProjectFileExtension(string projectName) =>
            projectName.EndsWith(Constants.ProjectFileExtension,
                                 StringComparison.InvariantCultureIgnoreCase)
                    ? projectName[..^ Constants.ProjectFileExtension.Length]
Exemplo n.º 18
0
        public virtual void Init()
        {
            var factory = new ParserFactory(CommandConfig);

            this._parser = factory.Create(true);
        }
 /// <summary>
 /// Create a deserializer instance for specified type and payload schema, using a custom object factory
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="schema">Schema of the payload</param>
 /// <param name="factory">Factory providing expressions to create objects during deserialization</param>
 /// <param name="inlineNested">Inline nested types if possible (optimizes for reduction of execution time
 /// at the expense of initialization time and memory)</param>
 public Deserializer(Type type, RuntimeSchema schema, Factory factory, bool inlineNested)
     : this(type, ParserFactory <R> .Create(schema), null, factory, inlineNested)
 {
 }
 /// <summary>
 /// Create a deserializer instance for specified type and payload schema, using a custom object factory
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="schema">Schema of the payload</param>
 /// <param name="factory">Factory providing expressions to create objects during deserialization</param>
 public Deserializer(Type type, RuntimeSchema schema, Factory factory)
     : this(type, ParserFactory <R> .Create(schema), null, factory)
 {
 }
Exemplo n.º 21
0
 /// <summary>
 /// Create a deserializer instance for specified type, using a custom object factory
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="factory">Factory to create objects during deserialization</param>
 public Deserializer(Type type, IFactory factory)
     : this(type, ParserFactory <R> .Create(type), factory)
 {
 }
Exemplo n.º 22
0
 /// <summary>
 /// Create a deserializer instance for specified type and payload schema
 /// </summary>
 /// <param name="type">Type representing a Bond schema</param>
 /// <param name="schema">Schema of the payload</param>
 public Deserializer(Type type, RuntimeSchema schema)
     : this(type, ParserFactory <R> .Create(schema), factory : null, inlineNested : true)
 {
 }