Skip to content

Commit 75ae7be

Browse files
committed
fix toString with quoted escape for Ent and StrAttr, add types implementation
1 parent d3dab72 commit 75ae7be

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

src/main/scala/02-meta-model.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ object meta:
252252
s"| infix def $name(sub: Elem*): Rel = Rel(e, ${name.capitalize}, Model(sub*))\n" +
253253
s"| infix def $name: Link = Link(e, ${name.capitalize})\n"
254254

255+
def dollar(s: String) = "${" + s + "}"
256+
255257
s"""|//--- THIS IS A GENERATED FILE! DO NOT EDIT AS CHANGES ARE LOST ON RE-GENERATION
256258
|//--- Edit the code below by changing `def generate` in reqt.meta
257259
|//--- Generate this file in sbt> `meta`
@@ -292,7 +294,8 @@ object meta:
292294
|
293295
|final case class Link(e: Ent, t: RelType)
294296
|
295-
|final case class Ent private (t: EntType, id: String) extends Node
297+
|final case class Ent private (t: EntType, id: String) extends Node:
298+
| override def toString = s"Ent(${dollar("t")},${dollar("id.quotedEscaped")})"
296299
|object Ent:
297300
| val emptyId = "???"
298301
| def apply(t: EntType, id: String): Ent =
@@ -304,13 +307,14 @@ object meta:
304307
| def t: AttrType[T]
305308
| def value: T
306309
|
307-
|final case class StrAttr(t: StrAttrType, value: String) extends Attr[String]
310+
|final case class StrAttr(t: StrAttrType, value: String) extends Attr[String]:
311+
| override def toString = s"StrAttr(${dollar("t")},${dollar("value.quotedEscaped")})"
308312
|case object StrAttr extends meta.ConceptGroup:
309-
| def types: Seq[StrAttrType] = ???
313+
| def types: Seq[StrAttrType] = meta.strAttrTypes.values.toSeq
310314
|
311315
|final case class IntAttr(t: IntAttrType, value: Int) extends Attr[Int]
312316
|case object IntAttr extends meta.ConceptGroup:
313-
| def types: Seq[IntAttrType] = ???
317+
| def types: Seq[IntAttrType] = meta.intAttrTypes.values.toSeq
314318
|
315319
|final case class Undefined[T](t: AttrType[T]) extends Attr[T]:
316320
| def value: T = throw new java.util.NoSuchElementException

src/main/scala/03-model-GENERATED.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ sealed trait AttrType[T] extends NodeType:
3838

3939
final case class Link(e: Ent, t: RelType)
4040

41-
final case class Ent private (t: EntType, id: String) extends Node
41+
final case class Ent private (t: EntType, id: String) extends Node:
42+
override def toString = s"Ent(${t},${id.quotedEscaped})"
4243
object Ent:
4344
val emptyId = "???"
4445
def apply(t: EntType, id: String): Ent =
@@ -50,13 +51,14 @@ sealed trait Attr[T] extends Node:
5051
def t: AttrType[T]
5152
def value: T
5253

53-
final case class StrAttr(t: StrAttrType, value: String) extends Attr[String]
54+
final case class StrAttr(t: StrAttrType, value: String) extends Attr[String]:
55+
override def toString = s"StrAttr(${t},${value.quotedEscaped})"
5456
case object StrAttr extends meta.ConceptGroup:
55-
def types: Seq[StrAttrType] = ???
57+
def types: Seq[StrAttrType] = meta.strAttrTypes.values.toSeq
5658

5759
final case class IntAttr(t: IntAttrType, value: Int) extends Attr[Int]
5860
case object IntAttr extends meta.ConceptGroup:
59-
def types: Seq[IntAttrType] = ???
61+
def types: Seq[IntAttrType] = meta.intAttrTypes.values.toSeq
6062

6163
final case class Undefined[T](t: AttrType[T]) extends Attr[T]:
6264
def value: T = throw new java.util.NoSuchElementException

src/main/scala/04-ModelMembers.scala

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,37 +151,57 @@ transparent trait ModelMembers:
151151

152152
/** Remove all elems in es using remove. Same as m.removeAll(e1, e2, e3) */
153153
def --(es: Elem*): Model = removeAll(es*)
154-
154+
155+
/** All entities and attributes in this model. */
155156
def nodes: Vector[Node] = elems.flatMap:
156157
case n: Node => Vector(n)
157158
case Rel(e, r, m) => Vector(e) ++ m.nodes
158159

160+
/** All relation links in of this model. */
159161
def links: Vector[Link] = elems.flatMap:
160162
case _: Node => Vector()
161163
case Rel(e, r, m) => Vector(Link(e,r)) ++ m.links
162164

165+
/** All relation types in of this model. */
163166
def relTypes: Vector[RelType] = links.map(_.t)
164167

168+
/** All relations of this model. */
165169
def rels: Vector[Rel] = elems.flatMap:
166170
case _: Node => Vector()
167171
case r@Rel(_, _, m) => Vector(r) ++ m.rels
168172

169-
173+
/** All undefined attributes of this model. */
170174
def undefined: Vector[Undefined[?]] = nodes.collect{ case u: Undefined[?] => u }
171175

176+
/** All entities of this model. */
172177
def ents: Vector[Ent] = nodes.collect { case e: Ent => e }
178+
179+
/** All entities of this model. */
173180
def entTypes: Vector[EntType] = nodes.collect { case e: Ent => e.t }
181+
182+
/** All attributes of this model. */
174183
def attrs: Vector[Attr[?]] = nodes.collect { case a: Attr[?] => a }
184+
185+
/** All string attributes of this model. */
175186
def strAttrs: Vector[StrAttr] = nodes.collect { case a: StrAttr => a }
187+
188+
/** All string values of this model. */
176189
def strValues: Vector[String] = nodes.collect { case a: StrAttr => a.value }
190+
191+
/** All integer attributes of this model. */
177192
def intAttrs: Vector[IntAttr] = nodes.collect { case a: IntAttr => a }
193+
194+
/** All integer attribute values of this model. */
178195
def intValues: Vector[Int] = nodes.collect { case a: IntAttr => a.value }
179196

197+
/** All entity ids of this model. */
180198
lazy val ids: Vector[String] = ents.map(_.id)
181199

200+
/** A Map from entity id to a Set of entity types of all entity ids of this model. */
182201
lazy val idTypeMap: Map[String, Set[EntType]] =
183202
ents.groupBy(_.id).map((id, xs) => id -> xs.map(_.t).toSet)
184203

204+
/** A Map from entity id to a Vector of all entities with that id. */
185205
lazy val idMap: Map[String, Vector[Ent]] =
186206
ents.groupBy(_.id).map((id, xs) => id -> xs.toVector)
187207

0 commit comments

Comments
 (0)