aboutsummaryrefslogtreecommitdiff
path: root/yamlesque/src/package.scala
blob: 43ab30b1c61a282259ed92b17c9031101fbc1d71 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package object yamlesque {
  import java.io.StringReader

  def read(input: String): Node = {
    (new Parser(new StringReader(input))).next()
  }

  def tryRead(input: String): Either[String, Node] =
    try {
      Right(read(input))
    } catch {
      case Parser.ParseException(msg) => Left(msg)
    }

  def readAll(input: String): List[Node] = {
    (new Parser(new StringReader(input))).toList
  }

  // TODO: the parser can actually recover from errors when a new document begins
  def tryReadAll(input: String): Either[String, List[Node]] =
    try {
      Right((new Parser(new StringReader(input))).toList)
    } catch {
      case Parser.ParseException(msg) => Left(msg)
    }

  def write(nodes: Node*): String = write(nodes)
  def write(nodes: Iterable[Node]): String = Writer.write(nodes)

}