Skip to content

Commit 379cea4

Browse files
committed
getting further...
1 parent 4869111 commit 379cea4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

mcparser.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ namespace microcode {
44
export function parse(str: string): ProgramDefn {
55
const token2tile = (tok: string) => {
66
const tid = tooltip2tid(tok.replaceAll("_", " "))
7+
control.assert(tid != undefined, `tok ${tok} does not have mapping`)
78
// check to see if field editor needed
89
const tile = getEditor(tid)
9-
if (tile instanceof ModifierEditor) {
10+
if (tile && tile instanceof ModifierEditor) {
1011
return tile.getNewInstance()
1112
} else {
1213
return tid
1314
}
1415
}
15-
const placeTile = (tile: Tile, rule: RuleDefn) => {
16+
const addTile = (tile: Tile, rule: RuleDefn) => {
1617
const tid = getTid(tile)
1718
if (isFilter(tid)) rule.push(tile, "filters", false)
1819
else if (isModifier(tid)) rule.push(tile, "modifiers", false)
@@ -25,8 +26,9 @@ namespace microcode {
2526
let currRule: RuleDefn = undefined
2627
let currTile: Tile = undefined
2728
for (let i = 0; i < lines.length; i++) {
28-
if (currTile instanceof IconEditor) {
29-
const all5 = lines.slice(i, i + 4).join("\n")
29+
if (currTile && currTile instanceof IconEditor) {
30+
const all5 = lines.slice(i, i + 5).join("\n")
31+
console.log(`get the image? ${all5}`)
3032
currTile.field = currTile.fieldEditor.fromString(all5)
3133
currTile = undefined
3234
i = i + 4 // loop count adds one more
@@ -52,11 +54,9 @@ namespace microcode {
5254
}
5355
let tok = tokens.shift()
5456
while (tok) {
55-
console.log(`tok = ${tok}`)
56-
if (!currTile) {
57-
currTile = token2tile(tok)
58-
placeTile(currTile, currRule)
59-
} else if (currTile instanceof IconEditor) {
57+
currTile = token2tile(tok)
58+
addTile(currTile, currRule)
59+
if (currTile instanceof IconEditor) {
6060
console.log(`got IconEditor`)
6161
break
6262
} else if (currTile instanceof DigitEditor) {

0 commit comments

Comments
 (0)