Options
All
  • Public
  • Public/Protected
  • All
Menu

Class InputStream

Utility class for string analysis.

Hierarchy

  • InputStream
    • InputStream

Index

Constructors

constructor

  • Parameters

    • source: string

      The source string.

    Returns InputStream

Properties

position

position: number

Current position in the source string.

source

source: string

Accessors

current

  • get current(): string
  • The current character.

    Returns string

currentLine

  • get currentLine(): string
  • The line containing the current character.

    Returns string

isEof

  • get isEof(): boolean
  • Whether the current position is reached the end of the source string.

    Returns boolean

isValid

  • get isValid(): boolean
  • Whether the current position is within the string bounds.

    Returns boolean

length

  • get length(): number
  • The length of the source string.

    Returns number

location

  • get location(): SourceLocation
  • The {@link SourceLocation location} of the current character.

    Returns SourceLocation

next

  • get next(): string
  • The next character.

    Returns string

rest

  • get rest(): string
  • The substring from the current position to the end of the source string.

    Returns string

Methods

checkBounds

  • checkBounds(offset: number): boolean
  • Checks whether the current position is within the string bounds.

    Parameters

    • offset: number

    Returns boolean

checkEof

  • checkEof(offset: number): boolean
  • Checks whether the current position is reached the end of the source string.

    Parameters

    • offset: number

      The offset relative the current position.

    Returns boolean

findMatching

  • findMatching(lexemes: string[], offset?: undefined | number): string | undefined
  • Returns the first matched lexeme, and undefined otherwise.

    Parameters

    • lexemes: string[]

      Lexemes to match with.

    • Optional offset: undefined | number

      The offset relative to the current position.

    Returns string | undefined

findMatchingLexeme

  • findMatchingLexeme(lexemes: Lexeme[], offset?: undefined | number): Lexeme | undefined
  • Returns the first matching lexeme from an array or undefined.

    Parameters

    • lexemes: Lexeme[]

      An array of lexemes to search in.

    • Optional offset: undefined | number

      Matching position offset.

    Returns Lexeme | undefined

findPresenting

  • findPresenting(lexemes: string[], offset?: undefined | number): string | undefined
  • Returns the first presenting lexeme, and undefined otherwise.

    Parameters

    • lexemes: string[]

      Lexemes to check for.

    • Optional offset: undefined | number

      The offset relative to the current position.

    Returns string | undefined

findPresentingLexeme

  • findPresentingLexeme(lexemes: Lexeme[], offset?: undefined | number): Lexeme | undefined
  • Returns the first lexeme from an array that is present at the current position.

    Parameters

    • lexemes: Lexeme[]

      An array of lexemes to search in.

    • Optional offset: undefined | number

      Matching position offset.

    Returns Lexeme | undefined

lookFor

  • lookFor(lexeme: string | string[], offset?: undefined | number): boolean
  • Checks whether a lexeme is present at the current position of the source string.

    Parameters

    • lexeme: string | string[]

      One or more lexemes to look for.

    • Optional offset: undefined | number

      The offset relative to the current position.

    Returns boolean

lookForLexeme

  • lookForLexeme(lexeme: Lexeme | Lexeme[], offset?: undefined | number): boolean
  • Looks whether a lexeme of any of lexemes is present at the current position.

    Parameters

    • lexeme: Lexeme | Lexeme[]

      A lexeme or an array of lexemes to look for.

    • Optional offset: undefined | number

      Matching position offset.

    Returns boolean

match

  • match(lexeme: string | string[], offset?: undefined | number): boolean
  • Matches a lexeme at the current position of the source string. I.e if a lexeme is present, moves the stream by the length of the lexeme.

    Parameters

    • lexeme: string | string[]

      One or more lexemes to match.

    • Optional offset: undefined | number

      The offset relative to the current position.

    Returns boolean

    Whether a lexeme was matched.

matchLexeme

  • matchLexeme(lexeme: Lexeme | Lexeme[], offset?: undefined | number): boolean
  • Tries to match a lexeme.

    Parameters

    • lexeme: Lexeme | Lexeme[]

      A lexeme or an array of lexemes to match.

    • Optional offset: undefined | number

      Matching position offset.

    Returns boolean

matchRegExp

  • matchRegExp(regexp: RegExp, offset?: undefined | number): RegExpMatchArray | null
  • Matches a regex pattern with the rest of the source string.

    Parameters

    • regexp: RegExp

      A regular expression to match with.

    • Optional offset: undefined | number

      The offset relative to the current value.

    Returns RegExpMatchArray | null

measureLexeme

  • measureLexeme(lexeme: Lexeme, offset?: undefined | number): number
  • Returns the length of a lexeme or 0 if it's not present.

    Parameters

    • lexeme: Lexeme

      A lexeme to measure.

    • Optional offset: undefined | number

      Matching position offset.

    Returns number

move

  • move(offset: number): number
  • Adjusts the current position by the specified value.

    Parameters

    • offset: number

      The offset to move by.

    Returns number

    New position.

moveTo

  • moveTo(position: number): number
  • Sets the current position.

    Parameters

    • position: number

      The new position.

    Returns number

    New position.

peek

  • peek(offset?: undefined | number): string
  • Returns the current character from the source string.

    Parameters

    • Optional offset: undefined | number

      The offset relative to the current position.

    Returns string

peekMany

  • peekMany(length: number, offset?: undefined | number): string
  • Returns the source substring of the specified length staring from current position with an offset.

    Parameters

    • length: number

      The number of characters to peek.

    • Optional offset: undefined | number

      The offset relative to the current position.

    Returns string

peekTo

  • peekTo(end?: undefined | number, offset?: undefined | number): string
  • Returns the source substring from the current position to the specified one. The substring includes the characters up to, but not including, the character indicated by end.

    Parameters

    • Optional end: undefined | number

      The zero-based index number to peek to. If this value is not specified, the substring continues to the end of the source string.

    • Optional offset: undefined | number

      The offset relative to the current position

    Returns string

reset

  • reset(): void
  • Sets the current position to 0.

    Returns void

slice

  • slice(start?: undefined | number, end?: undefined | number): string
  • Returns a section of the source string.

    Parameters

    • Optional start: undefined | number

      The index to the beginning of the specified portion of the source string.

    • Optional end: undefined | number

      The index to the end of the specified portion of the source string. The substring includes the characters up to, but not including, the character indicated by end. If this value is not specified, the substring continues to the end of the source string.

    Returns string

testFor

  • testFor(regexp: RegExp | RegExp[], offset?: undefined | number): boolean
  • Checks whether a regex pattern exists in the rest of the source string.

    Parameters

    • regexp: RegExp | RegExp[]

      One or more regular expressions to test for.

    • Optional offset: undefined | number

      The offset relative to the current position.

    Returns boolean

Static normalizeRegexp

  • normalizeRegexp(regexp: RegExp): RegExp
  • Makes a regexp match from the start of the string if it's not.

    Parameters

    • regexp: RegExp

      A regexp to normalize.

    Returns RegExp

Generated using TypeDoc