Skip to content

Commit 45f54ff

Browse files
committed
done with parser
1 parent def49de commit 45f54ff

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

language.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,17 @@ namespace microcode {
281281

282282
public toString() {
283283
const toToken = (tile: Tile) =>
284-
resolveTooltip("T" + getTid(tile)).replaceAll(" ", "-")
284+
resolveTooltip("T" + getTid(tile)).replaceAll(" ", "_")
285285
const tileToString = (tile: Tile) => {
286286
const tok = toToken(tile)
287287
if (tile instanceof ModifierEditor) {
288288
const mod = tile as ModifierEditor
289-
return tok + `\n` + mod.fieldEditor.toString(mod.getField())
289+
return (
290+
tok +
291+
`\n` +
292+
mod.fieldEditor.toString(mod.getField()) +
293+
"\n"
294+
)
290295
}
291296
return tok
292297
}

mcparser.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace microcode {
1515

1616
export function parse(str: string) {
1717
const token2tile = (tok: string) => {
18-
const tid = tooltip2tid(tok)
18+
const tid = tooltip2tid(tok.replaceAll("_", " "))
1919
// check to see if field editor needed
2020
const tile = getEditor(tid)
2121
if (tile instanceof ModifierEditor) {
@@ -35,7 +35,16 @@ namespace microcode {
3535
const lines = str.split("\n")
3636
let currPage: PageDefn = undefined
3737
let currRule: RuleDefn = undefined
38+
let currTile: Tile = undefined
3839
for (let i = 0; i < lines.length; i++) {
40+
if (currTile instanceof IconEditor) {
41+
// grab the next 4 lines as well
42+
const all5 = lines.slice(i, i + 4).join("\n")
43+
currTile.field = currTile.fieldEditor.fromString(all5)
44+
currTile = undefined
45+
i = i + 4
46+
continue
47+
}
3948
const line = lines[0].split(" ")
4049
if (line[0] == "Page") {
4150
currPage = new PageDefn()
@@ -53,11 +62,23 @@ namespace microcode {
5362
}
5463
let tok = line.shift()
5564
while (tok) {
56-
const tile = token2tile(tok)
57-
placeTile(tile, currRule)
58-
if (tile instanceof ModifierEditor) {
59-
// TODO: process the field, based on context
60-
} else tok = line.shift()
65+
if (!currTile) {
66+
currTile = token2tile(tok)
67+
placeTile(currTile, currRule)
68+
tok = line.shift()
69+
} else if (currTile instanceof IconEditor) {
70+
break
71+
} else if (currTile instanceof DigitEditor) {
72+
currTile.field = currTile.fieldEditor.fromString(tok)
73+
currTile = undefined
74+
tok = line.shift()
75+
} else if (currTile instanceof MelodyEditor) {
76+
currTile.field = currTile.fieldEditor.fromString(
77+
tok + line.join(" ")
78+
)
79+
currTile = undefined
80+
break
81+
}
6182
}
6283
}
6384
}

0 commit comments

Comments
 (0)