386 def empty: Keys = new Keys(Nil) |
386 def empty: Keys = new Keys(Nil) |
387 def quoted(s: Str): Keys = new Keys(List(s)) |
387 def quoted(s: Str): Keys = new Keys(List(s)) |
388 def dotted(s: Str): Keys = new Keys(s.split('.').toList) |
388 def dotted(s: Str): Keys = new Keys(s.split('.').toList) |
389 } |
389 } |
390 |
390 |
391 class Keys private(val rep: List[Key]) extends Positional { |
391 class Keys private(private val rep: List[Key]) extends Positional { |
392 override def hashCode(): Int = rep.hashCode() |
392 override def hashCode(): Int = rep.hashCode() |
393 override def equals(obj: Any): Bool = |
393 override def equals(obj: Any): Bool = |
394 obj match { |
394 obj match { |
395 case other: Keys => rep == other.rep |
395 case other: Keys => rep == other.rep |
396 case _ => false |
396 case _ => false |
501 context.error("Malformed TOML input: " + msg, next.pos) |
501 context.error("Malformed TOML input: " + msg, next.pos) |
502 } |
502 } |
503 |
503 |
504 def convert(ks0: Keys, ks1: Keys, v: Parsers.V): T = { |
504 def convert(ks0: Keys, ks1: Keys, v: Parsers.V): T = { |
505 def to_table(ks: Keys, t: T): Table = |
505 def to_table(ks: Keys, t: T): Table = |
506 ks.parent.rep.foldRight(Table(ks.the_last -> t))((k, v) => Table(k -> v)) |
506 if (ks.length == 1) Table(ks.the_head -> t) |
|
507 else Table(ks.the_head -> to_table(ks.split(1)._2, t)) |
|
508 |
507 def to_toml(v: Parsers.V): (T, Set[Keys]) = v match { |
509 def to_toml(v: Parsers.V): (T, Set[Keys]) = v match { |
508 case Parsers.Primitive(t) => (t, Set.empty) |
510 case Parsers.Primitive(t) => (t, Set.empty) |
509 case Parsers.Array(rep) => (Array(rep.map(to_toml(_)._1)), Set.empty) |
511 case Parsers.Array(rep) => (Array(rep.map(to_toml(_)._1)), Set.empty) |
510 case Parsers.Inline_Table(elems) => |
512 case Parsers.Inline_Table(elems) => |
511 elems.find(e => elems.count(_._1 == e._1) > 1).foreach((ks, _) => |
513 elems.find(e => elems.count(_._1 == e._1) > 1).foreach((ks, _) => |