public final class WorkingDocument extends Object implements InputContext
SnuggleInput document. This is
slightly non-trivial in that user-defined command and environments generally work as
simple text substitutions, so the state of the document changes during tokenisation.
However, we also need to be able to keep track of where each character in the document
comes from so as to enable decent error reporting. hence the complexity within here.| Modifier and Type | Class and Description |
|---|---|
static class |
WorkingDocument.CharacterSource
Represents a block of text that has been imported into this document.
|
static class |
WorkingDocument.IndexResolution
Holds information about how a particular index in the document is resolved against the
WorkingDocument.Slice
in which it is contained. |
static class |
WorkingDocument.Slice
Represents a contiguous portion of the document hat comes from the same
WorkingDocument.CharacterSource. |
static interface |
WorkingDocument.SourceContext
Marker interface that can be applied to classes that provide information for a
WorkingDocument.CharacterSource. |
static class |
WorkingDocument.SubstitutionContext
Implementation of
WorkingDocument.SourceContext that represents the result of a substitution. |
| Modifier and Type | Method and Description |
|---|---|
int |
charAt(int index)
Returns the character at the given index in the input document,
or -1 if the index is not contained within the document.
|
void |
dumpScoreboard() |
CharSequence |
extract()
Extracts a copy of the current entire content of the input as a
CharSequence |
CharSequence |
extract(int startIndex,
int endIndex)
Extracts a copy of a slice of the current entire content of the input as a
CharSequence,
including all characters with startIndex <= index < endIndex. |
FrozenSlice |
freezeSlice(int startIndex,
int endIndex) |
SnuggleInput |
getInput()
Accesses the underlying
SnuggleInput |
int |
getSubstitutionDepth(int index) |
int |
indexOf(int startSearchIndex,
char c)
Returns the first index of the given character, starting the search at the given
index.
|
int |
indexOf(int startSearchIndex,
String s)
Returns the first index of the given String, starting the search at the given
index.
|
boolean |
isRegionWhitespace(int startIndex,
int endIndex)
Tests whether all characters in the document with index satisfying
startIndex <= index < endIndex are whitespace.
|
int |
length()
Current length of this input
|
boolean |
matchesAt(int index,
char c)
Tests whether the character at the given index is equal to that specified.
|
boolean |
matchesAt(int index,
String s)
Tests whether the characters at the given index are equal to the String specified.
|
WorkingDocument.IndexResolution |
resolveIndex(int index,
boolean fallLeftOnBoundaries) |
WorkingDocument.CharacterSource |
substitute(int startIndex,
int endIndex,
CharSequence replacement) |
void |
unfreeze(int newFreezeIndex)
This is a rather nasty method which resets the "freeze index" of this document back to the
given index.
|
public SnuggleInput getInput()
InputContextSnuggleInputgetInput in interface InputContextpublic FrozenSlice freezeSlice(int startIndex, int endIndex)
public void unfreeze(int newFreezeIndex)
FrozenSlices that may previously have spanned this index are no
longer valid as their contents may change.
This class does NOT attempt to enforce this in any way - it is up to the caller to make sure he/she understands the implications of doing this.
The main requirement for having this is when evaluating single-argument user-defined commands
like \\udc \\alpha where the argument is implicitly taken to be the next
valid token.
newFreezeIndex - public int length()
InputContextlength in interface InputContextpublic WorkingDocument.IndexResolution resolveIndex(int index, boolean fallLeftOnBoundaries)
public int getSubstitutionDepth(int index)
public int charAt(int index)
InputContextcharAt in interface InputContextpublic boolean matchesAt(int index,
char c)
InputContextmatchesAt in interface InputContextpublic boolean matchesAt(int index,
String s)
InputContextmatchesAt in interface InputContextpublic int indexOf(int startSearchIndex,
char c)
InputContextindexOf in interface InputContextpublic int indexOf(int startSearchIndex,
String s)
InputContextindexOf in interface InputContextpublic boolean isRegionWhitespace(int startIndex,
int endIndex)
InputContextisRegionWhitespace in interface InputContextpublic CharSequence extract()
InputContextCharSequenceextract in interface InputContextpublic CharSequence extract(int startIndex, int endIndex)
InputContextCharSequence,
including all characters with startIndex <= index < endIndex.extract in interface InputContextpublic WorkingDocument.CharacterSource substitute(int startIndex, int endIndex, CharSequence replacement)
public void dumpScoreboard()
Copyright © 2008–2026 The University of Edinburgh. All rights reserved.