Class/Object

grizzled.file

Includer

Related Docs: object Includer | package file

Permalink

class Includer extends Iterator[String]

Process "include" directives in files, returning an iterator over lines from the flattened files.

The grizzled.file.Includer class can be used to process "include" directives within a text file, returning a file-like object. It also contains some utility functions that permit using include-enabled files in other contexts.

Syntax

The include syntax is defined by a regular expression; any line that matches the regular expression is treated as an include directive. The default regular expression, %include\s"(["]+)"$ matches include directives like this:

%include "/absolute/path/to/file"
%include "../relative/path/to/file"
%include "local_reference"
%include "http://localhost/path/to/my.config"

Relative and local file references are relative to the including file or URL. That is, if an Includer is processing file "/home/bmc/foo.txt" and encounters an attempt to include file "bar.txt", it will assume "bar.txt" is to be found in "/home/bmc".

Similarly, if an Includer is processing URL "http://localhost/bmc/foo.txt" and encounters an attempt to include file "bar.txt", it will assume "bar.txt" is to be found at "http://localhost/bmc/bar.txt".

Nested includes are permitted; that is, an included file may, itself, include other files. The maximum recursion level is configurable and defaults to 100.

The include syntax can be changed by passing a different regular expression to the Includer constructor.

Usage

This package provides an Includer class, which processes include directives in a file and behaves somewhat like a Scala Source. See the class documentation for more details.

The package also provides a preprocess() convenience function, via a companion object, that can be used to preprocess a file; it returns the path to the resulting preprocessed file.

Examples

Preprocess a file containing include directives, then read the result:

import grizzled.file.Includer

Includer(path).foreach(println(_))

Use an include-enabled file with a Scala scala.io.Source object:

import grizzled.file.includer.Includer
import scala.io.Source

val source = Source.fromFile(Includer.preprocess("/path/to/file"))
Linear Supertypes
Iterator[String], TraversableOnce[String], GenTraversableOnce[String], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Includer
  2. Iterator
  3. TraversableOnce
  4. GenTraversableOnce
  5. AnyRef
  6. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Includer(source: Source, includeRegex: Regex, maxNesting: Int)

    Permalink

    source

    the Source to read

    includeRegex

    the regular expression that defines an include directive. Must contain a group that surrounds the file or URL part.

    maxNesting

    the maximum nesting level

Type Members

  1. class GroupedIterator[B >: A] extends AbstractIterator[Seq[B]] with Iterator[Seq[B]]

    Permalink
    Definition Classes
    Iterator

Value Members

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  3. def ++[B >: String](that: ⇒ GenTraversableOnce[B]): Iterator[B]

    Permalink
    Definition Classes
    Iterator
  4. def /:[B](z: B)(op: (B, String) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  5. def :\[B](z: B)(op: (String, B) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  6. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  7. def addString(b: StringBuilder): StringBuilder

    Permalink
    Definition Classes
    TraversableOnce
  8. def addString(b: StringBuilder, sep: String): StringBuilder

    Permalink
    Definition Classes
    TraversableOnce
  9. def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder

    Permalink
    Definition Classes
    TraversableOnce
  10. def aggregate[B](z: ⇒ B)(seqop: (B, String) ⇒ B, combop: (B, B) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. def buffered: BufferedIterator[String]

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. def collect[B](pf: PartialFunction[String, B]): Iterator[B]

    Permalink
    Definition Classes
    Iterator
    Annotations
    @migration
    Migration

    (Changed in version 2.8.0) collect has changed. The previous behavior can be reproduced with toSeq.

  15. def collectFirst[B](pf: PartialFunction[String, B]): Option[B]

    Permalink
    Definition Classes
    TraversableOnce
  16. def contains(elem: Any): Boolean

    Permalink
    Definition Classes
    Iterator
  17. def copyToArray[B >: String](xs: Array[B], start: Int, len: Int): Unit

    Permalink
    Definition Classes
    Iterator → TraversableOnce → GenTraversableOnce
  18. def copyToArray[B >: String](xs: Array[B]): Unit

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  19. def copyToArray[B >: String](xs: Array[B], start: Int): Unit

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  20. def copyToBuffer[B >: String](dest: Buffer[B]): Unit

    Permalink
    Definition Classes
    TraversableOnce
  21. def corresponds[B](that: GenTraversableOnce[B])(p: (String, B) ⇒ Boolean): Boolean

    Permalink
    Definition Classes
    Iterator
  22. def count(p: (String) ⇒ Boolean): Int

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  23. def drop(n: Int): Iterator[String]

    Permalink
    Definition Classes
    Iterator
  24. def dropWhile(p: (String) ⇒ Boolean): Iterator[String]

    Permalink
    Definition Classes
    Iterator
  25. def duplicate: (Iterator[String], Iterator[String])

    Permalink
    Definition Classes
    Iterator
  26. final def eq(arg0: AnyRef): Boolean

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

    Permalink
    Definition Classes
    AnyRef → Any
  28. def exists(p: (String) ⇒ Boolean): Boolean

    Permalink
    Definition Classes
    Iterator → TraversableOnce → GenTraversableOnce
  29. def filter(p: (String) ⇒ Boolean): Iterator[String]

    Permalink
    Definition Classes
    Iterator
  30. def filterNot(p: (String) ⇒ Boolean): Iterator[String]

    Permalink
    Definition Classes
    Iterator
  31. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  32. def find(p: (String) ⇒ Boolean): Option[String]

    Permalink
    Definition Classes
    Iterator → TraversableOnce → GenTraversableOnce
  33. def flatMap[B](f: (String) ⇒ GenTraversableOnce[B]): Iterator[B]

    Permalink
    Definition Classes
    Iterator
  34. def fold[A1 >: String](z: A1)(op: (A1, A1) ⇒ A1): A1

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  35. def foldLeft[B](z: B)(op: (B, String) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  36. def foldRight[B](z: B)(op: (String, B) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  37. def forall(p: (String) ⇒ Boolean): Boolean

    Permalink
    Definition Classes
    Iterator → TraversableOnce → GenTraversableOnce
  38. def foreach[U](f: (String) ⇒ U): Unit

    Permalink
    Definition Classes
    Iterator → TraversableOnce → GenTraversableOnce
  39. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  40. def grouped[B >: String](size: Int): GroupedIterator[B]

    Permalink
    Definition Classes
    Iterator
  41. def hasDefiniteSize: Boolean

    Permalink
    Definition Classes
    Iterator → TraversableOnce → GenTraversableOnce
  42. def hasNext: Boolean

    Permalink

    Determine whether there are any more input lines to be read from the includer.

    Determine whether there are any more input lines to be read from the includer.

    returns

    true if at least one more line is available, false otherwise

    Definition Classes
    Includer → Iterator
  43. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  44. val includeRegex: Regex

    Permalink

    the regular expression that defines an include directive.

    the regular expression that defines an include directive. Must contain a group that surrounds the file or URL part.

  45. def indexOf[B >: String](elem: B, from: Int): Int

    Permalink
    Definition Classes
    Iterator
  46. def indexOf[B >: String](elem: B): Int

    Permalink
    Definition Classes
    Iterator
  47. def indexWhere(p: (String) ⇒ Boolean, from: Int): Int

    Permalink
    Definition Classes
    Iterator
  48. def indexWhere(p: (String) ⇒ Boolean): Int

    Permalink
    Definition Classes
    Iterator
  49. def isEmpty: Boolean

    Permalink
    Definition Classes
    Iterator → TraversableOnce → GenTraversableOnce
  50. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  51. def isTraversableAgain: Boolean

    Permalink
    Definition Classes
    Iterator → GenTraversableOnce
  52. def length: Int

    Permalink
    Definition Classes
    Iterator
  53. def map[B](f: (String) ⇒ B): Iterator[B]

    Permalink
    Definition Classes
    Iterator
  54. def max[B >: String](implicit cmp: Ordering[B]): String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  55. def maxBy[B](f: (String) ⇒ B)(implicit cmp: Ordering[B]): String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  56. val maxNesting: Int

    Permalink

    the maximum nesting level

  57. def min[B >: String](implicit cmp: Ordering[B]): String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  58. def minBy[B](f: (String) ⇒ B)(implicit cmp: Ordering[B]): String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  59. def mkString: String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  60. def mkString(sep: String): String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  61. def mkString(start: String, sep: String, end: String): String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  62. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  63. def next(): String

    Permalink

    Get the next input line.

    Get the next input line. You should call hasNext before calling this method, to ensure that there are input lines remaining. Calling next on an empty Includer will result in a runtime exception

    returns

    the next input line

    Definition Classes
    Includer → Iterator
  64. def nonEmpty: Boolean

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  65. final def notify(): Unit

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

    Permalink
    Definition Classes
    AnyRef
  67. def padTo[A1 >: String](len: Int, elem: A1): Iterator[A1]

    Permalink
    Definition Classes
    Iterator
  68. def partition(p: (String) ⇒ Boolean): (Iterator[String], Iterator[String])

    Permalink
    Definition Classes
    Iterator
  69. def patch[B >: String](from: Int, patchElems: Iterator[B], replaced: Int): Iterator[B]

    Permalink
    Definition Classes
    Iterator
  70. def product[B >: String](implicit num: Numeric[B]): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  71. def reduce[A1 >: String](op: (A1, A1) ⇒ A1): A1

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  72. def reduceLeft[B >: String](op: (B, String) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce
  73. def reduceLeftOption[B >: String](op: (B, String) ⇒ B): Option[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  74. def reduceOption[A1 >: String](op: (A1, A1) ⇒ A1): Option[A1]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  75. def reduceRight[B >: String](op: (String, B) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  76. def reduceRightOption[B >: String](op: (String, B) ⇒ B): Option[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  77. def reversed: List[String]

    Permalink
    Attributes
    protected[this]
    Definition Classes
    TraversableOnce
  78. def sameElements(that: Iterator[_]): Boolean

    Permalink
    Definition Classes
    Iterator
  79. def scanLeft[B](z: B)(op: (B, String) ⇒ B): Iterator[B]

    Permalink
    Definition Classes
    Iterator
  80. def scanRight[B](z: B)(op: (String, B) ⇒ B): Iterator[B]

    Permalink
    Definition Classes
    Iterator
  81. def seq: Iterator[String]

    Permalink
    Definition Classes
    Iterator → TraversableOnce → GenTraversableOnce
  82. def size: Int

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  83. def slice(from: Int, until: Int): Iterator[String]

    Permalink
    Definition Classes
    Iterator
  84. def sliceIterator(from: Int, until: Int): Iterator[String]

    Permalink
    Attributes
    protected
    Definition Classes
    Iterator
  85. def sliding[B >: String](size: Int, step: Int): GroupedIterator[B]

    Permalink
    Definition Classes
    Iterator
  86. val source: Source

    Permalink

    the Source to read

  87. def span(p: (String) ⇒ Boolean): (Iterator[String], Iterator[String])

    Permalink
    Definition Classes
    Iterator
  88. def sum[B >: String](implicit num: Numeric[B]): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  89. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  90. def take(n: Int): Iterator[String]

    Permalink
    Definition Classes
    Iterator
  91. def takeWhile(p: (String) ⇒ Boolean): Iterator[String]

    Permalink
    Definition Classes
    Iterator
  92. def to[Col[_]](implicit cbf: CanBuildFrom[Nothing, String, Col[String]]): Col[String]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  93. def toArray[B >: String](implicit arg0: ClassTag[B]): Array[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  94. def toBuffer[B >: String]: Buffer[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  95. def toIndexedSeq: IndexedSeq[String]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  96. def toIterable: Iterable[String]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  97. def toIterator: Iterator[String]

    Permalink
    Definition Classes
    Iterator → GenTraversableOnce
  98. def toList: List[String]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  99. def toMap[T, U](implicit ev: <:<[String, (T, U)]): Map[T, U]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  100. def toSeq: Seq[String]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  101. def toSet[B >: String]: Set[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  102. def toStream: Stream[String]

    Permalink
    Definition Classes
    Iterator → GenTraversableOnce
  103. def toString(): String

    Permalink
    Definition Classes
    Iterator → AnyRef → Any
  104. def toTraversable: Traversable[String]

    Permalink
    Definition Classes
    Iterator → TraversableOnce → GenTraversableOnce
  105. def toVector: Vector[String]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  106. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  109. def withFilter(p: (String) ⇒ Boolean): Iterator[String]

    Permalink
    Definition Classes
    Iterator
  110. def zip[B](that: Iterator[B]): Iterator[(String, B)]

    Permalink
    Definition Classes
    Iterator
  111. def zipAll[B, A1 >: String, B1 >: B](that: Iterator[B], thisElem: A1, thatElem: B1): Iterator[(A1, B1)]

    Permalink
    Definition Classes
    Iterator
  112. def zipWithIndex: Iterator[(String, Int)]

    Permalink
    Definition Classes
    Iterator

Inherited from Iterator[String]

Inherited from TraversableOnce[String]

Inherited from GenTraversableOnce[String]

Inherited from AnyRef

Inherited from Any

Ungrouped