@@ -13,8 +13,10 @@ namespace microcode {
1313 if ( tile instanceof ModifierEditor ) {
1414 const mod = tile as ModifierEditor
1515 const field = mod . fieldEditor . toString ( mod . getField ( ) )
16- if ( mod instanceof IconEditor ) return `${ tok } \n${ field } `
17- if ( mod instanceof MelodyEditor ) return `${ tok } ${ field } \n`
16+ if ( mod instanceof IconEditor )
17+ return `${ tok } \`\n${ field } \`\n`
18+ if ( mod instanceof MelodyEditor )
19+ return `${ tok } \`${ field } \`\n`
1820 else return `${ tok } ${ field } `
1921 }
2022 return tok
@@ -55,19 +57,20 @@ namespace microcode {
5557 return tid
5658 }
5759 }
58- const addTile = ( tile : Tile , rule : RuleDefn ) => {
60+ const addTile = ( rule : RuleDefn , tile : Tile ) => {
5961 control . assert ( rule != undefined , `No Rule definition` )
6062 const tid = getTid ( tile )
6163 if ( isSensor ( tid ) ) rule . push ( tile , "sensors" , false )
6264 if ( isFilter ( tid ) ) rule . push ( tile , "filters" , false )
6365 else if ( isModifier ( tid ) ) rule . push ( tile , "modifiers" , false )
6466 else rule . push ( tile , "actuators" , false )
6567 }
68+ // tokenizer
6669 let cursor = 0
67- const whiteSpace = ( s : string ) => {
68- return s == " " || s == "\n" || s == "\t"
69- }
7070 const getToken = ( ) => {
71+ const whiteSpace = ( s : string ) => {
72+ return s == " " || s == "\n" || s == "\t"
73+ }
7174 let prev = cursor
7275 let gotToken = false
7376 while ( cursor < str . length ) {
@@ -95,26 +98,25 @@ namespace microcode {
9598 let currTile : Tile = undefined
9699 let tok : string = undefined
97100 while ( ( tok = getToken ( ) ) ) {
98- // console.log(`tok1 = ${tok}`)
99- if ( currTile ) {
101+ // console.log(`tok = ${tok}`)
102+ if ( currTile && currTile instanceof ModifierEditor ) {
100103 if (
101104 currTile instanceof IconEditor ||
102105 currTile instanceof MelodyEditor
103106 ) {
104107 const thisTile = currTile as ModifierEditor
105108 control . assert ( tok == "`" , `expected \`, got ${ tok } ` )
106109 let tokens = [ ]
107- while ( ( tok = getToken ( ) ) == "." || tok == "1 ") {
110+ while ( ( tok = getToken ( ) ) != "` ") {
108111 tokens . push ( tok )
109112 }
110- control . assert (
111- tok == "`" ,
112- `expected {0, 1, \`}, got ${ tok } `
113- )
113+ //console.log(`got tokens = ${tokens.join(":")}`)
114+ control . assert ( tok == "`" , `expected \`, got ${ tok } ` )
114115 currTile . field = thisTile . fieldEditor . fromTokens ( tokens )
115116 } else if ( currTile instanceof DigitEditor ) {
116117 currTile . field = currTile . fieldEditor . fromTokens ( [ tok ] )
117118 }
119+ currTile = undefined
118120 continue
119121 }
120122 currTile = undefined
@@ -126,7 +128,6 @@ namespace microcode {
126128 }
127129 currPage = new PageDefn ( )
128130 getToken ( ) // consume page #
129- continue
130131 } else if ( tok == "When" ) {
131132 control . assert ( currPage != undefined , `No Page defined` )
132133 if ( currRule ) currPage . rules . push ( currRule )
@@ -135,7 +136,7 @@ namespace microcode {
135136 control . assert ( currRule != undefined , `No When defined` )
136137 } else {
137138 currTile = token2tile ( tok )
138- addTile ( currTile , currRule )
139+ addTile ( currRule , currTile )
139140 }
140141 }
141142 if ( currRule ) currPage . rules . push ( currRule )
0 commit comments