Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SyntaxParser" /> class.
        /// </summary>
        /// <param name="sourceFile">PHP source file representation</param>
        /// <param name="code">Source code of PHP script</param>
        public SyntaxParser(PhpSourceFile /*!*/ sourceFile, string /*!*/ code)
        {
            sourceUnit = new VirtualSourceFileUnit(compilationUnit, code, sourceFile, Encoding.Default);
            compilationUnit.SourceUnit = sourceUnit;

            // Assembly of the application is used instead of non-existing PHP script assembly.
            // To compile PHP, follow the basic technique of Phalanger PHP compilation.
            // <seealso cref="ScriptContext.CurrentContext" />
            // <seealso cref="ApplicationContext.Default" />
            // <seealso cref="ApplicationContext.AssemblyLoader" />
            var assembly       = System.Reflection.Assembly.GetExecutingAssembly();
            var assemblyName   = assembly.GetName();
            var scriptAssembly = new BasicScriptAssembly(assembly, assemblyName, compilationUnit);

            // TODO: It simulates command compilationUnit.module = scriptAssembly.Module;
            // It affects compilationUnit.ScriptModule and compilationUnit.ScriptBuilder too
            var type  = compilationUnit.GetType();
            var field = type.GetField("module", BindingFlags.NonPublic | BindingFlags.Instance);

            field.SetValue(compilationUnit, scriptAssembly.GetModule());

            IsParsed = false;
            output   = new StringWriter(assemblyName.CultureInfo);
            Errors   = new ErrorSinkThrowingException();
        }