/// <summary>
        /// Initializes a new instance of the <see cref="SpiceParser"/> class.
        /// </summary>
        /// <param name="settings">SPICE parser settings.</param>
        public SpiceParser(SpiceParserSettings settings)
        {
            Settings            = settings ?? throw new ArgumentNullException(nameof(settings));
            SingleNetlistParser = new SingleSpiceNetlistParser(Settings.Parsing);

            TokenProviderPool = new SpiceTokenProviderPool();
            var includesPreprocessor = new IncludesPreprocessor(
                new FileReader(),
                TokenProviderPool,
                SingleNetlistParser,
                () => Settings.WorkingDirectory,
                Settings.Lexing);

            var libPreprocessor = new LibPreprocessor(
                new FileReader(),
                TokenProviderPool,
                SingleNetlistParser,
                includesPreprocessor,
                () => Settings.WorkingDirectory,
                Settings.Reading,
                Settings.Lexing);

            var appendModelPreprocessor = new AppendModelPreprocessor();
            var sweepsPreprocessor      = new SweepsPreprocessor();
            var ifPostprocessor         = new IfPreprocessor();

            Preprocessors.AddRange(new IProcessor[] { includesPreprocessor, libPreprocessor, appendModelPreprocessor, sweepsPreprocessor, ifPostprocessor });
        }
        public override SpiceSharp.Components.Component Generate(string componentIdentifier, string originalName, string type, ParameterCollection parameters, ICircuitContext context)
        {
            SubCircuit     subCircuitDefinition = FindSubcircuitDefinition(parameters, context);
            CircuitContext subCircuitContext    = CreateSubcircuitContext(componentIdentifier, originalName, subCircuitDefinition, parameters, context);

            var ifPreprocessor = new IfPreprocessor();

            ifPreprocessor.CaseSettings = subCircuitContext.CaseSensitivity;
            ifPreprocessor.Validation   = new SpiceParserValidationResult()
            {
                Reading = context.Result.Validation
            };
            ifPreprocessor.EvaluationContext = subCircuitContext.Evaluator.GetEvaluationContext();
            subCircuitDefinition.Statements  = ifPreprocessor.Process(subCircuitDefinition.Statements);

            ReadParamControl(subCircuitDefinition, subCircuitContext);
            ReadFuncControl(subCircuitDefinition, subCircuitContext);
            ReadSubcircuits(subCircuitDefinition, subCircuitContext);
            CreateSubcircuitModels(subCircuitDefinition, subCircuitContext); // TODO: Share models someday between instances of subcircuits
            CreateSubcircuitComponents(subCircuitDefinition, subCircuitContext);

            context.Children.Add(subCircuitContext);

            // null is intentional
            return(null);
        }
Example #3
0
        public void Invoke(CancellationToken cancellationToken)
        {
            Snapshot snapshot = this.source.CurrentSnapshot;

            IfPreprocessor preprocessor = this.source.Settings.GetPreprocessor(snapshot, this.position);

            if (this.newValue)
            {
                preprocessor.SetAllValues(false);
            }

            preprocessor.GetPreprocessor(snapshot, this.position).Value = this.newValue;

            preprocessor.CheckForElse();

            this.actionSource.Update();

            (this.source as VSSource)?.Parse();
        }