/// <summary> /// Extends an absolute identifier with new identifier components. /// </summary> public FullSymbol Combine(SymbolTable table, PartialSymbol identifier) { Contract.RequiresNotNull(table, "table != null"); Contract.Requires(identifier.IsValid); return(AddIdentifierComponents(table, this, identifier.Components)); }
public bool TryGetRelative(SymbolTable table, FullSymbol proposedRelativeId, out PartialSymbol result) { Contract.Requires(table != null, "table != null"); Contract.Requires(proposedRelativeId.IsValid); string str; bool b = table.TryExpandNameRelativeToAnother(Value, proposedRelativeId.Value, out str); result = b ? PartialSymbol.Create(table.StringTable, str) : PartialSymbol.Invalid; return(b); }
/// <summary> /// Adds a identifier that might be relative, abandons if the identifier is invalid. /// </summary> /// <remarks> /// This is useful for hard-coded identifiers, don't use with any user input since it will kill the process on bad format. /// </remarks> /// <param name="table">The identifier table to use.</param> /// <param name="relativeId">The identifier to add. If absolute this will be the identifier returned, otherwise the relative identifier is tacked onto the end of the base identifier.</param> /// <returns>Final resulting absolute identifier.</returns> public FullSymbol Combine(SymbolTable table, StringSegment relativeId) { Contract.RequiresNotNull(table, "table != null"); PartialSymbol relIdentifier; PartialSymbol.ParseResult parseResult = PartialSymbol.TryCreate(table.StringTable, relativeId, out relIdentifier, out _); if (parseResult != PartialSymbol.ParseResult.Success) { Contract.Assume(false, I($"Failed to create a full symbol from the segment '{relativeId.ToString()}'")); } return(AddIdentifierComponents(table, this, relIdentifier.Components)); }
public bool TryGet(SymbolTable table, PartialSymbol relativeId, out FullSymbol result) { Contract.RequiresNotNull(table, "table != null"); if (relativeId.IsEmpty) { result = this; return(true); } HierarchicalNameId child; var found = table.TryGetName(Value, relativeId.Components, out child); result = new FullSymbol(child); return(found); }
/// <summary> /// Adds a identifier that might be relative, abandons if the identifier is invalid. /// </summary> /// <remarks> /// This is useful for hard-coded identifiers, don't use with any user input since it will kill the process on bad format. /// </remarks> /// <param name="table">The identifier table to use.</param> /// <param name="relativeId">The identifier to add. If absolute this will be the identifier returned, otherwise the relative identifier is tacked onto the end of the base identifier.</param> /// <returns>Final resulting absolute identifier.</returns> public FullSymbol Combine(SymbolTable table, StringSegment relativeId) { Contract.Requires(table != null, "table != null"); Contract.Ensures(Contract.Result <FullSymbol>() != FullSymbol.Invalid); int characterWithError; PartialSymbol relIdentifier; PartialSymbol.ParseResult parseResult = PartialSymbol.TryCreate(table.StringTable, relativeId, out relIdentifier, out characterWithError); if (parseResult != PartialSymbol.ParseResult.Success) { Contract.Assume(false, I($"Failed to create a full symbol from the segment '{relativeId.ToString()}'")); } return(AddIdentifierComponents(table, this, relIdentifier.Components)); }
public bool TryGet(SymbolTable table, PartialSymbol relativeId, out FullSymbol result) { Contract.Requires(table != null, "table != null"); Contract.Ensures(Contract.Result <bool>() == (Contract.ValueAtReturn(out result) != FullSymbol.Invalid)); if (relativeId.IsEmpty) { result = this; return(true); } HierarchicalNameId child; var found = table.TryGetName(Value, relativeId.Components, out child); result = new FullSymbol(child); return(found); }
/// <summary> /// Tries to break down an absolute identifier string into its constituent parts. /// </summary> private static ParseResult TryGetComponents(SymbolTable table, StringSegment fullSymbol, out StringId[] components, out int characterWithError) { Contract.RequiresNotNull(table, "table != null"); PartialSymbol relIdentifier; PartialSymbol.ParseResult parseResult = PartialSymbol.TryCreate(table.StringTable, fullSymbol, out relIdentifier, out characterWithError); if (parseResult == PartialSymbol.ParseResult.Success) { components = relIdentifier.Components; characterWithError = -1; return(ParseResult.Success); } components = null; return(parseResult == PartialSymbol.ParseResult.LeadingOrTrailingDot ? ParseResult.LeadingOrTrailingDot : ParseResult.FailureDueToInvalidCharacter); }
/// <summary> /// Determines whether a particular character is valid within an absolute identifier. /// </summary> public static bool IsValidAbsoluteIdChar(char value) { return(PartialSymbol.IsValidRelativeIdChar(value)); }