yaml is a parser for the YAML data serialization language written in Scala. yaml is moving towards compliance with YAML Version 1.2, but is still in early development.
Here are some example code snippets showing how to use the parser.
This is from example 2.10 from chapter 2 of the spec.
import xyz.hyperreal.yaml._
object Example extends App {
val result =
read(
"""
|---
|hr:
| - Mark McGwire
| # Following node labeled SS
| - &SS Sammy Sosa
|rbi:
| - *SS # Subsequent occurrence
| - Ken Griffey
""".stripMargin
)
println( result )
}
List(Map(hr -> List(Mark McGwire, Sammy Sosa), rbi -> List(Sammy Sosa, Ken Griffey)))
This is from example 2.27 from chapter 2 of the spec.
---
invoice: 34843
date : 2001-01-23
bill-to: &id001
given : Chris
family : Dumars
address:
lines: |
458 Walkman Dr.
Suite #292
city : Royal Oak
state : MI
postal : 48046
ship-to: *id001
product:
- sku : BL394D
quantity : 4
description : Basketball
price : 450.00
- sku : BL4438H
quantity : 1
description : Super Hoop
price : 2392.00
tax : 251.42
total: 4443.52
comments:
Late afternoon is best.
Backup contact is Nancy
Billsmer @ 338-4338.
...
The output from the above example is equivalent the result of the following Scala snippet.
val bill_to =
Map(
"given" -> "Chris",
"family" -> "Dumars",
"address" ->
Map(
"lines" -> "458 Walkman Dr.\nSuite #292\n",
"city" -> "Royal Oak",
"state" -> "MI",
"postal" -> 48046
)
)
Map(
"invoice" -> 34843,
"date" -> LocalDate.parse("2001-01-23"),
"bill-to" -> bill_to,
"ship-to" -> bill_to,
"product" ->
List(
Map(
"sku" -> "BL394D",
"quantity" -> 4,
"description" -> "Basketball",
"price" -> 450.00
),
Map(
"sku" -> "BL4438H",
"quantity" -> 1,
"description" -> "Super Hoop",
"price" -> 2392.00
)
),
"tax" -> 251.42,
"total" -> 4443.52,
"comments" -> "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338."
)
Use the following definition to use Yaml in your Maven project:
<repository>
<id>hyperreal</id>
<url>https://dl.bintray.com/edadma/maven</url>
</repository>
<dependency>
<groupId>xyz.hyperreal</groupId>
<artifactId>yaml</artifactId>
<version>0.2</version>
</dependency>
Add the following to your build.sbt
file to use yaml in your SBT project:
resolvers += "Hyperreal Repository" at "https://dl.bintray.com/edadma/maven"
libraryDependencies += "xyz.hyperreal" %% "yaml" % "0.2"
- Java 11
- SBT 1.2.8+
- Scala 2.13.0+
git clone git://github.com/edadma/yaml.git
cd yaml
sbt assembly
The command sbt assembly
also runs all the unit tests.
ISC © 2019 Edward A. Maxedon, Sr.