Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CharStream

Hierarchy

  • CharStream

Index

Constructors

constructor

  • new CharStream(s: String, startpos?: number, endpos?: number, hasEOF?: boolean): CharStream
  • Parameters

    • s: String
    • Optional startpos: number
    • Optional endpos: number
    • Optional hasEOF: boolean

    Returns CharStream

Properties

Readonly endpos

endpos: number

Readonly hasEOF

hasEOF: boolean = true

Readonly input

input: String

Readonly startpos

startpos: number

Methods

concat

  • Returns the concatenation of the current CharStream with the given CharStream. Note: returned object does not reuse original input string, and startpos and endpos are reset. If the given CharStream contains EOF, the concatenated CharStream will also contain EOF.

    Parameters

    • cs: CharStream

      the CharStream to concat to this CharStream

    Returns CharStream

head

  • Returns a new CharStream representing the head of the input at the current position. Throws an exception if the CharStream is empty.

    Returns CharStream

isEOF

  • isEOF(): boolean
  • Returns true of the end of the input has been reached.

    Returns boolean

isEmpty

  • isEmpty(): boolean
  • Returns true if the input at the current position is empty. Note that a CharStream at the end of the input contains an empty string but that an empty string may not be the end-of-file (i.e., isEOF is false).

    Returns boolean

length

  • length(): number
  • Returns the number of characters remaining at the current position.

    Returns number

peek

  • Returns a new CharStream representing the input from the current start position to an end position num chars from the current start position. If startpos + num > endpos, the current CharStream is returned.

    Parameters

    • num: number

    Returns CharStream

peekMatches

  • peekMatches(s: string): boolean
  • Returns true if the next s.length characters match s.

    Parameters

    • s: string

      A string.

    Returns boolean

seek

  • Returns a new CharStream representing the string after seeking num characters from the current position.

    Parameters

    • num: number

    Returns CharStream

seekWhile

  • seekWhile(pred: (char: string) => boolean): CharStream
  • Returns a new CharStream created by repeatedly applying the given predicate until it no longer matches.

    Parameters

    • pred: (char: string) => boolean

      A predicate over valid characters.

        • (char: string): boolean
        • Parameters

          • char: string

          Returns boolean

    Returns CharStream

seekWhileCharCode

  • A highly optimized seek that advances the stream while the given predicate returns true. Returns a pair of CharStreams [a,b] where a is the matching string and b is the remainder of the stream.

    Parameters

    • okCodes: (n: number) => boolean

      A predicate over valid ASCII character codes.

        • (n: number): boolean
        • Parameters

          • n: number

          Returns boolean

    Returns [CharStream, CharStream]

substring

  • substring(start: number, end: number): CharStream
  • Returns the substring between start and end at the current position.

    Parameters

    • start: number

      the start index of the substring, inclusive

    • end: number

      the end index of the substring, exclusive

    Returns CharStream

tail

  • Returns a new CharStream representing the tail of the input at the current position. Throws an exception if the CharStream is empty.

    Returns CharStream

toString

  • toString(): string
  • Returns a Javscript primitive string of the slice of input represented by this CharStream.

    Returns string

Static concat

Generated using TypeDoc