/// <summary>
        /// File-in and process the actions contained in the node.
        /// </summary>
        /// <param name="processor">Interchange format processor responsible for the processing context.</param>
        /// <param name="parseErrorSink">Error sink for reporting parse errors.</param>
        /// <param name="sourceCodeService">Source code service that can convert tokens to source code span and reports issues.</param>
        /// <returns>Return an interchange unit node for annotation, usually just self.</returns>
        public override InterchangeUnitNode FileIn(InterchangeFormatProcessor processor, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
        {
            if (processor == null)
            {
                throw new ArgumentNullException("processor");
            }
            if (parseErrorSink == null)
            {
                throw new ArgumentNullException("parseErrorSink");
            }
            if (sourceCodeService == null)
            {
                throw new ArgumentNullException("sourceCodeService");
            }

            // <programInitialization> ::= ’Global’ ’initializer’ <elementSeparator>
            //      <programInitializer> <elementSeparator>
            //  <programInitializer> ::= <initializer definition>

            ISourceCodeReferenceService methodSourceCodeService;
            InitializerNode             initializer = processor.ParseInitializer(out methodSourceCodeService);

            if (initializer == null)
            {
                return(this); // Processor/Parser should have reported errors
            }
            if (!initializer.Accept(IronSmalltalk.Compiler.Visiting.ParseTreeValidatingVisitor.Current))
            {
                // We expect the parser to have reported the errors. Just in case, we do it once more to the installer.
                // Bad practice here is to use the 'processor.SourcePosition', but we don't have anything better :-/
                if (processor.ErrorSink != null)
                {
                    processor.ErrorSink.AddInterchangeError(processor.SourcePosition, processor.SourcePosition, "Invalid initializer source code.");
                }
                return(this);
            }

            RuntimeProgramInitializerFactory factory = new RuntimeProgramInitializerFactory(initializer, methodSourceCodeService);

            ProgramInitializer definition = new ProgramInitializer(sourceCodeService, methodSourceCodeService, factory);

            this.Definfition = definition;
            // This may fail, but we don't care. If failed, it reported the error through its error sink.
            processor.FileInProcessor.FileInProgramInitializer(definition);

            return(this);
        }
 public bool ValidateProgramInitializer(ProgramInitializer definition, IDefinitionInstallerContext installer, ICodeValidationErrorSink errorSink)
 {
     return(((RuntimeProgramInitializer)this.CreateInitializer(definition, installer)).Validate(installer.NameScope, this.GetErrorSink(errorSink)));
 }
 bool IInterchangeFileInProcessor.FileInProgramInitializer(ProgramInitializer initializer)
 {
     this.AddProgramInitializer(initializer);
     return(true);
 }
예제 #4
0
        static void Main(string[] args)
        {
            var pi = new ProgramInitializer(new DefaultProgramActions());

            pi.Go(args);
        }
 /// <summary>
 /// Add a program initializer definition to the installation context.
 /// </summary>
 /// <param name="initializer">Definition of the initializer to be added.</param>
 public void AddProgramInitializer(ProgramInitializer initializer)
 {
     this._initializers.Add(initializer);
 }