Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Scanner

class

{Scanner} - Creates a scanner object.

Hierarchy

  • Scanner

Index

Constructors

constructor

  • example

    : javascript { const scanner = new Scanner(new Source('var x = 12;')); }

    Parameters

    • source: Source
    • Default value options: object = Options.Scanner
      • ignore: object
        • whitespace: boolean
      • override: object
        • isWhiteSpace: undefined

    Returns Scanner

Properties

Private column

column: number

The source column number

info

info: object

The information about the Scanner

Type declaration

  • errors: Array<any>
  • file: object
    • length: number
    • name: string
    • position: number
    • source: string
  • time: object
    • elapsed: Date | number

Private line

line: number

The source line number

Private options

options: any

The options

Private position

position: number

The source position number

Private range

range: Range

The range in the source.

Private source

source: Source

The source object

Private stack

stack: Array<any>

The history stack

Private tokens

tokens: Array<any>

The tokens stack

Methods

Private ignoreWhiteSpace

  • ignoreWhiteSpace(): void
  • method

    {ignoreWhiteSpace} - Ignores the whitespaces in the source.

    Returns void

isEOF

  • isEOF(): boolean
  • method

    {isEOF} - Determines whether the current character is the end of file.

    Returns boolean

    • The truth value.

location

  • location(): object
  • method

    {location} - Marks the locations.

    example

    : javascript { //... scanner.scan(ch => { this.location().start(); //... this.location().end(); }); }

    Returns object

    { { start: () => void, end: () => Range, eof: () => Range } } - The location helpers.

    • column: number
    • end: function
    • eof: function
    • line: number
    • start: function
        • (): void
        • Returns void

next

  • next(): string | number
  • Returns string | number

    • The next character.

peek

  • peek(peek?: number): string | number
  • Parameters

    • Default value peek: number = 0

    Returns string | number

    • The next character(s) to peek.

peekBack

  • peekBack(peek?: number): string | number
  • Parameters

    • Default value peek: number = 0

    Returns string | number

    • The previous character(s) to peek.

Private pop

  • pop(): void
  • method

    {pop} - Pops the previous charater and location from the history stack.

    Returns void

previous

  • previous(): string | number
  • Returns string | number

    • The previous character.

Private push

  • push(): void
  • method

    {push} - Pushes the current charater and location into the history stack.

    Returns void

raise

  • raise(message?: string, type?: string): void
  • method

    {raise} - Adds an error message into the errors stack.

    Parameters

    • Optional message: string
    • Optional type: string

    Returns void

scan

  • scan(driver: function, scanner?: Object): Stream
  • method

    {scan} - Calls the tokenizer as it scans through the source.

    example

    : javascript { let scanner = new Scanner(new Source('...')); scanner.scan(function(ch) { //... }); }

    Parameters

    • driver: function
        • (char: string | number): Tokenize.Token
        • Parameters

          • char: string | number

          Returns Tokenize.Token

    • Optional scanner: Object

    Returns Stream

    • The token stream.

Generated using TypeDoc