Fragments
ReferencesA 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.
First
#Gets the first fragment which is neither a terminal nor trivia, or the tail marker when there is no such fragment.
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.
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.
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.
Source
#Gets the string these fragments were scanned from. This is the complete string in every view, never a substring of it.
Indexers
Methods
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.
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.
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.
Create
#Split a string into fragments.
Parameters:
| source (string) | String to split. Null is treated as empty. |
| options (Fragmentation = 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.
Segment
#Create a view of a run of this view's fragments, both ends included.
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.
Parameters:
| symbol (char) | Separator character. |
Without
#Create a view without the fragments matching the given mask.
Parameters:
| mask (FragmentKind) | One or more kinds to omit. |