File tree Expand file tree Collapse file tree 5 files changed +72
-68
lines changed
Filter options
Expand file tree Collapse file tree 5 files changed +72
-68
lines changed
Original file line number Diff line number Diff line change @@ -13,21 +13,21 @@ let state = STATE_INIT;
13
13
for await ( const chunk of process . stdin ) {
14
14
console . log ( { chunk } ) ;
15
15
switch ( state ) {
16
- case STATE_INIT :
17
- console . log ( 'initialization' ) ;
18
- state = STATE_WORK ;
19
- break ;
20
- case STATE_WORK :
21
- console . log ( 'working' ) ;
22
- state = STATE_FIN ;
23
- break ;
24
- case STATE_FIN :
25
- console . log ( 'finalization' ) ;
26
- state = STATE_EXIT ;
27
- break ;
28
- case STATE_EXIT :
29
- console . log ( 'exit' ) ;
30
- process . exit ( 0 ) ;
16
+ case STATE_INIT :
17
+ console . log ( 'initialization' ) ;
18
+ state = STATE_WORK ;
19
+ break ;
20
+ case STATE_WORK :
21
+ console . log ( 'working' ) ;
22
+ state = STATE_FIN ;
23
+ break ;
24
+ case STATE_FIN :
25
+ console . log ( 'finalization' ) ;
26
+ state = STATE_EXIT ;
27
+ break ;
28
+ case STATE_EXIT :
29
+ console . log ( 'exit' ) ;
30
+ process . exit ( 0 ) ;
31
31
}
32
32
}
33
33
} ) ( ) ;
Original file line number Diff line number Diff line change @@ -9,25 +9,27 @@ const STATE_EXIT = 3;
9
9
10
10
let state = STATE_INIT ;
11
11
12
- process . on ( 'SIGINT' , ( ) => state = STATE_FIN ) ;
12
+ process . on ( 'SIGINT' , ( ) => {
13
+ state = STATE_FIN ;
14
+ } ) ;
13
15
14
16
const timer = setInterval ( step , TIME_STEP ) ;
15
17
16
18
function step ( ) {
17
19
switch ( state ) {
18
- case STATE_INIT :
19
- console . log ( 'initialization' ) ;
20
- state = STATE_WORK ;
21
- break ;
22
- case STATE_WORK :
23
- process . stdout . write ( '.' ) ;
24
- break ;
25
- case STATE_FIN :
26
- console . log ( '\nfinalization' ) ;
27
- state = STATE_EXIT ;
28
- break ;
29
- case STATE_EXIT :
30
- console . log ( 'exit' ) ;
31
- clearInterval ( timer ) ;
20
+ case STATE_INIT :
21
+ console . log ( 'initialization' ) ;
22
+ state = STATE_WORK ;
23
+ break ;
24
+ case STATE_WORK :
25
+ process . stdout . write ( '.' ) ;
26
+ break ;
27
+ case STATE_FIN :
28
+ console . log ( '\nfinalization' ) ;
29
+ state = STATE_EXIT ;
30
+ break ;
31
+ case STATE_EXIT :
32
+ console . log ( 'exit' ) ;
33
+ clearInterval ( timer ) ;
32
34
}
33
35
}
Original file line number Diff line number Diff line change @@ -7,20 +7,20 @@ class StateMachine {
7
7
this . state = StateMachine . STATE . INIT ;
8
8
this . timer = setInterval ( ( ) => {
9
9
switch ( this . state ) {
10
- case StateMachine . STATE . INIT :
11
- console . log ( 'initialization' ) ;
12
- this . state = StateMachine . STATE . WORK ;
13
- break ;
14
- case StateMachine . STATE . WORK :
15
- process . stdout . write ( '.' ) ;
16
- break ;
17
- case StateMachine . STATE . FIN :
18
- console . log ( '\nfinalization' ) ;
19
- this . state = StateMachine . STATE . EXIT ;
20
- break ;
21
- case StateMachine . STATE . EXIT :
22
- console . log ( 'exit' ) ;
23
- clearInterval ( this . timer ) ;
10
+ case StateMachine . STATE . INIT :
11
+ console . log ( 'initialization' ) ;
12
+ this . state = StateMachine . STATE . WORK ;
13
+ break ;
14
+ case StateMachine . STATE . WORK :
15
+ process . stdout . write ( '.' ) ;
16
+ break ;
17
+ case StateMachine . STATE . FIN :
18
+ console . log ( '\nfinalization' ) ;
19
+ this . state = StateMachine . STATE . EXIT ;
20
+ break ;
21
+ case StateMachine . STATE . EXIT :
22
+ console . log ( 'exit' ) ;
23
+ clearInterval ( this . timer ) ;
24
24
}
25
25
} , TIME_STEP ) ;
26
26
}
Original file line number Diff line number Diff line change @@ -9,31 +9,31 @@ class ArrayLiteralParser {
9
9
10
10
feed ( char ) {
11
11
switch ( this . state ) {
12
- case 'end' :
13
- throw new Error ( `Unexpected character after array end: ${ char } ` ) ;
14
- case 'start' :
15
- if ( char !== '[' ) {
16
- throw new Error ( `Unexpected character before array: ${ char } ` ) ;
17
- }
18
- this . array = [ ] ;
19
- this . state = 'value' ;
20
- break ;
21
- case 'value' :
22
- if ( char === ',' || char === ']' ) {
23
- const { value } = this ;
24
- this . value = '' ;
25
- const item = parseFloat ( value ) ;
26
- if ( Number . isNaN ( item ) ) {
27
- throw new Error ( `Can not parse value: ${ value } ` ) ;
12
+ case 'end' :
13
+ throw new Error ( `Unexpected character after array end: ${ char } ` ) ;
14
+ case 'start' :
15
+ if ( char !== '[' ) {
16
+ throw new Error ( `Unexpected character before array: ${ char } ` ) ;
28
17
}
29
- this . array . push ( item ) ;
30
- if ( char === ']' ) this . state = 'end ' ;
18
+ this . array = [ ] ;
19
+ this . state = 'value ' ;
31
20
break ;
32
- }
33
- if ( ! ( ' .-0123456789' ) . includes ( char ) ) {
34
- throw new Error ( `Unexpected character in value: ${ char } ` ) ;
35
- }
36
- this . value += char ;
21
+ case 'value' :
22
+ if ( char === ',' || char === ']' ) {
23
+ const { value } = this ;
24
+ this . value = '' ;
25
+ const item = parseFloat ( value ) ;
26
+ if ( Number . isNaN ( item ) ) {
27
+ throw new Error ( `Can not parse value: ${ value } ` ) ;
28
+ }
29
+ this . array . push ( item ) ;
30
+ if ( char === ']' ) this . state = 'end' ;
31
+ break ;
32
+ }
33
+ if ( ! ' .-0123456789' . includes ( char ) ) {
34
+ throw new Error ( `Unexpected character in value: ${ char } ` ) ;
35
+ }
36
+ this . value += char ;
37
37
}
38
38
}
39
39
Original file line number Diff line number Diff line change @@ -36,7 +36,9 @@ const parser = new ArrayLiteralParser({
36
36
'' : 'Unexpected character before array' ,
37
37
} ,
38
38
value : {
39
- ' .-0123456789' : ( target , char ) => target . value += char ,
39
+ ' .-0123456789' : ( target , char ) => {
40
+ target . value += char ;
41
+ } ,
40
42
',]' : ( target , char ) => {
41
43
const value = parseFloat ( target . value ) ;
42
44
target . result . push ( value ) ;
You can’t perform that action at this time.
0 commit comments