eu.matthiasbraun.sparse

Parser

Related Doc: package sparse

object Parser

A parser for extracting text blocks from a source such as a file. Created by Matthias Braun on 5/7/15.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Parser
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class BlockMarker(linePredicate: (String, Int) ⇒ Boolean, offset: Int = 0) extends Product with Serializable

    Marks the start or end of a text block.

    Marks the start or end of a text block. The linePredicate and its offset define where in the text this marker is placed.

  2. trait MarkerFactory extends AnyRef

    Inheritance allows use to reuse the constructor code defined in MarkerFactory's apply methods.

    Inheritance allows use to reuse the constructor code defined in MarkerFactory's apply methods. Alternatively, we could have used implicit conversions to turn, for example, from("start") into from(BlockMarker((anInt: Int, aString: String) => "start".equals")) and thus share constructors among to, from, and the rest. The drawback of these conversions is that target typing is not available, requiring the user of this library to provide types explicitly, therefore having to write from((_: String).startsWith("start")) instead of from(_.startsWith("start")).

  3. case class SparseException(msg: String) extends RuntimeException with Product with Serializable

    Thrown when the text couldn't be properly parsed.

  4. case class TextBlock(lines: Vector[String]) extends Product with Serializable

    A bunch of lines are a text block.

Value Members

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

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

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

    Definition Classes
    AnyRef → Any
  4. object after extends MarkerFactory

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker after that line.

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker after that line. This marker may either indicate the start or end of a eu.matthiasbraun.sparse.Parser.TextBlock. Example usage:

    parse(source, after("line before start"), to("end line")) parse(source, from("start line), after(_.startsWith("prefix of line before end"))) parse(source, after((line, lineNr) => line == "line before start" && lineNr > 10), to("end line"))

  5. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  6. object before extends MarkerFactory

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker before that line.

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker before that line. This marker indicates the start of a eu.matthiasbraun.sparse.Parser.TextBlock. Example usage:

    parse(source, before("line after start"), to("end line")) parse(source, before(_.startsWith("prefix of line after start"), to("end line")) parse(source, before((line, lineNr) => line == "line after start" && lineNr > 10), to("end line"))

  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

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

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. object from extends MarkerFactory

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker at that line.

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker at that line. This marker indicates the start of a eu.matthiasbraun.sparse.Parser.TextBlock. Example usage:

    parse(source, from("start line"), to("end line")) parse(source, from(_.endsWith("start line suffix")), to(_.startsWith("end line prefix"))) parse(source, from((line, lineNr) => line == "start line" && lineNr > 10 ), to("end line))

  12. final def getClass(): Class[_]

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

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

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

    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  18. def parse(source: Source, start: BlockMarker, end: BlockMarker): Try[List[TextBlock]]

    Parses eu.matthiasbraun.sparse.Parser.TextBlocks from a source, such as a file.

    Parses eu.matthiasbraun.sparse.Parser.TextBlocks from a source, such as a file. The start and end of a text block are defined by the start and end eu.matthiasbraun.sparse.Parser.BlockMarkers. These markers match lines within the text. The caller can create those markers using eu.matthiasbraun.sparse.Parser.from or eu.matthiasbraun.sparse.Parser.until, for example. Example usage:

    val file = new File("parse/this/file")
    val blocksMaybe = parse(fromFile(file), from("start line"), to("end line"))
      blocksMaybe match {
        case Success(blocks)    => blocks.foreach { println }
        case Failure(exception) => println(exception)
    }
    source

    the scala.io.Source that contains the text that we want to parse

    start

    the text blocks we want to parse begin at this eu.matthiasbraun.sparse.Parser.BlockMarker

    end

    the text blocks we want to parse stop at this eu.matthiasbraun.sparse.Parser.BlockMarker

    returns

    either a list of eu.matthiasbraun.sparse.Parser.TextBlocks wrapped in a scala.util.Success or a scala.util.Failure with the first exception that occurred during parsing.

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

    Definition Classes
    AnyRef
  20. object to extends MarkerFactory

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker at that line.

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker at that line. This marker indicates the end of a eu.matthiasbraun.sparse.Parser.TextBlock. Example usage:

    parse(source, from("start line"), to("end line")) parse(source, from(_.endsWith("start line suffix")), to(_.startsWith("end line prefix"))) parse(source, from("start line), to((line, lineNr) => line == "end line" && lineNr > 10 ))

  21. def toString(): String

    Definition Classes
    AnyRef → Any
  22. object until extends MarkerFactory

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker before that line.

    When a line within the parsed text matches the predicate, we set a eu.matthiasbraun.sparse.Parser.BlockMarker before that line. This marker indicates the end of a eu.matthiasbraun.sparse.Parser.TextBlock. Example usage:

    parse(source, from("start line"), until("line after end")) parse(source, from("start line"), until(_.startsWith("prefix of line after end"))) parse(source, from("start line), until((line, lineNr) => line == "line after end " && lineNr > 10 ))

  23. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped