internal ProductionRuleLiteralTokenItemReferenceStructuralItem(IOilexerGrammarTokenEntry initialSourceEntry, ILiteralReferenceProductionRuleItem initialReference, IOilexerGrammarProductionRuleEntry rule) : base(initialReference, rule, ResultedDataType.ImportType) { this.SourceEntries = new IOilexerGrammarTokenEntry[1] { initialSourceEntry }; }
/// <summary> /// Creates a new <see cref="InlinedTokenExpressionSeries"/> with the /// <paramref name="source"/>, <paramref name="sourceRoot"/> and /// <paramref name="root"/> /// </summary> /// <param name="source">The <see cref="TokenExpressionSeries"/> from which the current /// <see cref="InlinedTokenExpressionSeries"/> derives.</param> /// <param name="sourceRoot">The <see cref="IOilexerGrammarTokenEntry"/> which contains the /// <paramref name="source"/>.</param> /// <param name="root">The <see cref="InlinedTokenEntry"/> which contains the <see cref="InlinedTokenExpressionSeries"/>.</param> public InlinedTokenExpressionSeries(ITokenExpressionSeries source, IOilexerGrammarTokenEntry sourceRoot, InlinedTokenEntry root, IDictionary <ITokenItem, ITokenItem> oldNewLookup) : base(OilexerGrammarInliningCore.Inline(source.ToArray(), sourceRoot, root, oldNewLookup), source.Line, source.Column, source.Position, source.FileName) { this.Source = source; this.SourceRoot = SourceRoot; this.Root = root; }
private static IProductionRuleItem Deliteralize <T, TLiteral>(this ILiteralProductionRuleItem <T> literal, IOilexerGrammarProductionRuleEntry currentEntry, IList <IOilexerGrammarTokenEntry> availableStock, OilexerGrammarFile file, Func <ILiteralProductionRuleItem <T>, TLiteral> createNewLiteral, Func <TLiteral, IOilexerGrammarTokenEntry, IProductionRuleItem> createLiteralReference, ICompilerErrorCollection errors) where TLiteral : ILiteralTokenItem <T> { { ITokenItem foundItem = null; IOilexerGrammarTokenEntry literalContainerEntry = null; if ((foundItem = FindItemFromStock <T>(literal, currentEntry, availableStock, out literalContainerEntry, file, false)) != null) { var result = createLiteralReference(((TLiteral)(foundItem)), literalContainerEntry); ((LiteralProductionRuleItem <T>)literal).CloneData(result); return(result); } } IOilexerGrammarTokenEntry extractionsToken; if ((extractionsToken = availableStock.OilexerGrammarFindScannableEntry("__EXTRACTIONS")) == null) { extractionsToken = new OilexerGrammarTokenEntry("__EXTRACTIONS", new TokenExpressionSeries(new ITokenExpression[0], literal.Line, literal.Column, literal.Position, currentEntry.FileName), currentEntry.ScanMode, currentEntry.FileName, literal.Column, literal.Line, literal.Position, false, new List <OilexerGrammarTokens.IdentifierToken>(), false); availableStock.Add(extractionsToken); file.Add(extractionsToken); } TLiteral tokenLiteralItem = createNewLiteral(literal); ((TokenExpressionSeries)extractionsToken.Branches).Add(new TokenExpression(new List <ITokenItem>(new ITokenItem[] { tokenLiteralItem }), currentEntry.FileName, literal.Column, literal.Line, literal.Position)); var tokenReferenceItem = createLiteralReference(((TLiteral)(tokenLiteralItem)), extractionsToken); ((LiteralProductionRuleItem <T>)literal).CloneData(tokenReferenceItem); return(tokenReferenceItem); }
private static void ReplaceTokenReference(IProductionRule target, IOilexerGrammarTokenEntry sourceElement, InlinedTokenEntry destination) { foreach (var item in target) { ReplaceTokenReference(item, sourceElement, destination); } }
private static void ReplaceTokenReference(IOilexerGrammarTokenEntry sourceElement, InlinedTokenEntry destination) { foreach (var rule in OilexerGrammarLinkerCore.ruleEntries) { ReplaceTokenReference(rule, sourceElement, destination); } }
public void ResolvedSinglePartToToken(ISoftReferenceTokenItem item, IOilexerGrammarTokenEntry primary) { if (item.PrimaryToken != null) { this.handler.ReclassifyToken(item.PrimaryToken, primary); } }
private static ITokenItem ResolveTokenExpressionItem(this ITokenItem item, IOilexerGrammarTokenEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { if (item is ITokenGroupItem) { ((ITokenGroupItem)(item)).ResolveTokenExpressionSeries(entry, file, errors); return item; } else if (item is ISoftReferenceTokenItem) { return ((ISoftReferenceTokenItem)(item)).ResolveSoftReference(entry, file, errors); } else if (item is ICommandTokenItem) { ((ICommandTokenItem)(item)).ResolveSoftReference(entry, file, errors); return item; } else if (item is ILiteralStringTokenItem) { ILiteralStringTokenItem ilsti = ((ILiteralStringTokenItem)item); if (ilsti.Value.Length == 1) { LiteralCharTokenItem result = new LiteralCharTokenItem(ilsti.Value[0], ilsti.CaseInsensitive, ilsti.Column, ilsti.Line, ilsti.Position); ((LiteralStringTokenItem)(item)).CloneData(result); return result; } }//*/ return item; }
public LiteralReferenceProductionRuleItem(TLiteral literal, IOilexerGrammarTokenEntry source, int column, int line, long position, bool wasFlag, bool wasCounter) : base(column, line, position) { this.literal = literal; this.source = source; this.isFlag = wasFlag; this.counter = wasCounter; }
/// <summary> /// Creates a new <see cref="TokenReferenceTokenItem"/> with the <paramref name="reference"/>, /// <paramref name="column"/>, <paramref name="line"/>, and <paramref name="position"/>. /// </summary> /// <param name="reference">The <see cref="IOilexerGrammarTokenEntry"/> that the <see cref="ITokenReferenceTokenItem"/> /// references.</param> /// <param name="column">The column on <paramref name="line"/> at which the <see cref="TokenReferenceTokenItem"/> was /// defined.</param> /// <param name="line">The line at which the <see cref="TokenReferenceTokenItem"/> was defined.</param> /// <param name="position">The byte in the file at which the <see cref="TokenReferenceTokenItem"/> was declared.</param> public TokenReferenceTokenItem(IOilexerGrammarTokenEntry reference, int column, int line, long position) : base(column, line, position) { if (reference == null) { throw new ArgumentNullException("reference"); } this.reference = reference; }
/// <summary> /// Creates a new <see cref="InlinedTokenEntry"/> with the <paramref name="source"/> /// provided. /// </summary> /// <param name="source">The <see cref="IOilexerGrammarTokenEntry"/> from which the /// current <see cref="InlinedTokenEntry"/> derives.</param> public InlinedTokenEntry(IOilexerGrammarTokenEntry source, IOilexerGrammarFile file) : base(source.Name, null, source.ScanMode, source.FileName, source.Column, source.Line, source.Position, source.Unhinged, source.LowerPrecedenceTokens, source.ForcedRecognizer) { this.OldNewLookup = new Dictionary <ITokenItem, ITokenItem>(); this.branches = OilexerGrammarInliningCore.Inline(source.Branches, source, this, this.OldNewLookup); this.Source = source; this.file = file; this.Contextual = source.Contextual; }
public InlinedCharRangeTokenItem(ICharRangeTokenItem source, IOilexerGrammarTokenEntry sourceRoot, InlinedTokenEntry root) : base(source.Inverted, source.Range, source.Line, source.Column, source.Position) { this.Source = source; this.SourceRoot = sourceRoot; this.Root = root; this.RepeatOptions = source.RepeatOptions; this.Name = source.Name; this.SiblingAmbiguity = source.SiblingAmbiguity; }
public InlinedScanCommandTokenItem(IScanCommandTokenItem source, IOilexerGrammarTokenEntry sourceRoot, InlinedTokenEntry root, IDictionary <ITokenItem, ITokenItem> oldNewLookup) : base(OilexerGrammarInliningCore.Inline(source.SearchTarget, sourceRoot, root, oldNewLookup), source.SeekPast, source.Column, source.Line, source.Position) { this.Source = source; this.SourceRoot = sourceRoot; this.Root = root; this.RepeatOptions = source.RepeatOptions; this.SiblingAmbiguity = source.SiblingAmbiguity; this.Name = source.Name; }
public InlinedTokenGroupItem(ITokenGroupItem source, IOilexerGrammarTokenEntry sourceRoot, InlinedTokenEntry root, IDictionary <ITokenItem, ITokenItem> oldNewLookup) : base(source.FileName, OilexerGrammarInliningCore.Inline(source.ToArray(), sourceRoot, root, oldNewLookup), source.Column, source.Line, source.Position) { this.Source = source; this.SourceRoot = sourceRoot; this.Root = root; this.RepeatOptions = source.RepeatOptions; this.Name = source.Name; this.SiblingAmbiguity = source.SiblingAmbiguity; }
/// <summary> /// Creates a new <see cref="InlinedLiteralStringTokenItem"/> with the /// <paramref name="source"/>, and <paramref name="parent"/> provided. /// </summary> /// <param name="source">The <see cref="ILiteralStringTokenItem"/> from which /// the <see cref="InlinedLiteralStringTokenItem"/> is derived.</param> /// <param name="sourceRoot">The <see cref="IOilexerGrammarTokenEntry"/> which contains /// the <paramref name="source"/>.</param> /// <param name="root">The <see cref="InlinedTokenEntry"/> which roots the entire /// token structure.</param> public InlinedLiteralStringTokenItem(ILiteralStringTokenItem source, IOilexerGrammarTokenEntry sourceRoot, InlinedTokenEntry root) : base(source.Value, source.CaseInsensitive, source.Column, source.Line, source.Position, source.SiblingAmbiguity) { this.SourceRoot = sourceRoot; this.Source = source; this.Root = root; this.SiblingAmbiguity = source.SiblingAmbiguity; this.RepeatOptions = source.RepeatOptions; this.Name = source.Name; }
public void ResolvedDualPartToTokenItem(ISoftReferenceTokenItem item, IOilexerGrammarTokenEntry primary, ITokenItem secondary) { if (item.PrimaryToken != null) { this.handler.ReclassifyToken(item.PrimaryToken, primary); } if (item.SecondaryToken != null) { this.handler.ReclassifyToken(item.SecondaryToken, secondary); } }
private static void ResolveTokenExpression(this ITokenExpression expression, IOilexerGrammarTokenEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { IList<ITokenItem> rCopy = (from item in expression select item).ToList(); TokenExpression te = expression as TokenExpression; IEnumerable<ITokenItem> finalVersion = from item in rCopy select (item.ResolveTokenExpressionItem(entry, file, errors)); te.BaseCollection.Clear(); foreach (ITokenItem iti in finalVersion) te.BaseCollection.Add(iti); }
internal static RegularCaptureType DetermineKind(IOilexerGrammarTokenEntry entry, ITokenExpressionSeries series, IOilexerGrammarFile file) { RegularCaptureType result = RegularCaptureType.Undecided; foreach (var expression in series) { var currentKind = DetermineKind(entry, expression, file); switch (currentKind) { case RegularCaptureType.Recognizer: if (result == RegularCaptureType.Undecided) { result = currentKind; } break; case RegularCaptureType.Capturer: result = currentKind; break; case RegularCaptureType.Transducer: if (result == RegularCaptureType.Undecided) { result = RegularCaptureType.Transducer; } else if (result == RegularCaptureType.Recognizer) { result = RegularCaptureType.Capturer; } break; } } if (result == RegularCaptureType.Undecided) { result = RegularCaptureType.Recognizer; } if (result == RegularCaptureType.Transducer) { if ((from gdEntry in file where gdEntry is IOilexerGrammarProductionRuleEntry let ruleEntry = (IOilexerGrammarProductionRuleEntry)gdEntry from productionRuleItem in GetProductionRuleSeriesItems(ruleEntry) where productionRuleItem is ILiteralReferenceProductionRuleItem let literalItem = (ILiteralReferenceProductionRuleItem)productionRuleItem where literalItem.Source == entry select literalItem).Count() > 0) { return(RegularCaptureType.ContextfulTransducer); } } return(result); }
public static string GetDocComment(this IOilexerGrammarTokenEntry entry) { StringBuilder s = new StringBuilder(); if (entry == null || entry is IOilexerGrammarTokenEofEntry) { return(string.Empty); } s.Append(entry.ToString().Replace('\x20', '\xA0')); return(s.ToString()); }
private static ITokenItem ResolveSoftReference(this ISoftReferenceTokenItem item, IOilexerGrammarTokenEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { IOilexerGrammarTokenEntry tokenE = tokenEntries.OilexerGrammarFindScannableEntry(item.PrimaryName); if (tokenE != null) { if (item.SecondaryName != null) { ITokenItem iti = tokenE.FindTokenItem(item.SecondaryName); if (iti != null) { if (iti is ILiteralCharTokenItem) { LiteralCharReferenceTokenItem result = new LiteralCharReferenceTokenItem(tokenE, ((ILiteralCharTokenItem)(iti)), item.Column, item.Line, item.Position); if (!(string.IsNullOrEmpty(item.Name))) result.Name = item.Name; if (resolutionAid != null) resolutionAid.ResolvedDualPartToTokenItem(item, tokenE, iti); return result; } else if (iti is ILiteralStringTokenItem) { LiteralStringReferenceTokenItem result = new LiteralStringReferenceTokenItem(tokenE, ((ILiteralStringTokenItem)(iti)), item.Column, item.Line, item.Position); if (!(string.IsNullOrEmpty(item.Name))) result.Name = item.Name; if (resolutionAid != null) resolutionAid.ResolvedDualPartToTokenItem(item, tokenE, iti); return result; } else { errors.SourceModelError<ISoftReferenceTokenItem>(OilexerGrammarCore.CompilerErrors.UndefinedTokenReference, new LineColumnPair(item.Line, item.Column), new LineColumnPair(item.Line, item.Column + item.PrimaryName.Length), new Uri(entry.FileName, UriKind.RelativeOrAbsolute), item, string.Format(" '{0}'", item.PrimaryName)); } } } else { TokenReferenceTokenItem result = new TokenReferenceTokenItem(tokenE, item.Column, item.Line, item.Position); ((SoftReferenceTokenItem)(item)).CloneData(result); if (resolutionAid != null) resolutionAid.ResolvedSinglePartToToken(item, tokenE); return result; } } else if (item.SecondaryName == null) errors.SourceModelError<ISoftReferenceTokenItem>(OilexerGrammarCore.CompilerErrors.UndefinedTokenReference, new LineColumnPair(item.Line, item.Column), new LineColumnPair(item.Line, item.Column + item.PrimaryName.Length), new Uri(entry.FileName, UriKind.RelativeOrAbsolute), item, string.Format(" '{0}'", item.PrimaryName)); else errors.SourceModelError<ISoftReferenceTokenItem>(OilexerGrammarCore.CompilerErrors.UndefinedTokenReference, new LineColumnPair(item.Line, item.Column), new LineColumnPair(item.SecondaryToken.Line, item.SecondaryToken.Column + item.SecondaryToken.Length), new Uri(entry.FileName, UriKind.RelativeOrAbsolute), item, string.Format(" '{0}'", item.PrimaryName)); return item; }
public bool Contains(IOilexerGrammarTokenEntry entry) { var tSymbols = from symbol in this.symbols let tokenSymbol = symbol as IGrammarTokenSymbol where tokenSymbol != null && tokenSymbol.Source == entry select(uint) symbols.IndexOf(tokenSymbol); foreach (var tokenSymbolIndex in tSymbols) { if (this.Offset <= tokenSymbolIndex && Offset + this.Length > tokenSymbolIndex && this[tokenSymbolIndex]) { return(true); } } return(false); }
private static void ResolveSoftReference(this ICommandTokenItem source, IOilexerGrammarTokenEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { if (source is IScanCommandTokenItem) { var scanSource = source as ScanCommandTokenItem; scanSource.SearchTarget.ResolveTokenExpressionSeries(entry, file, errors); } else if (source is ISubtractionCommandTokenItem) { var subtractSource = source as SubtractionCommandTokenItem; subtractSource.Left.ResolveTokenExpressionSeries(entry, file, errors); subtractSource.Right.ResolveTokenExpressionSeries(entry, file, errors); } else if (source is IBaseEncodeGraphCommand) { var graph = source as BaseEncodeGraphCommand; graph.EncodeTarget.ResolveTokenExpressionSeries(entry, file, errors); } }
private static void ResolveProductionRuleTemplate(this IOilexerGrammarProductionRuleTemplateEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { foreach (ProductionRuleTemplatePart part in entry.Parts) { IOilexerGrammarTokenEntry reference = null; if (part.SpecialExpectancy == TemplatePartExpectedSpecial.None && part.ExpectedSpecific != null && part.ExpectedSpecific is ISoftReferenceProductionRuleItem) { var softExpect = part.ExpectedSpecific as ISoftReferenceProductionRuleItem; if ((reference = tokenEntries.OilexerGrammarFindScannableEntry(softExpect.PrimaryName)) != null) { part.ExpectedSpecific = new TokenReferenceProductionRuleItem(reference, part.Column, part.Line, part.Position); if (resolutionAid != null) resolutionAid.ResolvedSinglePartToToken(softExpect, reference); } else errors.SourceModelError<ISoftReferenceProductionRuleItem>(OilexerGrammarCore.CompilerErrors.UndefinedTokenReference, new LineColumnPair(part.ExpectedSpecific.Column, part.ExpectedSpecific.Line), LineColumnPair.Zero, new Uri(entry.FileName, UriKind.RelativeOrAbsolute), softExpect, string.Format(" '{0}'", softExpect.PrimaryName)); return; } } }
private static void ReplaceTokenReference(IProductionRuleItem target, IOilexerGrammarTokenEntry sourceElement, InlinedTokenEntry destination) { if (target is IProductionRuleGroupItem) { ReplaceTokenReference((IProductionRuleSeries)target, sourceElement, destination); } else if (target is ITokenReferenceProductionRuleItem) { var tTarget = target as TokenReferenceProductionRuleItem; if (tTarget.Reference != sourceElement) { return; } tTarget.Reference = destination; } else if (target is ILiteralStringReferenceProductionRuleItem) { var tTarget = target as LiteralStringReferenceProductionRuleItem; if (tTarget.Source != sourceElement) { return; } tTarget.Source = destination; /* * * The inlined token provides a lookup to assist * reference replacement. * */ tTarget.Literal = (ILiteralStringTokenItem)destination.OldNewLookup[tTarget.Literal]; } else if (target is ILiteralCharReferenceProductionRuleItem) { var tTarget = target as LiteralCharReferenceProductionRuleItem; if (tTarget.Source != sourceElement) { return; } tTarget.Source = destination; tTarget.Literal = (ILiteralCharTokenItem)destination.OldNewLookup[tTarget.Literal]; } }
private static void ResolveToken(this IOilexerGrammarTokenEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { List<IOilexerGrammarTokenEntry> lowerTokens = new List<IOilexerGrammarTokenEntry>(); if (entry.LowerPrecedenceTokens == null) { foreach (var s in entry.LowerPrecedenceNames) { var match = (from generalEntry in tokenEntries let tokenEntry = generalEntry as IOilexerGrammarTokenEntry where tokenEntry != null && tokenEntry.Name == s.Name select tokenEntry).FirstOrDefault(); if (match == null) { errors.SourceModelError<IOilexerGrammarTokenEntry>(OilexerGrammarCore.CompilerErrors.UndefinedTokenReference, new LineColumnPair(s.Line, s.Column), new LineColumnPair(s.Line, s.Column + s.Name.Length), new Uri(entry.FileName, UriKind.RelativeOrAbsolute), entry, string.Format(@", lower precedence: '{0}'", s.Name)); break; } lowerTokens.Add(match); } ((OilexerGrammarTokenEntry)entry).LowerPrecedenceTokens = lowerTokens.ToArray(); } entry.Branches.ResolveTokenExpressionSeries(entry, file, errors); }
private static void ResolveTokenExpressionSeries(this ITokenExpressionSeries series, IOilexerGrammarTokenEntry entry, OilexerGrammarFile file, ICompilerErrorCollection errors) { foreach (ITokenExpression ite in series) ite.ResolveTokenExpression(entry, file, errors); }
protected override void DefineTokenIdentifier(OilexerGrammarTokens.IdentifierToken tokenIdentifier, IOilexerGrammarTokenEntry tokenEntry) { this.Handler.ReclassifyToken(tokenIdentifier, tokenEntry); }
public RegularLanguageDFARootState(IOilexerGrammarTokenEntry entry) { this.entry = entry; }
/// <summary> /// Creates a new <see cref="LiteralReferenceProductionRuleItem{TValue, TLiteral}"/> with the /// <paramref name="column"/>, <paramref name="line"/>, and <paramref name="position"/>. /// </summary> /// <param name="literal">The <typeparamref name="TLiteral"/> which the <see cref="LiteralReferenceProductionRuleItem{TValue, TLiteral}"/> /// references.</param> /// <param name="source">The <see cref="IOilexerGrammarTokenEntry"/> which the contains the <paramref name="literal"/> the <see cref="LiteralReferenceProductionRuleItem{TValue, TLiteral}"/> /// references.</param> /// <param name="column">The column on <paramref name="line"/> at which the <see cref="LiteralReferenceProductionRuleItem{TValue, TLiteral}"/> was /// defined.</param> /// <param name="line">The line at which the <see cref="LiteralReferenceProductionRuleItem{TValue, TLiteral}"/> was defined.</param> /// <param name="position">The byte in the file at which the <see cref="LiteralReferenceProductionRuleItem{TValue, TLiteral}"/> was declared.</param> public LiteralReferenceProductionRuleItem(TLiteral literal, IOilexerGrammarTokenEntry source, int column, int line, long position) : base(column, line, position) { this.literal = literal; this.source = source; }
public LiteralCharReferenceTokenItem(IOilexerGrammarTokenEntry entryReference, ILiteralCharTokenItem reference, int column, int line, long position) : base(entryReference, reference, column, line, position) { }
internal void ReclassifyToken(OilexerGrammarTokens.IdentifierToken identifierToken, IOilexerGrammarTokenEntry primary) { if (reclassifications.ContainsKey(identifierToken)) { return; } reclassifications.Add(identifierToken, OilexerGrammarTokenType.TokenReference); }