@@ -14,11 +14,15 @@ function isSymbol(ch: string) {
14
14
return ch == ';' || ch == ':' || ch == '{' || ch == '}' || ch == ',' ;
15
15
}
16
16
17
+ function isSpace ( ch : string ) {
18
+ return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' ;
19
+ }
20
+
17
21
const stateMachine : StateMachine = {
18
22
';' : {
19
23
next ( ch ) {
20
24
if ( ch == '\'' || ch == '"' || ch == '(' ) return { state : ch }
21
- if ( ch == ' ' || ch == '\n' || ch == '\r' ) return { skipEmit : true }
25
+ if ( isSpace ( ch ) ) return { skipEmit : true }
22
26
if ( ch == '/' ) return { state : ';/' , skipEmit : true }
23
27
if ( isSymbol ( ch ) ) return ;
24
28
return { state : 'x' }
@@ -30,7 +34,7 @@ const stateMachine: StateMachine = {
30
34
';$' : { // after placeholder
31
35
next ( ch ) {
32
36
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
34
38
if ( ch == '/' ) return { state : '/' , skipEmit : true }
35
39
if ( isSymbol ( ch ) ) return { state : ';' } ;
36
40
return { state : 'x' }
@@ -39,15 +43,15 @@ const stateMachine: StateMachine = {
39
43
'x' : {
40
44
next ( ch ) {
41
45
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 }
43
47
if ( ch == '/' ) return { state : '/' , skipEmit : true }
44
48
if ( isSymbol ( ch ) ) return { state : ';' } ;
45
49
}
46
50
} ,
47
51
' ' : { // may need space
48
52
next ( ch ) {
49
53
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 }
51
55
if ( ch == '/' ) return { state : '/' , skipEmit : true }
52
56
if ( isSymbol ( ch ) ) return { state : ';' } ;
53
57
return { state : 'x' , emit : ' ' + ch } ;
@@ -59,7 +63,7 @@ const stateMachine: StateMachine = {
59
63
'\n' : { // may need new line
60
64
next ( ch ) {
61
65
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 }
63
67
if ( ch == '/' ) return { state : '/' , emit : '\n' }
64
68
if ( isSymbol ( ch ) ) return { state : ';' , emit : '\n' + ch } ;
65
69
return { state : 'x' , emit : '\n' + ch } ;
0 commit comments