public GenieConfig(GenieLamp lamp, XmlNode node) { this.lamp = lamp; macro = new MacroExpander(lamp.Macro); name = Utils.Xml.GetAttrValue(node, "name"); assemblyName = Utils.Xml.GetAttrValue(node, "assembly"); typeName = Utils.Xml.GetAttrValue(node, "type"); active = Utils.Xml.GetAttrValue(node, "active", true); targetVersion = Environment.ExpandEnvironmentVariables(Utils.Xml.GetAttrValue(node, "targetVersion", TargetVersionWildcard)); macro.SetMacro("%TARGET_VERSION%", targetVersion); outDir = macro.Subst(Lamp.ExpandFileName(Utils.Xml.GetAttrValue(node, "outDir"))); outFileName = macro.Subst(Lamp.Macro.Subst(Utils.Xml.GetAttrValue(node, "outFileName"))); this.OutFileEncoding = Encoding.GetEncoding(Utils.Xml.GetAttrValue(node, "outFileEncoding", Encoding.UTF8.BodyName)); this.UpdateDatabase = Utils.Xml.GetAttrValue(node, "updateDatabase", false); configParams = new GenieConfigParams(this, lamp.QueryNode(node, "./{0}:Param")); this.AssistantConfigs = new GenieAssistantConfigs(this, node); this.Assistants = new List <IGenieAssistant>(); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } }
public GenieLampConfig(GenieLamp lamp, XmlNode node) { this.lamp = lamp; macro = new MacroExpander(lamp.Macro); layers = new LayersConfig(this, node); patterns = new Patterns.Patterns(this, node); }
private static void ProcessMacroEntities(ExpansionSettings settings, Logger logger) { // Default to .map, if no extension was specified (unless there's an extensionless file that matches): var inputPath = settings.InputPath; if (!Path.HasExtension(settings.InputPath) && !File.Exists(settings.InputPath)) { inputPath = Path.ChangeExtension(settings.InputPath, ".map"); } if (settings.OutputPath == null) { settings.OutputPath = inputPath; } if (settings.Directory == null) { settings.Directory = Path.GetDirectoryName(settings.InputPath); } logger.Info($"Starting to expand macros in '{settings.InputPath}'."); var expandedMap = MacroExpander.ExpandMacros(inputPath, settings, logger); // TODO: Create a backup if the target file already exists! -- how many backups to make? -- make a setting for this behavior? using (var file = File.Create(settings.OutputPath)) { logger.Info($"Finished macro expansion. Saving to '{settings.OutputPath}'."); MapFormat.Save(expandedMap, file); } }
private static CSharpCompilation EditCompilation(CSharpCompilation compilation, CancellationToken cancellationToken) { int syntaxTreesLength = compilation.SyntaxTrees.Length; for (int i = 0; i < syntaxTreesLength; i++) { CSharpSyntaxTree tree = compilation.SyntaxTrees[i] as CSharpSyntaxTree; if (tree == null) { continue; } MacroExpander expander = new MacroExpander(tree, compilation, cancellationToken); SyntaxNode root = tree.GetCompilationUnitRoot(cancellationToken); SyntaxNode newRoot = expander.Visit(root); if (root != newRoot) { compilation = compilation.ReplaceSyntaxTree(tree, tree.WithRootAndOptions(newRoot, tree.Options)); } } return(compilation); }
internal BuildEnvironment( Backend backend, SourcePackage project, CompilerOptions options, ExtensionRoot extensions, ILFactory ilf, Compiler compiler) : base(compiler) { if (string.IsNullOrEmpty(options.Configuration)) { options.Configuration = "Debug"; } if (string.IsNullOrEmpty(options.BuildTarget)) { throw new ArgumentNullException(nameof(options.BuildTarget)); } if (string.IsNullOrEmpty(options.OutputDirectory)) { throw new ArgumentNullException(nameof(options.OutputDirectory)); } Extensions = extensions; Options = options; BundleDirectory = Path.Combine(project.CacheDirectory, "bundle"); CacheDirectory = Path.Combine(project.CacheDirectory, options.BuildTarget, options.Configuration); Essentials = ilf.Essentials; MacroExpander = new MacroExpander(backend, this, extensions, ilf, compiler); Compiler = compiler; Set("Target", options.BuildTarget); Set("Configuration", options.Configuration); Set("OutputDirectory", OutputDirectory = ExpandSingleLine(options.OutputDirectory).UnixToNative()); }
public void ConstructsWithDefaults() { var me = new MacroExpander(); Assert.AreEqual(me.Context, null); return; } // end of function - ConstructsWithDefaults
public void ExpandNullString() { var me = new MacroExpander(); Assert.AreEqual(null, me.Expand(null)); return; } // end of function - ExpandNullString
private void ReportDetailReport() { const string Separator = "\t"; string path = RemoveInvalidPathChars(MacroExpander.ExpandAll(config.FuhaReports.DetailReportFilePath)); using var writer = new StreamWriter(path, false, reportFileEncoidng); writer.WriteLine(string.Join(Separator, new[] { "順番", "ツイート日時", "ツイートID", "ユーザー名", "@ID", "ツイート内容", })); int rank = 1; collectedTweets.ForEach(t => { writer.WriteLine(string.Join(Separator, new[] { rank.ToString(), t.TweetedAt.ToString("yyyy-MM-dd HH:mm:ss.fff"), t.Id.ToString(), t.UserName, t.FormatedUserScreenName, t.EscapedText, })); rank++; }); }
private static string GetMacroErrorMessage(MacroExpander macroExpander, string text) { Regex regex = new Regex(@"\$\([^)]*\)?"); StringBuilder sb = new StringBuilder(); foreach (Match match in regex.Matches(text)) { string macro = match.Value; if (!macroExpander.Macros.ContainsKey(macro)) { sb.AppendFormat(CultureInfo.CurrentCulture, Res.InvalidMacro, macro); sb.AppendLine(); } } string errorMessage; if (sb.Length == 0) { errorMessage = null; } else { errorMessage = sb.ToString(); } return(errorMessage); }
public void ConstructsWithContext() { var context = Substitute.For <IItemContext>(); var me = new MacroExpander(context); Assert.AreEqual(context, me.Context); return; } // end of function - ConstructsWithContext
public void InitializesAfterDefaults() { var context = Substitute.For <IItemContext>(); var me = new MacroExpander(); me.Initialize(context); Assert.AreEqual(context, me.Context); return; } // end of function - InitializesAfterDefaults
private void Init(GenieLampConfig owner, string name) { this.owner = owner; this.name = name; namingConvention = new NamingConvention(this); layerConfigParams = new LayerConfigParams(this); macro = new MacroExpander(owner.Macro); this.Keywords = new LayerKeywords(); this.LocalizationParams = new LayerLocalizationParams(this); }
public void CanDispose() { var context = Substitute.For <IItemContext>(); var me = new MacroExpander(context); Assert.AreEqual(context, me.Context); me.Dispose(); Assert.AreEqual(null, me.Context); return; } // end of function - CanDispose
public MetaObject(Model model) { if (model == null) { throw new GlException("Provided model reference is null"); } SetModel(model); macro = new MacroExpander(model.Lamp.Macro); Init(); }
public SolutionSettingsForm(string solutionPath) { InitializeComponent(); _macroExpander = new MacroExpander(solutionPath); LoadSettings(solutionPath); UpdateEnabledState(); UpdateDeclaredProperties(); ValidateAll(); }
public void TestSimpleParse() { string line = "(seq (defmacro inc (x) (+ x 1)) (inc 2))"; Node node = HighLevel.Parse(line); Assert.IsNotNull(node); Env env = new Env(null); node = MacroExpander.ExpandMacros(node, env); string serialization = NodeOps.Serialize(node); Assert.AreEqual("(seq (+ 2 1))", serialization); }
public MetaObject(MetaObject owner) { if (owner == null) { throw new GlException("Provided owner reference is null"); } if (owner.Model == null) { throw new GlException("Provided owner model reference is null"); } this.owner = owner; SetModel(owner.Model); this.name = Guid.NewGuid().ToString(); macro = new MacroExpander(owner.Macro); Init(); }
public PatternConfig(GenieLampConfig owner, XmlNode node) { this.owner = owner; this.name = Utils.Xml.GetAttrValue(node, "name"); this.OnPersistentLayer = bool.Parse(Utils.Xml.GetAttrValue(node, "onPersistentLayer")); macro = new MacroExpander(owner.Macro); this.PatternApply = new PatternApply(owner); configParams = new PatternConfigParams(this, owner.Lamp.QueryNode(node, "./{0}:Param")); this.schema = Params.ValueByName("Schema", this.schema); this.PersistentSchemaDefined = Params.ParamByName("PersistentSchema", false) != null; this.persistentSchema = Params.ValueByName("PersistentSchema", this.persistentSchema); AddPatternApplyItems(owner.Lamp.QueryNode(node, "./{0}:Exclude"), PatternApplyMode.Exclude); AddPatternApplyItems(owner.Lamp.QueryNode(node, "./{0}:Include"), PatternApplyMode.Include); }
public void ExpandValidString() { var context = Substitute.For <IItemContext>(); var doc = Substitute.For <EnvDTE.Document>(); var name = "TestDocument.cs"; doc.Name.Returns(name); context.Document.Returns(doc); var me = new MacroExpander(context); string strToExpand = "{FILENAME}|{DATE}|{YEAR}"; var expandedStrs = me.Expand(strToExpand).Split('|'); Assert.AreEqual(3, expandedStrs.Length); Assert.AreEqual(expandedStrs[0], name); Assert.IsTrue(expandedStrs[1] != "{DATE}"); Assert.AreEqual(expandedStrs[2], DateTime.Now.Year.ToString()); return; } // end of function - ExpandValidString
private void ReportTweetReport() { Tweet?lastBossTweet = GetLastBossTweet(); string path = RemoveInvalidPathChars(MacroExpander.ExpandAll(config.FuhaReports.TweetReportFilePath)); using var writer = new StreamWriter(path, false, reportFileEncoidng); writer.WriteLine("本日のフハツイランキング"); if (lastBossTweet == null) { writer.WriteLine(); writer.WriteLine("ラスボスのツイートが見つからなかった為、集計できませんでした"); return; } bool isFlyingStart = true; int rank = -1; // -1: フライングツイート, 1以降: ツイート順位 collectedTweets.ForEach(t => { // ラスボスアカウントのツイートになったタイミングから順位付け開始 // それより前はフライング扱い if (t.UserScreenName == config.RankingCollection.RankingBaseId) { isFlyingStart = false; rank = 1; return; } var tweet = new FuhaTweet(t, lastBossTweet, rank); writer.WriteLine($"[{tweet.DifferenceFromLastBossTweetFlag}{tweet.DifferenceFromLastBossTweet:mm\\:ss\\.fff}]{tweet.DisplayRank}: {t.UserName}"); if (!isFlyingStart) { rank++; } }); writer.WriteLine(); writer.Write($"[ ]内はラスボスのフリージオがツイートした時間({lastBossTweet.TweetedAt:HH:mm:ss.fff})からの差"); }
private static Node ExpandMacros(Node node, Env env) { int times = 0; int numExpansions = 1; while (numExpansions > 0) { node = MacroExpander.ExpandMacros(node, env, out int expansionCount); numExpansions = expansionCount; times++; if (times > 100) { Console.WriteLine("Too many expansions. Likely a bug."); return(node); } } return(node); }
public void TestCase() { string envVarName = "GL_TEST"; string envVar = "%" + envVarName + "%"; string envVarValue = "/RootTest"; string source = String.Format("Output to: {0}/%PROJECT_DIR%/%PROJECT_NAME%.sql", envVar); string projectName = "TestProject"; string projectDir = "TestDir/Subdir"; string target = String.Format("Output to: {0}/{1}/{2}.sql", envVarValue, projectDir, projectName); Environment.SetEnvironmentVariable(envVarName, envVarValue); Assert.AreEqual("%%", System.Environment.ExpandEnvironmentVariables("%%")); Assert.AreEqual(envVarValue, System.Environment.ExpandEnvironmentVariables(envVar)); Assert.AreEqual("%" + envVar + "%", Utils.Sys.ExpandEnvironmentVariables("%" + envVar + "%")); Assert.AreEqual("%TEST123%", Utils.Sys.ExpandEnvironmentVariables("%TEST123%")); Assert.AreEqual("%TEST123%_%TEST456%", Utils.Sys.ExpandEnvironmentVariables("%TEST123%_%TEST456%")); Assert.AreEqual(envVarValue, Utils.Sys.ExpandEnvironmentVariables(envVar)); Assert.AreEqual(String.Format("{0}_{0}", envVarValue), String.Format("{0}_{0}", Utils.Sys.ExpandEnvironmentVariables(envVar))); MacroExpander m = new MacroExpander(); m.SetMacro("%PROJECT_NAME%", projectName); m.SetMacro("%PROJECT_DIR%", projectDir); Assert.AreEqual(2, m.Count); Assert.AreEqual(target, m.Subst(source)); m.Clear(); Assert.AreEqual(0, m.Count); string unchanged = "IX%COUNTER%_%TABLE%_%COLUMNS%"; Assert.AreEqual(unchanged, m.Subst(unchanged)); }
public Compiler() { _macroExp = null; }
public Compiler(MacroExpander macroExp) { _macroExp = macroExp; }