1.0.3 • Published 2 years ago

nv-cli-state v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

nv-cli-state

  • cli-tool
  • creat some code templates for state-machine

input example

    #input_kinds_count  
    
    :async 255 
    
    #state                              
    
    //used defined state can NOT  be error OR finish,  these two are handle names
    
    idle           connect  active 
    open_sent      open_confirm
    established
    
    
    
    #error
    
    // used defined state can NOT  be error OR finish, error is fixed-dflt-error-handle-name, finish is fixed-action-handle-name
    
    layer3_error
    error_a
    error_b
    error_c
    
    #transfer
    
    
    idle         ->            *                    -> connect
    
    connect      -> (30 35] (40 45) [50 55) [60 65] ->         established
    connect      -> 129 130 131                     -> :async  active_further_handle
    connect      ->  [150 160]                      -> :async  error_a
    connect      ->  170                            ->         other_further_handle
    connect      ->  ...                            ->         ~~error
    
    active       -> 100 101 102 103                 ->         open_sent
    active       -> 114 115 116 117                 ->         connect
    active       -> ...                             ->         error_c
    
    open_sent    -> 99                              -> :async  open_confirm_further_handle
    open_sent    -> 140 141 142                     ->         layer3_error
    open_sent    -> ...                             ->         error_b
    
    open_confirm -> [180 190]                       ->         established
    open_confirm -> ...                             -> :async  error_c
    
    established  -> 0                               ->         ~~finish
    established  -> 1                               -> :async  ~~finish
    established  -> ...                             -> :async  ~~error
    
    
    #end

input syntax

     5 keywords , all begin with "#"

           #input_kinds_count
           #state
           #error
           #transfer
           #end

     2 modifier ,  all beign with ":"

           :async 
           :sync         // this is default can be omitted

     2 built-in names.  all begin with "~~"

           ~~error      
           ~~finish   


     2 place-holders  :

           *  AND ...

     4 block-operators :

           [           // included  >= 
           ]           // included  <=
           (           // excluded  >=
           )           // excluded  <=

     1 literal-type :
           
           int
    
     1 seperator-operator:
         
           ->


      others ALL names:
           
           must be a valid JS var-name, can NOT be :
                 input_kinds_count   | state | error | transfer | end | finish | async | sync
                             
      //     <modi>  :sync | : async


       #input_kinds_count
            modi?  <int>
            
       #state
            <name>  <name> <name> ...


       #error   
           //modi? word   |  modi? word  | modi? word .....



            /*
                 #error
                            layer3_error             //:sync is default
                     :async error_a
                            error_b
                     :async error_c
            */



           #transfer
              <SRC>      ->       <INTS>              ->               <DST>
              <SRC>      ->       <INTS>              ->               <DST>
                              .....
                              
                              
                              
                              
              // <SRC>  
              //    MUST be a-name-defined-in<#state>                                                            AND 
              //    can NOT be  error | finish                                                                   AND
              //    can NOT be  sync | async | error | state | transfer | input_kinds_count | end                AND
              //    MUST be  a-valid-js-var-name
              
              
              // <INTS>   
              //     (30 35]  means    31 32 33 34 35
                              //     [30 35]  means 30 31 32 33 34 35
                              //     (30 35)  means    31 32 33 34 
                              //     [30 35)  means 30 31 32 33 34
                              //     [1,3] 8 [9,10]  means  1 2 3  8 9 10
                              //      *       means    ALL
                              //     ...      means    Rest(this will be calculated at next pass)
                              //     [*,*]    means    *
                              //     [*,*)    means    [min, max)
                              //     [*]      means    max
                              //     (*]      means    nothinf 
                              //     (1)      means    nothing
                              //     [1]      means    1
                              //     (1 *)    means    (1,max)
                              //     (* 5]    means    (min, 5]

                              
              
              // <DST>  could be 
              //    a-name-defined-in<#state>                                                    OR  
              //    a-error-handle-defined-in<(:sync|:async)?#error>                             OR 
              //    a-builtin-name-of<(:sync|:async)?(~~error | ~~finish)>                       OR
              //    a-action-name-of<(:sync|:async)?<your-name>>-defined-here
              //         <your-name> can NOT be  error | finish | defined-state-in<#state>                            AND
              //         <your-name> can NOT be  sync | async | error | state | transfer | input_kinds_count | end    AND
              //         <your-name> MUST be  a-valid-js-var-name 


          /* 
           #transfer
              // <SRC>             <INTS>                             <DST>
                idle    ->            *                    ->         connect           
                connect -> (30 35] (40 45) [50 55) [60 65] ->         established
                connect -> 129 130 131                     -> :async  active
                connect ->  [150 160]                      ->         error_a                  // error modifier could be omitted ,because it could be def in #error
                connect ->  170                            ->         other0
                connect ->  ...                            ->         ~~error                  // ~~error IS "built-in"  name       ~~error OR :sync ~~error OR  :async ~~error

                active  -> 100 101 102 103                 ->         open_sent
                active  -> 114 115 116 117                 ->         connect
                active  -> ...                             ->         error_c

                open_send  -> 99                           -> :async  open_confirm
                open_send  -> 140 141 142                  ->         layer3_error
                open_send  -> ...                          ->         error_b

                open_confirm -> [180 190]                  ->         established
                open_confirm -> ...                        -> :async  error_c                 // you can also  redefine error modifer(:async) here , it will overwrite the previous def     

                established -> 0                           ->         ~~finish                // ~~finish IS "built-in"  name        ~~finish OR :sync ~~finish OR  :async ~~finish
                established -> 1                           -> :async  ~~finish
                established -> ...                         -> :async  ~~error

           */

install

  • npm install nv-cli-state -g

usage

		Usage: nv_cli_state [options] 
		Options:
		    -o, --output         output string,default stdout
		    -i, --input          input string,default stdin
		    -w, --workdir        empty workdir, must exist AND empty, default "./" 
		    -h, --help           usage

example

      #mkdir  WORKCTX
      #cd     WORKCTX
      #nv_cli_state -i tst.state
		check node_modules AND install dependancies IF missing....
		file input-hash.js template created, total  255
		file state-def.js template created: total  6 the first is active : 1 the last is open_sent : 6
		{
		  '1': 'active',
		  '2': 'connect',
		  '3': 'established',
		  '4': 'idle',
		  '5': 'open_confirm',
		  '6': 'open_sent',
		  active: 1,
		  connect: 2,
		  established: 3,
		  idle: 4,
		  open_confirm: 5,
		  open_sent: 6
		}
		file err-handle.js template created: total  5 the first is error_a : -1 the last is error : -5
		{
		  error_a: -1,
		  '-1': 'error_a',
		  error_b: -2,
		  '-2': 'error_b',
		  error_c: -3,
		  '-3': 'error_c',
		  layer3_error: -4,
		  '-4': 'layer3_error',
		  error: -5,
		  '-5': 'error'
		}
		file action-handle.js template created: total  3 the first is active_further_handle : 7 the last is open_confirm_further_handle : 9
		{
		  '7': 'active_further_handle',
		  '8': 'finish',
		  '9': 'open_confirm_further_handle',
		  active_further_handle: 7,
		  finish: 8,
		  open_confirm_further_handle: 9
		}
		stack.js created
		transfer-mat.js created
		index.js created

     # ls -l 

					total 116
					-rw-r--r-- 1 root root  1104 Jun 24 16:40 action-handle.js
					-rw-r--r-- 1 root root  1385 Jun 24 16:40 err-handle.js
					-rw-r--r-- 1 root root  1467 Jun 24 16:40 index.js
					-rw-r--r-- 1 root root 45056 Jun 24 16:40 input-hash.js          // delete the unsed branch is ok, most is empty code
					-rw-r--r-- 1 root root   488 Jun 24 16:40 stack.js
					-rw-r--r-- 1 root root   551 Jun 24 16:40 state-def.js
					-rw-r--r-- 1 root root 50289 Jun 24 16:40 transfer-mat.js        // delete the unsed branch is ok, most is empty code

LICENSE

  • ISC