/// <summary> /// Adds a context that has been queued to the builder. /// </summary> private void AddQueuedContext(string ctxName, InlinePushContextMember ilp, IroPrecompileData data, ref StringBuilder text) { //Begin this context. text.AppendLine("\"" + ctxName + "\": ["); //Get styles out for pop rule. var popStyles = GetPatternStyles(ilp.PopStyles, data); //Add the pop rule. text.AppendLine("{"); text.AppendLine("\"token\": \"" + popStyles[0].AceScope + "\","); text.AppendLine("\"regex\": \"" + ilp.PopData.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\","); text.AppendLine("\"next\": \"pop\""); text.AppendLine("},"); //Add all patterns for the ILP. foreach (var pattern in ilp.Patterns) { AddMember(pattern, ctxName, ref text, data); } //Add the default style. text.AppendLine("{"); text.AppendLine("defaultToken: \"text\""); text.AppendLine("}"); //End this context. text.AppendLine("],"); }
//Adds an inline push context member. private void AddILPContext(string ctxName, string name, InlinePushContextMember mem, IroPrecompileData data, ref RubyStringMaker text) { //Create the rule, reset includes. includedThisRun = new List <string>(); text.AppendLine("state:" + name); text.TabIn(); //Add the pop rule. string popRule = "rule /" + mem.PopData + "/"; var styles = GetPatternStyles(mem.PopStyles, data); if (styles.Count > 1) { //Append. popRule += " do"; text.AppendLine(popRule); text.TabIn(); //Newline with groups. popRule = "groups "; foreach (var scope in styles) { popRule += scope.PygmentsScope.Replace(".", "::") + ", "; } popRule = popRule.TrimEnd(' ', ','); text.AppendLine(popRule); text.AppendLine("push :pop!"); text.TabOut(); text.AppendLine("end"); } else if (styles.Count == 1) { //Single style. popRule += ", " + styles[0].PygmentsScope.Replace(".", "::") + ", :pop!"; text.AppendLine(popRule); } else { Error.Compile("No pop styles included for pop rule '" + mem.PopData + "'."); return; } //Loop over rules, add them. foreach (var member in mem.Patterns) { AddContextMember(member, ctxName, data, ref text); } text.TabOut(); text.AppendLine("end"); }
//Adds a queued context to the text. private void AddQueuedContext(string name, string originalCtx, InlinePushContextMember ilp, IroPrecompileData data, ref PyStringMaker text) { //Open the context. text.AppendLine("'" + name + "' : ["); text.TabIn(); //Add the pop rule. var popStyles = GetPatternStyles(ilp.PopStyles, data); text.AppendLine("(u'" + ilp.PopData.Replace("\\", "\\\\") + "', byGroups(" + string.Join(", ", popStyles.Select(x => x.PygmentsScope)).TrimEnd(',', ' ') + "), '" + originalCtx + "')"); //Add context members. includedThisRun = new List <string>(); foreach (var member in ilp.Patterns) { AddContextMember(name, member, data, ref text); } text.TrimEnd(',', ' '); text.TabOut(); text.AppendLine("],"); }
/// <summary> /// Enqueues an inline push helper context to be created later. /// </summary> private void QueueILPContext(string name, InlinePushContextMember ilp) { queuedContexts.Add(name, ilp); }
//Queues a context for creation. private void QueueContext(string helperName, string originalCtx, InlinePushContextMember ilp) { queuedContexts.Add(new Tuple <string, string>(helperName, originalCtx), ilp); }
//Queues an inline push scope to be generated. private void QueueILPScope(string ctx, string helperName, InlinePushContextMember ilp) { queuedContexts.Add(new Tuple <string, string>(ctx, helperName), ilp); }