/// <summary> /// Initializes a new instance of the <see cref="IncludesPreprocessor"/> class. /// </summary> /// <param name="fileReader">File reader.</param> /// <param name="tokenProviderPool">Token provider pool.</param> /// <param name="spiceNetlistParser">Parser.</param> /// <param name="lexerSettings">Lexer settings.</param> /// <param name="initialDirectoryPathProvider">Directory provider.</param> public IncludesPreprocessor(IFileReader fileReader, ISpiceTokenProviderPool tokenProviderPool, ISingleSpiceNetlistParser spiceNetlistParser, Func <string> initialDirectoryPathProvider, SpiceLexerSettings lexerSettings) { TokenProviderPool = tokenProviderPool; SpiceNetlistParser = spiceNetlistParser; FileReader = fileReader; InitialDirectoryPathProvider = initialDirectoryPathProvider; LexerSettings = lexerSettings; }
/// <summary> /// Initializes a new instance of the <see cref="LibPreprocessor"/> class. /// </summary> /// <param name="fileReader">File reader.</param> /// <param name="tokenProviderPool">Token provider.</param> /// <param name="spiceNetlistParser">Single spice netlist parser.</param> /// <param name="includesPreprocessor">Includes preprocessor.</param> /// <param name="initialDirectoryPathProvider">Initial directory path provider.</param> /// <param name="readerSettings">Reader settings.</param> /// <param name="lexerSettings">Lexer settings.</param> public LibPreprocessor( IFileReader fileReader, ISpiceTokenProviderPool tokenProviderPool, ISingleSpiceNetlistParser spiceNetlistParser, IProcessor includesPreprocessor, Func <string> initialDirectoryPathProvider, SpiceNetlistReaderSettings readerSettings, SpiceLexerSettings lexerSettings) { ReaderSettings = readerSettings ?? throw new ArgumentNullException(nameof(readerSettings)); TokenProviderPool = tokenProviderPool ?? throw new ArgumentNullException(nameof(tokenProviderPool)); IncludesPreprocessor = includesPreprocessor ?? throw new ArgumentNullException(nameof(includesPreprocessor)); SpiceNetlistParser = spiceNetlistParser ?? throw new ArgumentNullException(nameof(spiceNetlistParser)); FileReader = fileReader ?? throw new ArgumentNullException(nameof(fileReader)); InitialDirectoryPathProvider = initialDirectoryPathProvider ?? throw new ArgumentNullException(nameof(initialDirectoryPathProvider)); LexerSettings = lexerSettings ?? throw new ArgumentNullException(nameof(lexerSettings)); }
private void ReadSingleLib(Statements statements, string currentDirectoryPath, Control lib) { // get full path of .lib string libPath = PathConverter.Convert(lib.Parameters.Get(0).Image); bool isAbsolutePath = Path.IsPathRooted(libPath); string libFullPath = isAbsolutePath ? libPath : Path.Combine(currentDirectoryPath, libPath); // check if file exists if (!File.Exists(libFullPath)) { Validation.Reading.Add( new ValidationEntry( ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"Netlist include at {libFullPath} could not be found", lib.LineInfo)); return; } // get lib content string libContent = FileReader.ReadAll(libFullPath); if (libContent != null) { var lexerSettings = new SpiceLexerSettings() { HasTitle = false, IsDotStatementNameCaseSensitive = LexerSettings.IsDotStatementNameCaseSensitive, }; var tokens = TokenProviderPool.GetSpiceTokenProvider(lexerSettings).GetTokens(libContent); foreach (var token in tokens) { token.FileName = libFullPath; } SpiceNetlistParser.Settings = new SingleSpiceNetlistParserSettings(lexerSettings) { IsNewlineRequired = false, IsEndRequired = false, }; SpiceNetlist includeModel = SpiceNetlistParser.Parse(tokens); var allStatements = includeModel.Statements.ToList(); if (lib.Parameters.Count == 2) { ReadSingleLibWithTwoArguments(statements, lib, allStatements); } else if (lib.Parameters.Count == 1) { ReadSingleLibWithOneArgument(statements, lib, allStatements); } } else { Validation.Reading.Add( new ValidationEntry( ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"Netlist include at {libFullPath} could not be read", lib.LineInfo)); } }
/// <summary> /// Initializes a new instance of the <see cref="SpiceNetlistCaseSensitivitySettings"/> class. /// </summary> /// <param name="lexerSettings">Lexer settings.</param> public SpiceNetlistCaseSensitivitySettings(SpiceLexerSettings lexerSettings) { _lexerSettings = lexerSettings ?? throw new ArgumentNullException(nameof(lexerSettings)); }
private void ReadSingleInclude(Statements statements, string currentDirectoryPath, Control include) { // get full path of .include string includePath = include.Parameters.Get(0).Image; includePath = PathConverter.Convert(includePath); bool isAbsolutePath = Path.IsPathRooted(includePath); string includeFullPath = isAbsolutePath ? includePath : Path.Combine(currentDirectoryPath, includePath); // check if file exists if (!File.Exists(includeFullPath)) { Validation.Reading.Add( new ValidationEntry( ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"Netlist include at {includeFullPath} is not found", include.LineInfo)); return; } // get include content string includeContent = FileReader.ReadAll(includeFullPath); if (includeContent != null) { var lexerSettings = new SpiceLexerSettings() { HasTitle = false, IsDotStatementNameCaseSensitive = LexerSettings.IsDotStatementNameCaseSensitive, }; var tokens = TokenProviderPool.GetSpiceTokenProvider(lexerSettings).GetTokens(includeContent); foreach (var token in tokens) { token.FileName = includeFullPath; } SpiceNetlistParser.Settings = new SingleSpiceNetlistParserSettings(lexerSettings) { IsNewlineRequired = false, IsEndRequired = false, }; SpiceNetlist includeModel = SpiceNetlistParser.Parse(tokens); // process includes of include netlist includeModel.Statements = Process(includeModel.Statements, Path.GetDirectoryName(includeFullPath)); // replace statement by the content of the include statements.Replace(include, includeModel.Statements); } else { Validation.Reading.Add( new ValidationEntry( ValidationEntrySource.Reader, ValidationEntryLevel.Warning, $"Netlist include at {includeFullPath} could not be read", include.LineInfo)); } }
/// <summary> /// Initializes a new instance of the <see cref="SingleSpiceNetlistParserSettings"/> class. /// </summary> /// <param name="lexerSettings">Lexer settings.</param> public SingleSpiceNetlistParserSettings(SpiceLexerSettings lexerSettings) { Lexer = lexerSettings ?? throw new ArgumentNullException(nameof(lexerSettings)); }
public SpiceParserSettings() { Lexing = new SpiceLexerSettings(); Parsing = new SingleSpiceNetlistParserSettings(Lexing); Reading = new SpiceNetlistReaderSettings(new SpiceNetlistCaseSensitivitySettings(Lexing), () => WorkingDirectory); }