@@ -14,11 +14,15 @@ function isSymbol(ch: string) {
1414 return ch == ';' || ch == ':' || ch == '{' || ch == '}' || ch == ',' ;
1515}
1616
17+ function isSpace ( ch : string ) {
18+ return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' ;
19+ }
20+
1721const stateMachine : StateMachine = {
1822 ';' : {
1923 next ( ch ) {
2024 if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch }
21- if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { skipEmit : true }
25+ if ( isSpace ( ch ) ) return { skipEmit : true }
2226 if ( ch == '/' ) return { state : ';/' , skipEmit : true }
2327 if ( isSymbol ( ch ) ) return ;
2428 return { state : 'x' }
@@ -30,7 +34,7 @@ const stateMachine: StateMachine = {
3034 ';$' : { // after placeholder
3135 next ( ch ) {
3236 if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch }
33- if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { skipEmit : true , state : ' ' } // we may need a space
37+ if ( isSpace ( ch ) ) return { skipEmit : true , state : ' ' } // we may need a space
3438 if ( ch == '/' ) return { state : '/' , skipEmit : true }
3539 if ( isSymbol ( ch ) ) return { state : ';' } ;
3640 return { state : 'x' }
@@ -39,15 +43,15 @@ const stateMachine: StateMachine = {
3943 'x' : {
4044 next ( ch ) {
4145 if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch }
42- if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { state : ' ' , skipEmit : true }
46+ if ( isSpace ( ch ) ) return { state : ' ' , skipEmit : true }
4347 if ( ch == '/' ) return { state : '/' , skipEmit : true }
4448 if ( isSymbol ( ch ) ) return { state : ';' } ;
4549 }
4650 } ,
4751 ' ' : { // may need space
4852 next ( ch ) {
4953 if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch , emit : ' ' + ch }
50- if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { state : ' ' , skipEmit : true }
54+ if ( isSpace ( ch ) ) return { state : ' ' , skipEmit : true }
5155 if ( ch == '/' ) return { state : '/' , skipEmit : true }
5256 if ( isSymbol ( ch ) ) return { state : ';' } ;
5357 return { state : 'x' , emit : ' ' + ch } ;
@@ -59,7 +63,7 @@ const stateMachine: StateMachine = {
5963 '\n' : { // may need new line
6064 next ( ch ) {
6165 if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch , emit : '\n' + ch }
62- if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { state : '\n' , skipEmit : true }
66+ if ( isSpace ( ch ) ) return { state : '\n' , skipEmit : true }
6367 if ( ch == '/' ) return { state : '/' , emit : '\n' }
6468 if ( isSymbol ( ch ) ) return { state : ';' , emit : '\n' + ch } ;
6569 return { state : 'x' , emit : '\n' + ch } ;
0 commit comments