/// <summary> /// Preprocessor keywords must not be preceded by space. /// </summary> /// <param name="node"> /// The node to use. /// </param> public static void PreprocessorKeywordsMustNotBePrecededBySpace(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { if (currentNode is IPreprocessorDirective) { IPreprocessorDirective preprocessorDirectiveNode = currentNode as IPreprocessorDirective; TreeOffset directiveTokenNodeOffset = preprocessorDirectiveNode.Directive.GetTreeStartOffset(); TreeOffset numberSignTokenNodeOffset = preprocessorDirectiveNode.NumberSign.GetTreeStartOffset(); if (directiveTokenNodeOffset - 1 != numberSignTokenNodeOffset) { // There is a gap between them ITokenNode tokenNode = preprocessorDirectiveNode.NumberSign; ITokenNode nextToken = tokenNode.GetNextToken(); using (WriteLockCookie.Create(true)) { // remove the whitespace or new line LowLevelModificationUtil.DeleteChild(nextToken); } } } if (currentNode.FirstChild != null) { PreprocessorKeywordsMustNotBePrecededBySpace(currentNode.FirstChild); } } }
internal static IProductionRuleItem Expand(this IPreprocessorDirective directive, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { switch (directive.Type) { case EntryPreprocessorType.If: case EntryPreprocessorType.IfNotDefined: case EntryPreprocessorType.IfDefined: case EntryPreprocessorType.ElseIf: case EntryPreprocessorType.ElseIfDefined: case EntryPreprocessorType.Else: return(((IPreprocessorIfDirective)directive).Expand(currentEntry, availableStock, argumentLookup, entry, file, errors)); case EntryPreprocessorType.DefineRule: ((IPreprocessorDefineRuleDirective)(directive)).Expand(currentEntry, availableStock, argumentLookup, entry, file, errors); break; case EntryPreprocessorType.AddRule: ((IPreprocessorAddRuleDirective)(directive)).Expand(currentEntry, availableStock, argumentLookup, entry, file, errors); break; case EntryPreprocessorType.Throw: ((IPreprocessorThrowDirective)(directive)).Expand(currentEntry, availableStock, argumentLookup, entry, file, errors); break; case EntryPreprocessorType.Return: return(((IPreprocessorConditionalReturnDirective)(directive)).Expand(currentEntry, availableStock, argumentLookup, entry, file, errors)); } return(null); }
/// <summary> /// The execute transaction inner. /// </summary> /// <param name="solution"> /// The solution. /// </param> /// <param name="textControl"> /// The text control. /// </param> public override void ExecuteTransactionInner(ISolution solution, ITextControl textControl) { Utils.FormatLineForTextControl(solution, textControl); ITreeNode element = Utils.GetElementAtCaret(solution, textControl); IPreprocessorDirective containingBlock = element.GetContainingNode <IPreprocessorDirective>(true); if (containingBlock != null) { SpacingRules.PreprocessorKeywordsMustNotBePrecededBySpace(containingBlock); } }
public static IPreprocessorDirective ResolveProductionRuleItem<T>(this IPreprocessorDirective item, T entry, OilexerGrammarFile file, ICompilerErrorCollection errors) where T : IOilexerGrammarProductionRuleEntry { switch (item.Type) { case EntryPreprocessorType.If: case EntryPreprocessorType.IfNotDefined: case EntryPreprocessorType.IfDefined: case EntryPreprocessorType.ElseIf: case EntryPreprocessorType.ElseIfDefined: case EntryPreprocessorType.Else: IPreprocessorIfDirective ipid = ((IPreprocessorIfDirective)(item)); PreprocessorIfDirective pid = new PreprocessorIfDirective(item.Type, ((IPreprocessorIfDirective)item).Condition, entry.FileName, item.Column, item.Line, item.Position); foreach (IPreprocessorDirective ipd in ipid.Body) ((PreprocessorIfDirective.DirectiveBody)(pid.Body)).Add(ipd.ResolveProductionRuleItem(entry, file, errors)); if (ipid.Next != null) pid.Next = (IPreprocessorIfDirective)ipid.Next.ResolveProductionRuleItem(entry, file, errors); return pid; case EntryPreprocessorType.DefineRule: IPreprocessorDefineRuleDirective ipdd = ((IPreprocessorDefineRuleDirective)(item)); IProductionRule[] dr = new IProductionRule[ipdd.DefinedRules.Length]; for (int i = 0; i < ipdd.DefinedRules.Length; i++) { dr[i] = ipdd.DefinedRules[i].Clone(); dr[i].ResolveProductionRule(entry, file, errors); } return new PreprocessorDefineRuleDirective(ipdd.DeclareTarget, dr, ipdd.Column, ipdd.Line, ipdd.Position); case EntryPreprocessorType.AddRule: IPreprocessorAddRuleDirective ipard = ((IPreprocessorAddRuleDirective)(item)); IProductionRule[] ar = new IProductionRule[ipard.Rules.Length]; for (int i = 0; i < ipard.Rules.Length; i++) { ar[i] = ipard.Rules[i].Clone(); ar[i].ResolveProductionRule(entry, file, errors); } return new PreprocessorAddRuleDirective(ipard.InsertTarget, ar, ipard.Column, ipard.Line, ipard.Position); case EntryPreprocessorType.Throw: return item; case EntryPreprocessorType.Return: IPreprocessorConditionalReturnDirective ipcrd = ((IPreprocessorConditionalReturnDirective)(item)); IProductionRule[] crd = new IProductionRule[ipcrd.Result.Length]; for (int i = 0; i < ipcrd.Result.Length; i++) { crd[i] = ipcrd.Result[i].Clone(); crd[i].ResolveProductionRule(entry, file, errors); } return new PreprocessorConditionalReturnDirective(crd, ipcrd.Column, ipcrd.Line, ipcrd.Position); } return item; }
private static void ProcessCSharpPreprocessorDirective([NotNull] IPreprocessorDirective preprocessorDirective, [NotNull] CodeStructureElement parentElement, [NotNull] CSharpCodeStructureProcessingState state) { switch (preprocessorDirective.Kind) { case PreprocessorDirectiveKind.REGION: state.Regions.Push(new T4CSharpCodeStructureRegion(parentElement, preprocessorDirective, state)); break; case PreprocessorDirectiveKind.ENDREGION: state.Regions.TryPop(); // ReSharper disable ObjectCreationAsStatement new T4CSharpCodeStructureRegionEnd(parentElement, preprocessorDirective, state); // ReSharper restore ObjectCreationAsStatement break; } }
protected void Body_Add(IPreprocessorDirective directive) { ((DirectiveBody)this.Body).Add(directive); }
/// <summary> /// Creates a new <see cref="ProductionRulePreprocessorDirective"/> with the /// <paramref name="column"/>, <paramref name="line"/>, and <paramref name="position"/>. /// </summary> /// <param name="column">The column on <paramref name="line"/> at which the <see cref="ProductionRulePreprocessorDirective"/> was /// defined.</param> /// <param name="line">The line at which the <see cref="ProductionRulePreprocessorDirective"/> was defined.</param> /// <param name="position">The byte in the file at which the <see cref="ProductionRulePreprocessorDirective"/> was declared.</param> public ProductionRulePreprocessorDirective(IPreprocessorDirective directive, int column, int line, long position) : base(column, line, position) { this.directive = directive; }