Class/Object

fastparse

ParsingRun

Related Docs: object ParsingRun | package fastparse

Permalink

final class ParsingRun[+T] extends AnyRef

Models an in-progress parsing run; contains all the mutable state that may be necessary during the parse, in order to avoid the individual parsers needing to perform their own allocations and instantiations, and greatly improving performance

There are a few patterns that let us program with these mutable variables in a sort-of-pure-functional way:

test - If a parser that wishes to ignore changes to a field within their child parsers, a common pattern is to save the value of the field before the wrapped parser runs, and then re-set the field. e.g. this can be used to backtrack index after a lookahead parser finishes

test - If a parser wants to read the value of the field "returned" by multiple child parsers, make sure to read the field into a local variable after each child parser is complete to make sure the value you want from an earlier child isn't stomped over by a later child

In general, for a parser to "return" a value in a mutable field, it is sufficient to simply set the value of that field before returning. It is the parent-parser's responsibility to make sure it reads out the value of the field to a local variable before running another child parser that will over-write the mutable field

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

Instance Constructors

  1. new ParsingRun(input: ParserInput, startIndex: Int, originalParser: (ParsingRun[_]) ⇒ ParsingRun[_], traceIndex: Int, instrument: Instrument, failureTerminalAggregate: Msgs, failureGroupAggregate: Msgs, shortParserMsg: Msgs, lastFailureMsg: Msgs, failureStack: List[(String, Int)], isSuccess: Boolean, logDepth: Int, index: Int, cut: Boolean, successValue: Any, verboseFailures: Boolean, noDropBuffer: Boolean, misc: Map[Any, Any])

    Permalink

    input

    The input to the parsing run, as a ParserInput.

    startIndex

    Where the parse initially started, so as to allow .result.traced to re-create it with tracing enabled.

    originalParser

    The original parsing function we used to start this run, so as to allow .result.traced to re-create it with tracing enabled.

    traceIndex

    The index we wish to trace if tracing is enabled, else -1. Used to find failure messages to aggregate into failureTerminalAggregate

    instrument

    Callbacks that can be injected before/after every P(...) parser.

    failureTerminalAggregate

    When tracing is enabled, this collects up all the upper-most failures that happen at traceIndex (in Lazy wrappers) so they can be shown to the user at end-of-parse as suggestions for what could make the parse succeed. For terminal parsers like LiteralStr, it just aggregate's the string representation. For composite parsers like a ~ b or !a which may fail at traceIndex even without any of their wrapped terminal parsers failing there, it makes use of the shortParserMsg as the string representation of the composite parser.

    shortParserMsg

    When tracing is enabled, this contains string representation of the last parser to run. Since parsers aren't really objects, we piece together the string in the parser body and return store it here, and an enclosing parser may fetch it back out to help build its own string representation. If the last parser started before the traceIndex, we only aggregate the portion of the parser msg that takes place after traceIndex

    failureStack

    The stack of named P(...) parsers in effect when the failure occured; only constructed when tracing is enabled via traceIndex != -1

    isSuccess

    Whether or not the parse is currently successful

    logDepth

    How many nested .log calls are currently surrounding us. Used to nicely indent the log output so you can see which parsers are nested within which other parsers; -1 means logging is disabled

    index

    The current index of the parse

    cut

    Has the current parse been prevented from backtracking? This field starts as true at top-level, since there is nowhere to backtrack to. Upon entering a parser that can backtrack, such as | or .? or .rep, it is set to false, and re-set to true upon encountering a ./ or ~/ cut operator that prevents backtracking.

    successValue

    The currently returned success value

    verboseFailures

    Whether or not we are currently collecting lastFailureMsgs; defaults to false, unless traceIndex is set OR we are inside a LogByNameOps.log call which necessitates tracing in order to print out failure traces during logging

    noDropBuffer

    Flag that prevents the parser from dropping earlier input. Used for the .! capture operator that needs the input around to return as a string, the NoCut operator that forces backtracking (regardless of internal cuts), or whitespace consumption which implicitly backtracks if the parser on the RHS of the whitespace fails or consumes 0 characters. The value for this field is lexically scoped, but it is up to the individual parser method implementations to set the values and remember to un-set it to the previous value after they finish. Forgetting to re-set it to the previous value can cause strange behavior or crashes.

    misc

    Additional key-value metadata that a user can attach to a parsing run, and manage however they like. Not as high performance as the built-in fields of ParsingRun, but perhaps sufficient to satisfy ad-hoc needs e.g. keeping track of indentation or other contextual information

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. def aggregateMsg(startIndex: Int, msgToSet: Msgs, msgToAggregate: Msgs, forceAggregate: Boolean): Unit

    Permalink
  5. def aggregateMsg(startIndex: Int, msgToSet: Msgs, msgToAggregate: Msgs): Unit

    Permalink
  6. def aggregateMsg(startIndex: Int, msgToSet: () ⇒ String, msgToAggregate: Msgs): Unit

    Permalink
  7. def aggregateTerminal(startIndex: Int, f: () ⇒ String): Unit

    Permalink
  8. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  9. def augmentFailure(index: Int, cut: Boolean): ParsingRun[Nothing]

    Permalink
  10. def augmentFailure(index: Int): ParsingRun[Nothing]

    Permalink
  11. def checkAggregate(startIndex: Int): Boolean

    Permalink

    Conditions under which we want to aggregate the given parse

  12. def checkForDrop(): Boolean

    Permalink
  13. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. var cut: Boolean

    Permalink

    Has the current parse been prevented from backtracking? This field starts as true at top-level, since there is nowhere to backtrack to.

    Has the current parse been prevented from backtracking? This field starts as true at top-level, since there is nowhere to backtrack to. Upon entering a parser that can backtrack, such as | or .? or .rep, it is set to false, and re-set to true upon encountering a ./ or ~/ cut operator that prevents backtracking.

  15. final def eq(arg0: AnyRef): Boolean

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

    Permalink
    Definition Classes
    AnyRef → Any
  17. var failureGroupAggregate: Msgs

    Permalink
  18. var failureStack: List[(String, Int)]

    Permalink

    The stack of named P(...) parsers in effect when the failure occured; only constructed when tracing is enabled via traceIndex != -1

  19. var failureTerminalAggregate: Msgs

    Permalink

    When tracing is enabled, this collects up all the upper-most failures that happen at traceIndex (in Lazy wrappers) so they can be shown to the user at end-of-parse as suggestions for what could make the parse succeed.

    When tracing is enabled, this collects up all the upper-most failures that happen at traceIndex (in Lazy wrappers) so they can be shown to the user at end-of-parse as suggestions for what could make the parse succeed. For terminal parsers like LiteralStr, it just aggregate's the string representation. For composite parsers like a ~ b or !a which may fail at traceIndex even without any of their wrapped terminal parsers failing there, it makes use of the shortParserMsg as the string representation of the composite parser.

  20. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  21. def freshFailure(startPos: Int): ParsingRun[Nothing]

    Permalink
  22. def freshFailure(): ParsingRun[Nothing]

    Permalink
  23. def freshSuccess[V](value: V, index: Int, cut: Boolean): ParsingRun[V]

    Permalink
  24. def freshSuccess[V](value: V, cut: Boolean): ParsingRun[V]

    Permalink
  25. def freshSuccess[V](value: V, index: Int): ParsingRun[V]

    Permalink
  26. def freshSuccess[V](value: V): ParsingRun[V]

    Permalink
  27. def freshSuccessUnit(index: Int): ParsingRun[Unit]

    Permalink
  28. def freshSuccessUnit(): ParsingRun[Unit]

    Permalink
  29. final def getClass(): Class[_]

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

    Permalink
    Definition Classes
    AnyRef → Any
  31. var index: Int

    Permalink

    The current index of the parse

  32. val input: ParserInput

    Permalink

    The input to the parsing run, as a ParserInput.

  33. val instrument: Instrument

    Permalink

    Callbacks that can be injected before/after every P(...) parser.

  34. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  35. var isSuccess: Boolean

    Permalink

    Whether or not the parse is currently successful

  36. var lastFailureMsg: Msgs

    Permalink
  37. var logDepth: Int

    Permalink

    How many nested .log calls are currently surrounding us.

    How many nested .log calls are currently surrounding us. Used to nicely indent the log output so you can see which parsers are nested within which other parsers; -1 means logging is disabled

  38. val misc: Map[Any, Any]

    Permalink

    Additional key-value metadata that a user can attach to a parsing run, and manage however they like.

    Additional key-value metadata that a user can attach to a parsing run, and manage however they like. Not as high performance as the built-in fields of ParsingRun, but perhaps sufficient to satisfy ad-hoc needs e.g. keeping track of indentation or other contextual information

  39. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  40. var noDropBuffer: Boolean

    Permalink

    Flag that prevents the parser from dropping earlier input.

    Flag that prevents the parser from dropping earlier input. Used for the .! capture operator that needs the input around to return as a string, the NoCut operator that forces backtracking (regardless of internal cuts), or whitespace consumption which implicitly backtracks if the parser on the RHS of the whitespace fails or consumes 0 characters. The value for this field is lexically scoped, but it is up to the individual parser method implementations to set the values and remember to un-set it to the previous value after they finish. Forgetting to re-set it to the previous value can cause strange behavior or crashes.

  41. final def notify(): Unit

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

    Permalink
    Definition Classes
    AnyRef
  43. val originalParser: (ParsingRun[_]) ⇒ ParsingRun[_]

    Permalink

    The original parsing function we used to start this run, so as to allow .result.traced to re-create it with tracing enabled.

  44. def setMsg(startIndex: Int, f: Msgs): Unit

    Permalink
  45. def setMsg(startIndex: Int, f: () ⇒ String): Unit

    Permalink
  46. var shortParserMsg: Msgs

    Permalink

    When tracing is enabled, this contains string representation of the last parser to run.

    When tracing is enabled, this contains string representation of the last parser to run. Since parsers aren't really objects, we piece together the string in the parser body and return store it here, and an enclosing parser may fetch it back out to help build its own string representation. If the last parser started before the traceIndex, we only aggregate the portion of the parser msg that takes place after traceIndex

  47. val startIndex: Int

    Permalink

    Where the parse initially started, so as to allow .result.traced to re-create it with tracing enabled.

  48. var successValue: Any

    Permalink

    The currently returned success value

  49. final def synchronized[T0](arg0: ⇒ T0): T0

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

    Permalink
    Definition Classes
    AnyRef → Any
  51. val traceIndex: Int

    Permalink

    The index we wish to trace if tracing is enabled, else -1.

    The index we wish to trace if tracing is enabled, else -1. Used to find failure messages to aggregate into failureTerminalAggregate

  52. var verboseFailures: Boolean

    Permalink

    Whether or not we are currently collecting lastFailureMsgs; defaults to false, unless traceIndex is set OR we are inside a LogByNameOps.log call which necessitates tracing in order to print out failure traces during logging

  53. final def wait(): Unit

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

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

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

Inherited from AnyRef

Inherited from Any

Ungrouped