Go to repository

Class UnknownSourcePosition

An UnknownSourcePosition represents an unknown source position, that is, it does not point to any position in any source reader. These positions responds with true to the operation isUnknown.

It is used when a position must be provided, but no one is known, working as a Null Object Pattern. Additionally, this class follows the Singleton Pattern using an eager initialization.

This class has a single instance, accessible through the instance static field, and cannot be further instantiated.

Hierarchy (view full)

Implements

Constructors

Private

Returns an instance of this class. Made private to follow the singleton pattern.

Returns UnknownSourcePosition

Properties

Readonly
isUnknown: boolean = true

Answers if this position correspond to one in some SourceReader, or if it is unknown.

Static Readonly
instance: UnknownSourcePosition = ...

Returns the single instance of this class.

Accessors

get column(): number

The column number of this position in the current input.

PRECONDITIONS:

  • the position is not unknown
  • the position is not at the end of input

INVARIANT: column >= 1 and it is a valid column in that reader.

Returns number

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the position is unknown.

SourceReader/Errors.InvalidOperationAtEOIError if the position is at the end of input.

get documentName(): string

The name of the input document this position belongs to.

PRECONDITIONS:

  • the position is not unknown
  • the position is not at the end of input

Returns string

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the position is unknown.

SourceReader/Errors.InvalidOperationAtEOIError if the position is at the end of input.

get fullDocumentContents(): string

The contents of the input document this position belongs to (both visible and non visible).

PRECONDITIONS:

  • the position is not unknown
  • the position is not at the end of input

Returns string

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the receiver is unknown.

SourceReader/Errors.InvalidOperationAtEOIError if the receiver is the end of input.

get isEndOfDocument(): boolean

Answers if this position corresponds to the end of a document in the SourceReader it belongs, or not. The EndOfDocument is reached when all the characters in a document in the source input has been processed, but before the processing of the next document started.

PRECONDITIONS:

  • the position is not unknown
  • the position is not at the end of input

Returns boolean

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the position is unknown.

SourceReader/Errors.InvalidOperationAtEOIError if the position is at the end of input.

get isEndOfInput(): boolean

Answers if this position corresponds to the end of input of the SourceReader it belongs, or not. The EndOfInput is reached when all documents in the source input has been processed.

PRECONDITIONS:

  • the position is known

Returns boolean

get line(): number

The line number of this position in the current input.

PRECONDITIONS:

  • the position is not unknown
  • the position is not at the end of input

INVARIANT: line >=1, and it is a valid line in that reader.

Returns number

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the position is unknown.

SourceReader/Errors.InvalidOperationAtEOIError if the position is at the end of input.

get regions(): string[]

The regions the position in the current input belongs to.

PRECONDITIONS:

  • the position is not unknown
  • the position is not at the end of input

INVARIANT: the regions are valid in the position's reader.

Returns string[]

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the position is unknown.

SourceReader/Errors.InvalidOperationAtEOIError if the position is at the end of input.

get visibleDocumentContents(): string

The contents of the visible input document this position belongs to.

PRECONDITIONS:

  • the position is not unknown
  • the position is not at the end of input

Returns string

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the receiver is unknown.

SourceReader/Errors.InvalidOperationAtEOIError if the receiver is the end of input.

Methods

Returns the full context of the source document after the position, up to the beginning of the given number of lines or the end of the document.

The char at the given position is the first one in the solution.

PRECONDITIONS:

  • the position is not unknown
  • the position is not at the end of input

Parameters

  • _lines: number

Returns string[]

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the position is unknown.

SourceReader/Errors.InvalidOperationAtEOIError if the position is at the end of input.

Returns the full context of the source document before the position, up to the beginning of the given number of lines, or the beginning of the document, whichever comes first.

The char at the given position is NOT included in the solution.

PRECONDITIONS:

  • the position is not unknown
  • the position is not at the end of input

Parameters

  • _lines: number

Returns string[]

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the position is unknown.

SourceReader/Errors.InvalidOperationAtEOIError if the position is at the end of input.

The exact portion of the source that is enclosed between the argument position and the receiver position (not included), both visible and non visible. If the receiver does not come after the argument, the result is the empty string.

PRECONDITIONS:

  • both positions are known
  • both positions correspond to the same reader
  • the receiver is not at the end of input

Parameters

Returns string

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the receiver or the argument positions are unknown.

SourceReader/Errors.MismatchedInputsError if the receiver and the argument positions do not belong to the same reader.

SourceReader/Errors.InvalidOperationAtEOIError if the receiver is the end of input.

The exact portion of the source, both visible and non visible, that is enclosed between the receiver position and the argument position (not included). If the argument does not come after the receiver, the result is the empty string.

PRECONDITIONS:

  • both positions are known
  • both positions correspond to the same reader
  • the receiver is not at the end of input

Parameters

Returns string

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the receiver or the argument positions are unknown.

SourceReader/Errors.MismatchedInputsError if the receiver and the argument positions do not belong to the same reader.

SourceReader/Errors.InvalidOperationAtEOIError if the receiver is the end of input.

Gives a string representation of the position. It is NOT useful for persistence, as it may loose information.

Returns string

The exact portion of the source that is enclosed between the from position and this position (not included) and is visible. If this does not come after from, the result is the empty string.

PRECONDITIONS:

  • both positions are known
  • both positions correspond to the same reader
  • the receiver is not at the end of input

Parameters

Returns string

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the receiver or the argument positions are unknown.

SourceReader/Errors.MismatchedInputsError if the receiver and the argument positions do not belong to the same reader.

SourceReader/Errors.InvalidOperationAtEOIError if the receiver is the end of input.

The exact portion of the source that is enclosed between the this position and to position (not included) and is visible. If to does not come after this, the result is the empty string.

PRECONDITIONS:

  • both positions are known
  • both positions correspond to the same reader
  • the receiver is not at the end of input

Parameters

Returns string

SourceReader/Errors.InvalidOperationAtUnknownPositionError if the receiver or the argument positions are unknown.

SourceReader/Errors.MismatchedInputsError if the receiver and the argument positions do not belong to the same reader.

SourceReader/Errors.InvalidOperationAtEOIError if the receiver is the end of input.