public static void FinalLink(this IOilexerGrammarProductionRuleEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { if (entry.NeedsFinalLinking()) { List <IProductionRule> result = new List <IProductionRule>(); foreach (IProductionRule currentItem in entry) { IProductionRule resultIPR = null; if (currentItem.NeedsFinalLinking()) { resultIPR = currentItem.FinalLink(entry, file, errors); } else { resultIPR = currentItem; } if (resultIPR != null) { result.Add(resultIPR); } } OilexerGrammarProductionRuleEntry r = ((OilexerGrammarProductionRuleEntry)(entry)); r.Clear(); foreach (IProductionRule ipr in result) { r.Add(ipr); } } }
public static void Deliteralize(this IOilexerGrammarProductionRuleEntry entry, IList <IOilexerGrammarTokenEntry> availableStock, OilexerGrammarFile file, ICompilerErrorCollection errors) { if (entry.NeedsDeliteralized()) { List <IProductionRule> result = new List <IProductionRule>(); foreach (IProductionRule ipr in entry) { IProductionRule resultIPR = null; if (ipr.NeedsDeliteralized()) { resultIPR = ipr.Deliteralize(entry, availableStock, file, errors); } else { resultIPR = ipr; } if (resultIPR != null) { result.Add(resultIPR); } } OilexerGrammarProductionRuleEntry r = ((OilexerGrammarProductionRuleEntry)(entry)); r.Clear(); foreach (IProductionRule ipr in result) { r.Add(ipr); } //currentEntry = null; } }
public static void ReplaceReferences(IOilexerGrammarFile source, IOilexerGrammarProductionRuleEntry target, IDictionary <IProductionRuleItem, IProductionRuleItem> elementToElementList) { OilexerGrammarProductionRuleEntry r = (OilexerGrammarProductionRuleEntry)(target); IProductionRuleSeries resultSeries = ReplaceReferences(source, ((IProductionRuleSeries)(r)).ToArray(), elementToElementList); r.Clear(); foreach (var rule in resultSeries) { r.Add(rule); } }
internal static void ExpandTemplates(this IOilexerGrammarProductionRuleEntry entry, IList <IOilexerGrammarTokenEntry> availableStock, OilexerGrammarFile file, ICompilerErrorCollection errors) { while (entry.NeedsExpansion()) { OilexerGrammarProductionRuleEntry e = ((OilexerGrammarProductionRuleEntry)(entry)); IProductionRuleSeries iprs = entry.ExpandTemplates(availableStock, entry, file, errors); e.Clear(); foreach (IProductionRule ipr in iprs) { e.Add(ipr); } } }
internal static void Expand(this IPreprocessorAddRuleDirective directive, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { string search = directive.InsertTarget; if (search != null && search != string.Empty) { OilexerGrammarProductionRuleEntry foundItem = null; if (argumentLookup.ContainsParameter(search)) { IProductionRuleTemplatePart part = argumentLookup.GetParameter(search); IProductionRuleSeries iprs = argumentLookup[part]; if (iprs.Count == 1 && iprs[0].Count == 1) { IProductionRuleItem ipri = iprs[0][0]; if (ipri is ISoftReferenceProductionRuleItem) { ISoftReferenceProductionRuleItem n = (ISoftReferenceProductionRuleItem)ipri; search = n.PrimaryName; } else if (ipri is IRuleReferenceProductionRuleItem) { foundItem = (OilexerGrammarProductionRuleEntry)((IRuleReferenceProductionRuleItem)(ipri)).Reference; } } } if (foundItem == null) { foreach (IOilexerGrammarEntry ie in file) { if (ie is OilexerGrammarProductionRuleEntry && ((OilexerGrammarProductionRuleEntry)ie).Name == search) { foundItem = ie as OilexerGrammarProductionRuleEntry; break; } } } if (foundItem == null) { errors.SourceError(OilexerGrammarCore.CompilerErrors.UndefinedAddRuleTarget, new LineColumnPair(directive.Line, directive.Column), LineColumnPair.Zero, new Uri(entry.FileName, UriKind.RelativeOrAbsolute), string.Join <IProductionRule>(" | ", directive.Rules), search); return; } foreach (IProductionRule ipr in directive.Rules) { foundItem.Add(ipr.Expand(currentEntry, availableStock, argumentLookup, entry, file, errors)); } } }
internal static void Expand(this IPreprocessorDefineRuleDirective directive, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, ProductionRuleTemplateArgumentSeries argumentLookup, IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { string search = directive.DeclareTarget; if (search != null && search != string.Empty) { if (argumentLookup.ContainsParameter(search)) { IProductionRuleTemplatePart part = argumentLookup.GetParameter(search); IProductionRuleSeries iprs = argumentLookup[part]; if (iprs.Count == 1 && iprs[0].Count == 1) { IProductionRuleItem ipri = iprs[0][0]; if (ipri is ISoftReferenceProductionRuleItem) { ISoftReferenceProductionRuleItem n = (ISoftReferenceProductionRuleItem)ipri; search = n.PrimaryName; } } } /* ToDo: Evaluate the depth necessary to institute a lock associated to the base list on the oilexer grammar file type. */ IOilexerGrammarEntry[] fileElements; lock (file) fileElements = file.ToArray(); foreach (IOilexerGrammarEntry ie in fileElements) { if (ie is IOilexerGrammarNamedEntry && ((IOilexerGrammarNamedEntry)ie).Name == search) { errors.SourceError(OilexerGrammarCore.CompilerErrors.DuplicateTermDefined, new LineColumnPair(directive.Line, directive.Column), LineColumnPair.Zero, new Uri(entry.FileName, UriKind.RelativeOrAbsolute), search); return; } } OilexerGrammarProductionRuleEntry insertedItem = new OilexerGrammarProductionRuleEntry(search, entry.ScanMode, entry.FileName, directive.Column, directive.Line, directive.Position); lock (file) file.Add(insertedItem); foreach (IProductionRule ipr in directive.DefinedRules) { IProductionRule expanded = ipr.Expand(currentEntry, availableStock, argumentLookup, entry, file, errors); insertedItem.Add(expanded); } } }