Fragments

References
public sealed class Fragments : IEnumerable<Fragment>
A string split into categorised fragments, plus the views derived from it.

Scanning happens once, on creation, and never fails. Problems such as an unterminated literal or an unmatched bracket are recorded on the fragment they belong to, so that half typed input still yields a complete and navigable result. Call Validate() when well formed input is required.

Every view is pinned to the same Source string and every fragment reports absolute indices into it, so error positions remain valid no matter how deeply a view is derived.

Properties

Body

#
Gets all fragments in this view except the two terminals. This is what interpreters pattern match against. Do not modify the returned array.
public Fragment[] Body { get; }

Count

#
Gets the number of fragments in this view, including the two terminals.
public int Count { get; }

First

#
Gets the first fragment which is neither a terminal nor trivia, or the tail marker when there is no such fragment.
public Fragment First { get; }

InnerContent

#
Gets this view without any enclosing bracket pairs. The cleanup is repeated, so that "([5])" yields "5". Returns this view when the body is not wrapped in a bracket pair.
public Fragments InnerContent { get; }

Options

#
Gets the choices this view was scanned with. Views inherit the options of the collection they were derived from, since they describe the same characters.
public Fragmentation Options { get; }

OuterBrackets

#
Gets the opening bracket of the innermost pair removed by InnerContent, or null when this view is not wrapped. Access the corresponding closing bracket via BracketFragment.Partner.
public BracketFragment OuterBrackets { get; }

Reduced

#
Gets a view without whitespace or comments. Line breaks are retained.
public Fragments Reduced { get; }

Source

#
Gets the string these fragments were scanned from. This is the complete string in every view, never a substring of it.
public string Source { get; }

Tail

#
Gets the marker at the end of this view.
public Fragment Tail { get; }

Indexers

this[]

#
Gets the fragment at the given index.
public Fragment this[
index
] { get; }

Methods

After

#
Create a view of everything following the given fragment.
public Fragments After(
fragment
)

Before

#
Create a view of everything preceding the given fragment.
public Fragments Before(
fragment
)

BreakLines

#
Create one view per line. The line breaks themselves are omitted; they are the delimiters. A bracket pair split across two lines loses track of itself, and both sides will report a null partner.
public Fragments[] BreakLines()

Content

#
Gets the source text from the first meaningful fragment of this view to the last, which is Coverage() without the whitespace and comments around the outside of it.

A view holding nothing but trivia yields an empty string, which is how a piece of a split can say it carries no content at all.

public string Content()

Coverage

#
Gets the characters spanned by this view. Unlike Source, which is always the complete string, this covers only the extent between the two terminals.
public string Coverage()

Create

#
Split a string into fragments.
public static Fragments Create(
source,
String to split. Null is treated as empty.
options = Fragmentation.Default
Choices which change what the characters mean.
)

Find

#
Find every fragment matching the predicate which sits at the top level of this view, that is, inside none of its bracket pairs.
public Fragment[] Find(
predicate
Test to apply to each fragment.
)

GetEnumerator

#
Enumerate every fragment in this view, terminals included.
public IEnumerator<Fragment> GetEnumerator()

Segment

#
Create a view of a run of this view's fragments, both ends included.
public Fragments Segment(
first,
First fragment to include.
last
Last fragment to include. Must not precede the first.
)

Split

#
Cut this view into pieces at every top level occurrence of a symbol. The separators themselves are omitted, and a view without any separators yields a single piece, so the result always holds one more piece than there were separators.
public Fragments[] Split(
symbol
Separator character.
)
Explicit

IEnumerable.GetEnumerator

#
IEnumerator IEnumerable.GetEnumerator()

ToString

#
Gets a description of this view, for debugging purposes.
public override string ToString()
Object.ToString

Validate

#
Report the first defect in this view, if there is one.
public IResult Validate()

Without

#
Create a view without the fragments matching the given mask.
public Fragments Without(
mask
One or more kinds to omit.
)