Esempio n. 1
0
        public CompilerResults Compile(string generatedCodeFileName = null)
        {
            var options = new Dictionary<string, string>
                          {
                          	{"CompilerVersion", "v3.5"}
                          };
            var codeProvider = new CSharpCodeProvider(options);

            var scanner = new Scanner(this.fileName);
            var parser = new Parser(scanner);

            parser.Parse();

            var generatator = new Generator();
            var generatedCode = generatator.Generate(null, parser.ruleClassStatement, "");

            if (generatedCodeFileName != null)
            {
                using (var stream = new StreamWriter(generatedCodeFileName, false, Encoding.UTF8))
                {
                    stream.Write(generatedCode);
                }
            }

            return codeProvider.CompileAssemblyFromSource(this._compilerParams, generatedCode.ToString());
        }
Esempio n. 2
0
        public void NullOrWhitespaceParametersTest()
        {
            var generator = new Generator();
            var dynamicInvoker = new DynamicInvoker( generator );

            EmptyAndNullParametersTestHelper( dynamicInvoker, "" );
            EmptyAndNullParametersTestHelper( dynamicInvoker, null );
            EmptyAndNullParametersTestHelper( dynamicInvoker, "    " );
            EmptyAndNullParametersTestHelper( dynamicInvoker, "\r\n" );
            EmptyAndNullParametersTestHelper( dynamicInvoker, "\t\t\t" );
        }
Esempio n. 3
0
        public void SimpleTest()
        {
            var generator = new Generator();
            var dynamicInvoker = new DynamicInvoker( generator );

            var callStatement = new CallStatement( Helper.EmptyPosition, "Name", "param1, param2" );

            var invokeCodeWriter = dynamicInvoker.Invoke<CodeWriter>( "GenerateInvoke", callStatement );

            Assert.IsNotNull( invokeCodeWriter );

            var invokeText = invokeCodeWriter.ToString().Replace( " ", "" );

            Assert.That( invokeText, Is.EqualTo( "this.Invoke(\"Name\",param1,param2)" ) );
        }
Esempio n. 4
0
        static void Main()
        {
            var scanner = new Scanner( @"Rules\Main.txt" );
            var parser = new Parser( scanner );

            parser.Parse();

            var mainClass = new MainClass();

            try
            {
                Console.WriteLine( mainClass.Main( new object[] { "Id", "Name" } ) );
            }
            catch (Exception e)
            {
                Console.WriteLine( e );
            }
            var code = new Generator().Generate( null, parser.ruleClassStatement, "test.rule" ).ToString();

            using (var stream = new StreamWriter( "../../GeneratedClass.cs" ))
            {
                stream.WriteLine( code );
            }
        }
        protected override byte[] GenerateCode( string inputFileName, string inputFileContent )
        {
            this.fileName = inputFileName;

            var serviseObject = this.GetService<ProjectItem>();
            Project containintProject;

            if (serviseObject != null)
            {
                containintProject = serviseObject.ContainingProject;
                var dte = containintProject.DTE;
                var outputWindow = dte.Windows.Item( Constants.vsWindowKindOutput );
                var output = (OutputWindow)outputWindow.Object;
                foreach (OutputWindowPane pane in output.OutputWindowPanes)
                {
                    if (pane.Name != wolfGeneratorPaneName) continue;

                    this.generatorPane = pane;
                    this.generatorPane.Clear();
                    break;
                }
                if (this.generatorPane == null)
                    this.generatorPane = output.OutputWindowPanes.Add( wolfGeneratorPaneName );
            }

            string programCode;
            try
            {
                var scanner = new GeneratorScanner( inputFileName, this );
                var parser = new Parser( scanner );

                parser.Parse();

                if (parser.errors.count == 0)
                    programCode = new Generator().Generate( FileNameSpace, parser.ruleClassStatement, Path.GetFileName( inputFileName ) ).ToString();
                else
                    programCode = "parser errors: " + parser.errors.count;
            }
            catch (Exception e)
            {
                programCode = "// Exception See OutputWindow/WolfGenerator for detaile";
                WriteError( 0, 0, ErrorLevel.Error, e.Message );
            }

            return Encoding.UTF8.GetBytes( programCode );
        }