public PkgdefRegistryKeySegment(IReadOnlyList <PkgdefSegment> segments) { PreCondition.AssertNotNullAndNotEmpty(segments, nameof(segments)); PreCondition.AssertEqual(segments[0].GetSegmentType(), PkgdefSegmentType.RegistryKeyPath, "segments[0].GetSegmentType()"); this.segments = segments; }
public PkgdefRegistryKeyPathSegment(IReadOnlyList <PkgdefToken> tokens) { PreCondition.AssertNotNullAndNotEmpty(tokens, nameof(tokens)); PreCondition.AssertEqual(tokens[0].GetTokenType(), PkgdefTokenType.LeftSquareBracket, "tokens[0].GetTokenType()"); this.tokens = tokens; }
internal static PkgdefRegistryKeyPathSegment ParseRegistryKeyPath(int startIndex, string text) { PreCondition.AssertGreaterThanOrEqualTo(startIndex, 0, nameof(startIndex)); PreCondition.AssertNotNullAndNotEmpty(text, nameof(text)); PreCondition.AssertEqual(text[0], '[', "text[0]"); Action <PkgdefIssue> onIssue = PkgdefDocument.IgnoreIssue; PkgdefTokenizer tokenizer = PkgdefTokenizer.Create(startIndex, text, onIssue); tokenizer.Next(); return(PkgdefDocument.ParseRegistryKeyPath(tokenizer, onIssue)); }
internal static PkgdefRegistryKeyPathSegment ParseRegistryKeyPath(PkgdefTokenizer tokenizer, Action <PkgdefIssue> onIssue) { PreCondition.AssertNotNull(tokenizer, nameof(tokenizer)); PreCondition.AssertTrue(tokenizer.HasCurrent(), "tokenizer.HasCurrent()"); PreCondition.AssertEqual(tokenizer.GetCurrent().GetTokenType(), PkgdefTokenType.LeftSquareBracket, "tokenizer.GetCurrent().GetTokenType()"); PreCondition.AssertNotNull(onIssue, nameof(onIssue)); List <PkgdefToken> tokens = new List <PkgdefToken>() { tokenizer.TakeCurrent() }; while (tokenizer.HasCurrent()) { PkgdefTokenType tokenType = tokenizer.GetCurrent().GetTokenType(); if (tokenType == PkgdefTokenType.NewLine) { break; } else { tokens.Add(tokenizer.TakeCurrent()); if (tokenType == PkgdefTokenType.RightSquareBracket) { break; } } } PkgdefRegistryKeyPathSegment result = new PkgdefRegistryKeyPathSegment(tokens); if (result.GetRightSquareBracket() == null) { onIssue(new PkgdefIssue(result.GetStartIndex(), result.GetLength(), "Missing registry key path right square bracket (']').")); } return(result); }
internal static PkgdefSegment ParseLineComment(PkgdefTokenizer tokenizer, Action <PkgdefIssue> onIssue) { PreCondition.AssertNotNull(tokenizer, nameof(tokenizer)); PreCondition.AssertTrue(tokenizer.HasCurrent(), "tokenizer.HasCurrent()"); PreCondition.AssertEqual(tokenizer.GetCurrent().GetTokenType(), PkgdefTokenType.ForwardSlash, "tokenizer.GetCurrent().GetTokenType()"); PreCondition.AssertNotNull(onIssue, nameof(onIssue)); PkgdefSegment result; int startIndex = tokenizer.TakeCurrent().GetStartIndex(); StringBuilder builder = new StringBuilder().Append('/'); if (!tokenizer.HasCurrent()) { onIssue(new PkgdefIssue(startIndex, 1, "Missing line-comment's second forward slash ('/').")); result = PkgdefSegment.Unrecognized(startIndex, builder.ToString()); } else if (tokenizer.GetCurrent().GetTokenType() != PkgdefTokenType.ForwardSlash) { onIssue.Invoke(new PkgdefIssue(startIndex + 1, 1, "Expected line-comment's second forward slash ('/').")); result = PkgdefSegment.Unrecognized(startIndex, builder.ToString()); } else { builder.Append('/'); tokenizer.Next(); while (tokenizer.HasCurrent() && tokenizer.GetCurrent().GetTokenType() != PkgdefTokenType.NewLine) { builder.Append(tokenizer.TakeCurrent().GetText()); } string text = builder.ToString(); result = PkgdefSegment.LineComment(startIndex, text); } return(result); }