@effekt-lang/effekt 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,7 +62,7 @@ def encodeJsonObject[R]{ body: => R / JsonObjectBuilder }: R / emit[String] = {
62
62
  do emit("{")
63
63
  def c(k: String) = {
64
64
  if (not(first)) { do emit(",") }
65
- do emit(escape(k)); do emit(":")
65
+ do emit(escape(k)); do emit(":")
66
66
  first = false
67
67
  }
68
68
  val r = encodeJson {
@@ -76,7 +76,7 @@ def encodeJsonObject[R]{ body: => R / JsonObjectBuilder }: R / emit[String] = {
76
76
  /// Main entry point for encoding json.
77
77
  /// Emits individual tokens of the resulting json.
78
78
  def encodeJson[R]{ body: => R / JsonBuilder }: R / emit[String] = {
79
- try body() with JsonBuilder {
79
+ try body() with JsonBuilder {
80
80
  def null() = { resume(do emit("null")) }
81
81
  def bool(v) = { resume(do emit( if(v){ "true" } else { "false" } )) }
82
82
  def number(n) = { resume(do emit(show(n))) }
@@ -112,7 +112,7 @@ def readDouble(): Double / Scan[Char] = {
112
112
  if (optionally { readIf('.') }) {
113
113
  var b = 0.1
114
114
  var r = pre.toDouble
115
- while (optionally[Int] { readDigit() } is Some(d)) {
115
+ while (returning::optionally[Int] { readDigit() } is Some(d)) {
116
116
  r = r + b * d.toDouble
117
117
  b = b * 0.1
118
118
  }
@@ -126,14 +126,14 @@ def readDouble(): Double / Scan[Char] = {
126
126
 
127
127
  def expectString(string: String): Unit / { Scan[Char], Exception[WrongFormat] } =
128
128
  for[Char] { string.each } { char =>
129
- expect[Unit]("Expected " ++ string) { readIf(char) }
129
+ expect("Expected " ++ string) { readIf(char) }
130
130
  }
131
131
 
132
132
  /// Read and unescape a string in ""
133
133
  def readQuotedString(): Unit / { Scan[Char], emit[Char], Exception[WrongFormat] } = {
134
134
  try {
135
135
  skipWhitespace()
136
- expect[Unit]("Expected \"") { readIf('"') }
136
+ expect("Expected \"") { readIf('"') }
137
137
  while(read[Char]() is c and c != '"') {
138
138
  c match {
139
139
  case '\\' => read[Char]() match {
@@ -191,7 +191,7 @@ def decodeJsonObject(): Unit / {Scan[Char], JsonObjectBuilder, Exception[WrongFo
191
191
  }
192
192
  do skip[Char]()
193
193
  }
194
- def decodeJsonList(): Unit / {Scan[Char], JsonBuilder, Exception[WrongFormat]} = {
194
+ def decodeJsonList(): Unit / {Scan[Char], JsonBuilder, Exception[WrongFormat]} = {
195
195
  var first = true
196
196
  expectString("[")
197
197
  with boundary
@@ -278,7 +278,7 @@ def build[R](){ body: => R / JsonBuilder }: (R, JsonValue) = {
278
278
  }
279
279
  (x, r)
280
280
  }
281
- def buildList[R](){ body: => R / JsonBuilder }: (R, List[JsonValue]) = collectList[JsonValue, R] {
281
+ def buildList[R](){ body: => R / JsonBuilder }: (R, List[JsonValue]) = returning::collectList[JsonValue, R] {
282
282
  try body() with JsonBuilder {
283
283
  def number(n) = { do emit(Number(n)); resume(()) }
284
284
  def bool(b) = { do emit(Bool(b)); resume(()) }
@@ -296,7 +296,7 @@ def buildList[R](){ body: => R / JsonBuilder }: (R, List[JsonValue]) = collectLi
296
296
  }
297
297
  }
298
298
  }
299
- def buildDict[R](){ body: => R / JsonObjectBuilder }: (R, List[(String, JsonValue)]) = collectList[(String, JsonValue), R] {
299
+ def buildDict[R](){ body: => R / JsonObjectBuilder }: (R, List[(String, JsonValue)]) = returning::collectList[(String, JsonValue), R] {
300
300
  try body() with JsonObjectBuilder {
301
301
  def field(k) = resume { {v} =>
302
302
  val x = build{v}
@@ -315,10 +315,12 @@ namespace test {
315
315
 
316
316
  // Read quoted string
317
317
  feed("\"\ta\n\ra\"") {
318
- with scanner[Char, Unit]
318
+ with scanner[Char]
319
319
  println(collectString { readQuotedString() })
320
320
  }
321
321
 
322
+ println("")
323
+
322
324
  // Parse example
323
325
  feed("""{ "a": null, "b": [true,false,false,true], "f": 12.532 }"""){
324
326
  with scanner[Char]
@@ -336,8 +338,10 @@ namespace test {
336
338
  }
337
339
  handleJsonBuilder{d}{ decodeJson() }
338
340
  }
339
- try{
340
-
341
+
342
+ println("")
343
+
344
+ try {
341
345
  // Encode example
342
346
  encodeJson {
343
347
  do dict{
@@ -352,13 +356,15 @@ namespace test {
352
356
  }
353
357
  }
354
358
  }
355
-
359
+
360
+ println("")
361
+
356
362
  // format with intermediate value
357
- val j = feed("""{
358
- "a": null,
359
- "b": [true, false, false, true], "f": 12.532
363
+ val j = feed[JsonValue]("""{
364
+ "a": null,
365
+ "b": [true, false, false, true], "f": 12.532
360
366
  } """){
361
- with scanner[Char, JsonValue]
367
+ with returning::scanner[Char, JsonValue]
362
368
  build {
363
369
  decodeJson()
364
370
  }.second
@@ -366,18 +372,20 @@ namespace test {
366
372
  encodeJson{
367
373
  unbuild(j)
368
374
  }
369
-
375
+
376
+ println("")
377
+
370
378
  // format (minify) example
371
379
  encodeJson{
372
- feed("""{
373
- "a": null,
374
- "b": [true, false, false, true], "f": 12.532
380
+ feed("""{
381
+ "a": null,
382
+ "b": [true, false, false, true], "f": 12.532
375
383
  } """){
376
- with scanner[Char, Unit]
384
+ with scanner[Char]
377
385
  decodeJson()
378
386
  }
379
387
  }
380
-
388
+
381
389
  } with emit[String] { e =>
382
390
  resume(println(e))
383
391
  }