Top Description Inners Fields Constructors Methods
uk.ac.ed.ph.snuggletex.internal

public final Class WorkingDocument

extends Object
implements InputContext
Class Inheritance
All Implemented Interfaces
uk.ac.ed.ph.snuggletex.InputContext
Imports
uk.ac.ed.ph.snuggletex.InputContext, .SnuggleInput, .SnuggleLogicException, java.util.ArrayList, .List

Represents the "working view" of the current 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.
Author
David McKain
Version
$Revision$

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
WorkingDocument.CharacterSource

Represents a block of text that has been imported into this document.

public static class
WorkingDocument.IndexResolution

Holds information about how a particular index in the document is resolved against the Slice in which it is contained.

public static class
WorkingDocument.Slice

Represents a contiguous portion of the document hat comes from the same CharacterSource.

public static interface
WorkingDocument.SourceContext

Marker interface that can be applied to classes that provide information for a CharacterSource.

public static class
WorkingDocument.SubstitutionContext

Implementation of SourceContext that represents the result of a substitution.

Field Summary

Modifier and TypeField and Description
private final StringBuilder
private int
private final SnuggleInput
pack-priv int
lastResolvedSliceIndex

Index in scoreboard of last successful resolution used in resolveIndex(int, boolean) below

private int
length

Current length of document (this is kept in sync with buffer.length())

private final List<WorkingDocument.Slice>

Constructor Summary

AccessConstructor and Description
pack-priv
WorkingDocument(final CharSequence initialData, final SnuggleInputReader inputReader)

Method Summary

Modifier and TypeMethod and Description
public int
charAt(final int index)

Implements uk.ac.ed.ph.snuggletex.InputContext.charAt.

Returns the character at the given index in the input document, or -1 if the index is not contained within the document.

private void
checkIndex(final int index, final String errorStart)

private void
checkRange(final int startIndex, final int endIndex)

public void
public CharSequence
extract()

Implements uk.ac.ed.ph.snuggletex.InputContext.extract.

Extracts a copy of the current entire content of the input as a CharSequence

public CharSequence
extract(final int startIndex, final int endIndex)

Implements uk.ac.ed.ph.snuggletex.InputContext.extract.

Extracts a copy of a slice of the current entire content of the input as a CharSequence, including all characters with startIndex <= index < endIndex.

public FrozenSlice
freezeSlice(final int startIndex, final int endIndex)

public SnuggleInput
public int
getSubstitutionDepth(final int index)

public int
indexOf(final int startSearchIndex, final char c)

Implements uk.ac.ed.ph.snuggletex.InputContext.indexOf.

Returns the first index of the given character, starting the search at the given index.

public int
indexOf(final int startSearchIndex, final String s)

Implements uk.ac.ed.ph.snuggletex.InputContext.indexOf.

Returns the first index of the given String, starting the search at the given index.

public boolean
isRegionWhitespace(final int startIndex, final int endIndex)

Implements uk.ac.ed.ph.snuggletex.InputContext.isRegionWhitespace.

Tests whether all characters in the document with index satisfying startIndex <= index < endIndex are whitespace.

public int
length()

Implements uk.ac.ed.ph.snuggletex.InputContext.length.

Current length of this input

public boolean
matchesAt(final int index, final char c)

Implements uk.ac.ed.ph.snuggletex.InputContext.matchesAt.

Tests whether the character at the given index is equal to that specified.

public boolean
matchesAt(final int index, final String s)

Implements uk.ac.ed.ph.snuggletex.InputContext.matchesAt.

Tests whether the characters at the given index are equal to the String specified.

public WorkingDocument.IndexResolution
resolveIndex(final int index, final boolean fallLeftOnBoundaries)

public WorkingDocument.CharacterSource
substitute(final int startIndex, final int endIndex, final CharSequence replacement)

public void
unfreeze(final int newFreezeIndex)

This is a rather nasty method which resets the "freeze index" of this document back to the given index.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private final StringBuilder buffer
freezeIndexback to summary
private int freezeIndex
inputback to summary
private final SnuggleInput input
lastResolvedSliceIndexback to summary
pack-priv int lastResolvedSliceIndex

Index in scoreboard of last successful resolution used in resolveIndex(int, boolean) below

lengthback to summary
private int length

Current length of document (this is kept in sync with buffer.length())

scoreBoardback to summary
private final List<WorkingDocument.Slice> scoreBoard

Constructor Detail

WorkingDocumentback to summary
pack-priv WorkingDocument(final CharSequence initialData, final SnuggleInputReader inputReader)

Method Detail

charAtback to summary
public int charAt(final int index)

Implements uk.ac.ed.ph.snuggletex.InputContext.charAt.

Doc from uk.ac.ed.ph.snuggletex.InputContext.charAt.

Returns the character at the given index in the input document, or -1 if the index is not contained within the document.

checkIndexback to summary
private void checkIndex(final int index, final String errorStart)
checkRangeback to summary
private void checkRange(final int startIndex, final int endIndex)
dumpScoreboardback to summary
public void dumpScoreboard()
extractback to summary
public CharSequence extract()

Implements uk.ac.ed.ph.snuggletex.InputContext.extract.

Doc from uk.ac.ed.ph.snuggletex.InputContext.extract.

Extracts a copy of the current entire content of the input as a CharSequence

extractback to summary
public CharSequence extract(final int startIndex, final int endIndex)

Implements uk.ac.ed.ph.snuggletex.InputContext.extract.

Doc from uk.ac.ed.ph.snuggletex.InputContext.extract.

Extracts a copy of a slice of the current entire content of the input as a CharSequence, including all characters with startIndex <= index < endIndex.

freezeSliceback to summary
public FrozenSlice freezeSlice(final int startIndex, final int endIndex)
getInputback to summary
public SnuggleInput getInput()

Implements uk.ac.ed.ph.snuggletex.InputContext.getInput.

Doc from uk.ac.ed.ph.snuggletex.InputContext.getInput.

Accesses the underlying SnuggleInput

getSubstitutionDepthback to summary
public int getSubstitutionDepth(final int index)
indexOfback to summary
public int indexOf(final int startSearchIndex, final char c)

Implements uk.ac.ed.ph.snuggletex.InputContext.indexOf.

Doc from uk.ac.ed.ph.snuggletex.InputContext.indexOf.

Returns the first index of the given character, starting the search at the given index. Returns -1 if not found.

indexOfback to summary
public int indexOf(final int startSearchIndex, final String s)

Implements uk.ac.ed.ph.snuggletex.InputContext.indexOf.

Doc from uk.ac.ed.ph.snuggletex.InputContext.indexOf.

Returns the first index of the given String, starting the search at the given index. Returns -1 if not found.

isRegionWhitespaceback to summary
public boolean isRegionWhitespace(final int startIndex, final int endIndex)

Implements uk.ac.ed.ph.snuggletex.InputContext.isRegionWhitespace.

Doc from uk.ac.ed.ph.snuggletex.InputContext.isRegionWhitespace.

Tests whether all characters in the document with index satisfying startIndex <= index < endIndex are whitespace.

lengthback to summary
public int length()

Implements uk.ac.ed.ph.snuggletex.InputContext.length.

Doc from uk.ac.ed.ph.snuggletex.InputContext.length.

Current length of this input

matchesAtback to summary
public boolean matchesAt(final int index, final char c)

Implements uk.ac.ed.ph.snuggletex.InputContext.matchesAt.

Doc from uk.ac.ed.ph.snuggletex.InputContext.matchesAt.

Tests whether the character at the given index is equal to that specified.

matchesAtback to summary
public boolean matchesAt(final int index, final String s)

Implements uk.ac.ed.ph.snuggletex.InputContext.matchesAt.

Doc from uk.ac.ed.ph.snuggletex.InputContext.matchesAt.

Tests whether the characters at the given index are equal to the String specified.

resolveIndexback to summary
public WorkingDocument.IndexResolution resolveIndex(final int index, final boolean fallLeftOnBoundaries)
substituteback to summary
public WorkingDocument.CharacterSource substitute(final int startIndex, final int endIndex, final CharSequence replacement)
unfreezeback to summary
public void unfreeze(final int newFreezeIndex)

This is a rather nasty method which resets the "freeze index" of this document back to the given index. Any 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.

uk.ac.ed.ph.snuggletex.internal back to summary

public final Class WorkingDocument.CharacterSource

extends Object
Class Inheritance
  • java.lang.Object
  • uk.ac.ed.ph.snuggletex.internal.WorkingDocument.CharacterSource

Represents a block of text that has been imported into this document.

Field Summary

Modifier and TypeField and Description
public final WorkingDocument.SourceContext
context

Contextual information about where this data came from

private transient String
public final WorkingDocument.CharacterSource
substitutedSource

The block that this block was initially substituted into, or null to indicate that it is "top level" or was appended rather than substituted.

public final CharSequence
substitutedText

The text in the parent component that this data replaced, or null if substitutedSource is null.

public final int
substitutionOffset

The offset in substitutedSource where the substitution occurred, or 0 if substitutedSource is null.

Constructor Summary

AccessConstructor and Description
public
public
CharacterSource(final WorkingDocument.SourceContext context, final WorkingDocument.CharacterSource substitutedSource, final int substitutionOffset, final CharSequence substitutedText)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

contextback to summary
public final WorkingDocument.SourceContext context

Contextual information about where this data came from

stringRepresentationback to summary
private transient String stringRepresentation
substitutedSourceback to summary
public final WorkingDocument.CharacterSource substitutedSource

The block that this block was initially substituted into, or null to indicate that it is "top level" or was appended rather than substituted.

substitutedTextback to summary
public final CharSequence substitutedText

The text in the parent component that this data replaced, or null if substitutedSource is null.

substitutionOffsetback to summary
public final int substitutionOffset

The offset in substitutedSource where the substitution occurred, or 0 if substitutedSource is null.

Constructor Detail

CharacterSourceback to summary
public CharacterSource(final WorkingDocument.SourceContext context)
CharacterSourceback to summary
public CharacterSource(final WorkingDocument.SourceContext context, final WorkingDocument.CharacterSource substitutedSource, final int substitutionOffset, final CharSequence substitutedText)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
uk.ac.ed.ph.snuggletex.internal back to summary

public Class WorkingDocument.IndexResolution

extends Object
Class Inheritance
  • java.lang.Object
  • uk.ac.ed.ph.snuggletex.internal.WorkingDocument.IndexResolution

Holds information about how a particular index in the document is resolved against the Slice in which it is contained.
Author
David McKain
Version
$Revision$

Field Summary

Modifier and TypeField and Description
public final int
public final int
public final WorkingDocument.Slice

Constructor Summary

AccessConstructor and Description
public
IndexResolution(final int scoreboardIndex, final WorkingDocument.Slice slice, final int indexInComponent)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

indexInComponentback to summary
public final int indexInComponent
scoreboardIndexback to summary
public final int scoreboardIndex
sliceback to summary
public final WorkingDocument.Slice slice

Constructor Detail

IndexResolutionback to summary
public IndexResolution(final int scoreboardIndex, final WorkingDocument.Slice slice, final int indexInComponent)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
uk.ac.ed.ph.snuggletex.internal back to summary

public final Class WorkingDocument.Slice

extends Object
Class Inheritance

Represents a contiguous portion of the document hat comes from the same CharacterSource. During parsing, Slices will be broken up to create new Slices whenever user-defined commands and environments are substituted.

Field Summary

Modifier and TypeField and Description
public final int
public final int
public final WorkingDocument.CharacterSource
public final int

Constructor Summary

AccessConstructor and Description
public
Slice(final int startIndex, final int endIndex, final WorkingDocument.CharacterSource resolvedComponent, final int componentIndexOffset)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

componentIndexOffsetback to summary
public final int componentIndexOffset
endIndexback to summary
public final int endIndex
resolvedComponentback to summary
public final WorkingDocument.CharacterSource resolvedComponent
startIndexback to summary
public final int startIndex

Constructor Detail

Sliceback to summary
public Slice(final int startIndex, final int endIndex, final WorkingDocument.CharacterSource resolvedComponent, final int componentIndexOffset)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
uk.ac.ed.ph.snuggletex.internal back to summary

public Interface WorkingDocument.SourceContext

Known Direct Implementers
uk.ac.ed.ph.snuggletex.internal.WorkingDocument.SubstitutionContext, uk.ac.ed.ph.snuggletex.internal.SnuggleInputReader

Marker interface that can be applied to classes that provide information for a CharacterSource.
uk.ac.ed.ph.snuggletex.internal back to summary

public final Class WorkingDocument.SubstitutionContext

extends Object
implements SourceContext
Class Inheritance
  • java.lang.Object
  • uk.ac.ed.ph.snuggletex.internal.WorkingDocument.SubstitutionContext
All Implemented Interfaces
uk.ac.ed.ph.snuggletex.internal.WorkingDocument.SourceContext

Implementation of SourceContext that represents the result of a substitution.

Field Summary

Modifier and TypeField and Description
public CharSequence
replacement

The characters that replaced what was originally in the document.

Constructor Summary

AccessConstructor and Description
public
SubstitutionContext(final CharSequence replacement)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

replacementback to summary
public CharSequence replacement

The characters that replaced what was originally in the document.

Constructor Detail

SubstitutionContextback to summary
public SubstitutionContext(final CharSequence replacement)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override