Skip to content

Commit 9b0c0b8

Browse files
committed
clean up unparser
1 parent e4cec15 commit 9b0c0b8

File tree

4 files changed

+22
-44
lines changed

4 files changed

+22
-44
lines changed

assets/progs/happySad.mc

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,84 @@
11
Page 1
2-
press button_A show_image LED_image
2+
When press button_A Do show_image LED_image
33
1 1 . 1 1
44
1 1 . 1 1
55
. . . . .
66
1 . . . 1
77
. 1 1 1 .
8-
98
LED_image
109
1 1 . 1 1
1110
. . . . .
1211
1 . . . 1
1312
. 1 1 1 .
1413
. . . . .
1514
16-
EOR
1715
18-
press button_A play_sound happy EOR
16+
When press button_A Do play_sound happy
1917
20-
press button_B show_image LED_image
18+
When press button_B Do show_image LED_image
2119
1 1 . 1 1
2220
1 1 . 1 1
2321
. . . . .
2422
. 1 1 1 .
2523
1 . . . 1
26-
2724
LED_image
2825
1 1 . 1 1
2926
1 1 . 1 1
3027
. . . . .
3128
. . . . .
3229
1 1 1 1 1
3330
34-
EOR
3531
36-
press button_B play_sound sad EOR
32+
When press button_B Do play_sound sad
3733
38-
EOP
3934
Page 2
4035
41-
EOP
4236
Page 3
4337
44-
EOP
4538
Page 4
4639
47-
EOP
4840
Page 5
4941
50-
EOP
51-
52-
button-up
5342
5443
Page 1
55-
press button_A show_image LED_image
44+
When press button_A Do show_image LED_image
5645
1 1 . 1 1
5746
1 1 . 1 1
5847
. . . . .
5948
1 . . . 1
6049
. 1 1 1 .
61-
6250
LED_image
6351
1 1 . 1 1
6452
. . . . .
6553
1 . . . 1
6654
. 1 1 1 .
6755
. . . . .
6856
69-
EOR
7057
71-
press button_A play_sound happy EOR
58+
When press button_A Do play_sound happy
7259
73-
press button_B show_image LED_image
60+
When press button_B Do show_image LED_image
7461
1 1 . 1 1
7562
1 1 . 1 1
7663
. . . . .
7764
. 1 1 1 .
7865
1 . . . 1
79-
8066
LED_image
8167
1 1 . 1 1
8268
1 1 . 1 1
8369
. . . . .
8470
. . . . .
8571
1 1 1 1 1
8672
87-
EOR
8873
89-
press button_B play_sound sad EOR
74+
When press button_B Do play_sound sad
9075
91-
EOP
9276
Page 2
9377
94-
EOP
9578
Page 3
9679
97-
EOP
9880
Page 4
9981
100-
EOP
10182
Page 5
10283
103-
EOP
84+

editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ namespace microcode {
296296
this.progdef = ProgramDefn.fromBuffer(new BufferReader(buf))
297297
// to string
298298
const progAsString = this.progdef.toString()
299-
const progFromString = parse(progAsString)
299+
console.log(progAsString)
300+
// const progFromString = parse(progAsString)
300301
// const progAsBuf = progFromString.toBuffer()
301302
// // compare buffers
302303
// if (buf.length == progAsBuf.length) {

language.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,26 +286,24 @@ namespace microcode {
286286
const tok = toToken(tile)
287287
if (tile instanceof ModifierEditor) {
288288
const mod = tile as ModifierEditor
289-
return (
290-
tok +
291-
`\n` +
292-
mod.fieldEditor.toString(mod.getField()) +
293-
"\n"
294-
)
289+
const field = mod.fieldEditor.toString(mod.getField())
290+
if (mod instanceof IconEditor) return `${tok}\n${field}`
291+
else return `${tok} ${field}\n`
295292
}
296293
return tok
297294
}
298295
return (
296+
"When " +
299297
toToken(this.sensor) +
300298
" " +
301299
this.filters.map(tileToString).join(" ") +
302-
" " +
300+
" Do " +
303301
(this.actuators.length
304302
? toToken(this.actuators[0]) +
305303
" " +
306304
this.modifiers.map(tileToString).join(" ")
307305
: "") +
308-
" EOR\n"
306+
"\n"
309307
)
310308
}
311309
}
@@ -417,7 +415,7 @@ namespace microcode {
417415

418416
public toString() {
419417
const res = this.pages.map(page => page.toString())
420-
return res.map((ps, i) => `Page ${i + 1}\n${ps}\nEOP`).join("\n")
418+
return res.map((ps, i) => `Page ${i + 1}\n${ps}`).join("\n")
421419
}
422420
}
423421

mcparser.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace microcode {
2828
for (let i = 0; i < lines.length; i++) {
2929
if (currTile && currTile instanceof IconEditor) {
3030
const all5 = lines.slice(i, i + 5).join("\n")
31-
console.log(`get the image? ${all5}`)
31+
console.log(`get the image?\n${all5}`)
3232
currTile.field = currTile.fieldEditor.fromString(all5)
3333
currTile = undefined
3434
i = i + 4 // loop count adds one more
@@ -42,13 +42,11 @@ namespace microcode {
4242
} else if (tokens[0] == "EOP") {
4343
prog.pages.push(currPage)
4444
currPage = undefined
45-
} else if (tokens[0] == "EOR") {
46-
console.log("EOR")
47-
currPage.rules.push(currRule)
48-
currRule = undefined
45+
} else if (tokens[0] == "When") {
46+
if (currRule) currPage.rules.push(currRule)
47+
currRule = new RuleDefn()
4948
} else {
5049
if (!currRule) {
51-
currRule = new RuleDefn()
5250
currRule.sensors.push(token2tile(tokens[0]) as number)
5351
tokens.shift()
5452
}

0 commit comments

Comments
 (0)