Class

upickle.json

Parser

Related Doc: package json

Permalink

abstract class Parser[J] extends AnyRef

Parser implements a state machine for correctly parsing JSON data.

The trait relies on a small number of methods which are left abstract, and which generalize parsing based on whether the input is in Bytes or Chars, coming from Strings, files, or other input. All methods provided here are protected, so different parsers can choose which functionality to expose.

Parser is parameterized on J, which is the type of the JSON AST it will return. Jawn can produce any AST for which a Facade[J] is available.

The parser trait does not hold any state itself, but particular implementations will usually hold state. Parser instances should not be reused between parsing runs.

For now the parser requires input to be in UTF-8. This requirement may eventually be relaxed.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Parser
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Parser()

    Permalink

Abstract Value Members

  1. abstract def at(i: Int, j: Int): CharSequence

    Permalink

    Read the bytes/chars from 'i' until 'j' as a String.

    Read the bytes/chars from 'i' until 'j' as a String.

    Attributes
    protected[this]
  2. abstract def at(i: Int): Char

    Permalink

    Read the byte/char at 'i' as a Char.

    Read the byte/char at 'i' as a Char.

    Note that this should not be used on potential multi-byte sequences.

    Attributes
    protected[this]
  3. abstract def atEof(i: Int): Boolean

    Permalink

    Return true iff 'i' is at or beyond the end of the input (EOF).

    Return true iff 'i' is at or beyond the end of the input (EOF).

    Attributes
    protected[this]
  4. abstract def checkpoint(state: Int, i: Int, stack: List[ObjArrVisitor[_, J]]): Unit

    Permalink

    The checkpoint() method is used to allow some parsers to store their progress.

    The checkpoint() method is used to allow some parsers to store their progress.

    Attributes
    protected[this]
  5. abstract def close(): Unit

    Permalink

    Should be called when parsing is finished.

    Should be called when parsing is finished.

    Attributes
    protected[this]
  6. abstract def column(i: Int): Int

    Permalink
    Attributes
    protected[this]
  7. abstract def line(): Int

    Permalink
    Attributes
    protected[this]
  8. abstract def newline(i: Int): Unit

    Permalink
    Attributes
    protected[this]
  9. abstract def parseString(i: Int, key: Boolean): (CharSequence, Int)

    Permalink

    Parse the JSON string starting at 'i' and save it into 'ctxt'.

    Parse the JSON string starting at 'i' and save it into 'ctxt'.

    Attributes
    protected[this]
  10. abstract def reset(i: Int): Int

    Permalink

    The reset() method is used to signal that we're working from the given position, and any previous data can be released.

    The reset() method is used to signal that we're working from the given position, and any previous data can be released. Some parsers (e.g. StringParser) will ignore release, while others (e.g. PathParser) will need to use this information to release and allocate different areas.

    Attributes
    protected[this]

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final val ARRBEG: Int(6)

    Permalink

    Valid parser states.

    Valid parser states.

    Attributes
    protected[this]
  5. final val ARREND: Int(4)

    Permalink
    Attributes
    protected[this]
  6. final val DATA: Int(1)

    Permalink
    Attributes
    protected[this]
  7. final val HexChars: Array[Int]

    Permalink
    Attributes
    protected[this]
  8. final val KEY: Int(2)

    Permalink
    Attributes
    protected[this]
  9. final val OBJBEG: Int(7)

    Permalink
    Attributes
    protected[this]
  10. final val OBJEND: Int(5)

    Permalink
    Attributes
    protected[this]
  11. final val SEP: Int(3)

    Permalink
    Attributes
    protected[this]
  12. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  13. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. final def descape(s: CharSequence): Char

    Permalink

    Generate a Char from the hex digits of "ሴ" (i.e.

    Generate a Char from the hex digits of "ሴ" (i.e. "1234").

    NOTE: This is only capable of generating characters from the basic plane. This is why it can only return Char instead of Int.

    Attributes
    protected[this]
  15. def die(i: Int, msg: String): Nothing

    Permalink

    Used to generate error messages with character info and offsets.

    Used to generate error messages with character info and offsets.

    Attributes
    protected[this]
  16. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  18. def error(msg: String): Nothing

    Permalink

    Used to generate messages for internal errors.

    Used to generate messages for internal errors.

    This should only be used in situations where a possible bug in the parser was detected. For errors in user-provided JSON, use die().

    Attributes
    protected[this]
  19. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  20. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  21. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  22. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  23. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  24. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  25. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  26. final def parse(i: Int)(implicit facade: Visitor[_, J]): (J, Int)

    Permalink

    Parse and return the next JSON value and the position beyond it.

    Parse and return the next JSON value and the position beyond it.

    Attributes
    protected[this]
  27. final def parseFalse(i: Int)(implicit facade: Visitor[_, J]): J

    Permalink

    Parse the JSON constant "false".

    Parse the JSON constant "false".

    Note that this method assumes that the first character has already been checked.

    Attributes
    protected[this]
  28. final def parseNull(i: Int)(implicit facade: Visitor[_, J]): J

    Permalink

    Parse the JSON constant "null".

    Parse the JSON constant "null".

    Note that this method assumes that the first character has already been checked.

    Attributes
    protected[this]
  29. final def parseNum(i: Int, ctxt: ObjArrVisitor[Any, J])(implicit facade: Visitor[_, J]): Int

    Permalink

    Parse the given number, and add it to the given context.

    Parse the given number, and add it to the given context.

    We don't actually instantiate a number here, but rather pass the string of for future use. Facades can choose to be lazy and just store the string. This ends up being way faster and has the nice side-effect that we know exactly how the user represented the number.

    Attributes
    protected[this]
  30. final def parseNumSlow(i: Int)(implicit facade: Visitor[_, J]): (J, Int)

    Permalink

    Parse the given number, and add it to the given context.

    Parse the given number, and add it to the given context.

    This method is a bit slower than parseNum() because it has to be sure it doesn't run off the end of the input.

    Normally (when operating in rparse in the context of an outer array or object) we don't need to worry about this and can just grab characters, because if we run out of characters that would indicate bad input. This is for cases where the number could possibly be followed by a valid EOF.

    This method has all the same caveats as the previous method.

    Attributes
    protected[this]
  31. final def parseTrue(i: Int)(implicit facade: Visitor[_, J]): J

    Permalink

    Parse the JSON constant "true".

    Parse the JSON constant "true".

    Note that this method assumes that the first character has already been checked.

    Attributes
    protected[this]
  32. def reject(j: Int, path: List[Any]): PartialFunction[Throwable, Nothing]

    Permalink
  33. final def rparse(state: Int, j: Int, stack: List[ObjArrVisitor[_, J]], path: List[Any]): (J, Int)

    Permalink

    Tail-recursive parsing method to do the bulk of JSON parsing.

    Tail-recursive parsing method to do the bulk of JSON parsing.

    This single method manages parser states, data, etc. Except for parsing non-recursive values (like strings, numbers, and constants) all important work happens in this loop (or in methods it calls, like reset()).

    Currently the code is optimized to make use of switch statements. Future work should consider whether this is better or worse than manually constructed if/else statements or something else. Also, it may be possible to reorder some cases for speed improvements.

    Attributes
    protected[this]
    Annotations
    @tailrec()
  34. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  35. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  36. final val utf8: Charset

    Permalink
    Attributes
    protected[this]
  37. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped