Packages

class Lexer extends AnyRef

A simple lexer for tokens as they are used in JSON, plus parens (, ) Tokens understood are:

(, ), [, ], {, }, :, ,, true, false, null, strings (syntax as in JSON), integer numbers (syntax as in JSON: -?(0|\d+) floating point numbers (syntax as in JSON: -?(0|\d+)(\.\d+)?((e|E)(+|-)?\d+)?) The end of input is represented as its own token, EOF. Lexers can keep one token lookahead

Source
Lexer.scala
Linear Supertypes
AnyRef, Any
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Lexer
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Lexer(rd: Reader)

    rd

    the reader from which characters are read.

Value Members

  1. def accept(ch: Char): Unit

    The current token is a delimiter consisting of given character, reads next token, otherwise raises an error.

    The current token is a delimiter consisting of given character, reads next token, otherwise raises an error.

    ch

    the given delimiter character to compare current token with

    Exceptions thrown

    MalformedInput if the current token token is not a delimiter, or consists of a character different from c.

  2. def accept(t: Token): Unit

    If current token equals given token, reads next token, otherwise raises an error.

    If current token equals given token, reads next token, otherwise raises an error.

    t

    the given token to compare current token with

    Exceptions thrown

    MalformedInput if the two tokens do not match.

  3. def acceptChar(c: Char): Unit

    If last-read character equals given character, reads next character, otherwise raises an error

    If last-read character equals given character, reads next character, otherwise raises an error

    c

    the given character to compare with last-read character

    Exceptions thrown

    MalformedInput if character does not match

  4. var ch: Char

    The last-read character

  5. def error(msg: String): Nothing

    Always throws a MalformedInput exception with given error message.

    Always throws a MalformedInput exception with given error message.

    msg

    the error message

  6. def getNumber(): Unit

    Reads a numeric literal, and forms an IntLit or FloatLit token from it.

    Reads a numeric literal, and forms an IntLit or FloatLit token from it. Last-read input character ch must be either - or a digit.

    Exceptions thrown

    MalformedInput if lexeme not recognized as a numeric literal.

  7. def getString(): Unit

    Reads a string literal, and forms a StringLit token from it.

    Reads a string literal, and forms a StringLit token from it. Last-read input character ch must be opening "-quote.

    Exceptions thrown

    MalformedInput if lexeme not recognized as a string literal.

  8. def nextChar(): Unit

    Reads next character into ch

  9. def nextToken(): Unit

    Skips whitespace and reads next lexeme into token

    Skips whitespace and reads next lexeme into token

    Exceptions thrown

    MalformedInput if lexeme not recognized as a valid token

  10. var pos: Long

    The number of characters read so far

  11. var token: Token

    The last-read token

  12. var tokenPos: Long

    The number of characters read before the start of the last-read token