@@ -36,47 +36,46 @@ namespace microcode {
3636 }
3737 const tokens = lines [ i ] . split ( " " )
3838 if ( tokens . length == 0 || ! tokens [ 0 ] ) continue
39- console . log ( `tok1 = ${ tokens [ 0 ] } ` )
40- if ( tokens [ 0 ] == "Page" ) {
39+ let tok = tokens . shift ( )
40+ console . log ( `tok1 = ${ tok } ` )
41+ if ( tok == "Page" ) {
4142 if ( currPage ) {
4243 if ( currRule ) currPage . rules . push ( currRule )
4344 prog . pages . push ( currPage )
4445 currRule = undefined
4546 }
4647 currPage = new PageDefn ( )
4748 continue
48- } else if ( tokens [ 0 ] == "When" ) {
49+ } else if ( tok == "When" ) {
4950 control . assert ( currPage != undefined )
5051 if ( currRule ) currPage . rules . push ( currRule )
5152 currRule = undefined
52- tokens . shift ( )
53+ tok = tokens . shift ( )
5354 }
54- let tok = tokens . shift ( )
55- while ( tok ) {
55+ for ( ; tok ; tok = tokens . shift ( ) ) {
56+ console . log ( `tok2 = ${ tok } ` )
5657 if ( ! currRule ) {
5758 currRule = new RuleDefn ( )
58- currRule . sensors . push ( token2tile ( tokens [ 0 ] ) as number )
59- tokens . shift ( )
59+ // can we have When followed by Do?
60+ currRule . sensors . push ( token2tile ( tok ) as number )
61+ continue
6062 }
61- console . log ( `tok2 = ${ tok } ` )
62- if ( tok !== "Do" ) {
63- currTile = token2tile ( tok )
64- addTile ( currTile , currRule )
65- if ( currTile instanceof IconEditor ) {
66- console . log ( `got IconEditor` )
67- break
68- } else if ( currTile instanceof DigitEditor ) {
69- currTile . field = currTile . fieldEditor . fromString ( tok )
70- currTile = undefined
71- } else if ( currTile instanceof MelodyEditor ) {
72- currTile . field = currTile . fieldEditor . fromString (
73- tok + tokens . join ( " " )
74- )
75- currTile = undefined
76- break
77- }
63+ if ( tok == "Do" ) continue
64+ currTile = token2tile ( tok )
65+ addTile ( currTile , currRule )
66+ if ( currTile instanceof IconEditor ) {
67+ console . log ( `got IconEditor` )
68+ break
69+ } else if ( currTile instanceof DigitEditor ) {
70+ currTile . field = currTile . fieldEditor . fromString ( tok )
71+ currTile = undefined
72+ } else if ( currTile instanceof MelodyEditor ) {
73+ currTile . field = currTile . fieldEditor . fromString (
74+ tok + tokens . join ( " " )
75+ )
76+ currTile = undefined
77+ break
7878 }
79- tok = tokens . shift ( )
8079 }
8180 }
8281 if ( currRule ) currPage . rules . push ( currRule )
0 commit comments