0.0.2 • Published 2 years ago

nv-macro-simple-goto v0.0.2

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

nv-macro-simple-goto

  • nv-macro-simple-goto is a simple macro-tool, to let you use GOTO in javascript
  • cli tool
  • it has 7 keywords
  • ##goto_blk {...} mark as a goto-block
  • ##goto_is_from(label) prev-goto-entry-label
  • ##goto(label) goto the goto-entry-block-of-
  • ##goto_next() goto the next-goto-entry-block, if curr-goto-entry-block is last, sameas ##goto_end()
  • ##goto_prev() goto the prev-goto-entry-block, if curr-goto-entry-block is first,same as ##goto_end()
  • ##goto_fst() goto the first-goto-entry-block
  • ##goto_lst() goto the last-goto-entry-block
  • ##goto_end() end-and-exit nearest(parent)-goto-block

install

  • npm install nv-macro-simple-goto -g

usage

    Usage: nv_macro_sgoto [options]
    Options:
        -i, --input         input string ,default stdin
        -o, --output        output string,default stdout
        -h, --help          usage


        ......
            function tst(s) {
                ##goto_blk {
                    l0:{
                        console.log("l0")
                        if(##goto_is_from(l2)) {
                            ##goto_next();                        //goto l1 AND ##from === l0
                        } else {
                            ##goto(l2)                            //goto l2 AND ##from === l0
                        }
                    }
                    l1: {
                        console.log("l1")
                        ##goto(l3)                                 //goto l3 AND ##from === l1
                    }
                    l2: {
                        console.log("l2")
                        if(##goto_is_from(l3)) {
                            ##goto_next()                         //goto l3 AND ##from === l2
                        } else {
                            ##goto_fst()                          //goto l0 AND ##from === l2
                        }
                    }
                    l3: {
                        console.log("l3")
                        if(##goto_is_from(l1)) {
                            ##goto_prev();                     //goto l2 AND ##from === l3
                        } else {
                            ##goto_lst()                       //goto l4 AND ##from === l3
                        }
                    }
                    l4: {
                        console.log("l4");
                        ##goto_end()                           //stop goto
                    }
                }
            }
        .....

example

 nv_macro_sgoto -i  

input

    function tst(...args) {

        ##goto_blk {
            l0:{
                console.log("l0")
                if(##goto_is_from(l2)) {
                    ##goto_next();                        //goto l1 AND ##from === l0
                } else {
                    ##goto(l2)                            //goto l2 AND ##from === l0
                }
            }
            l1: {
                console.log("l1")
                ##goto(l3)                                 //goto l3 AND ##from === l1
            }
            l2: {
                console.log("l2")
                if(##goto_is_from(l3)) {
                    ##goto_next()                         //goto l3 AND ##from === l2
                } else {
                    ##goto_fst()                          //goto l0 AND ##from === l2
                }
            }
            l3: {
                console.log("l3")
                if(##goto_is_from(l1)) {
                    ##goto_prev();                     //goto l2 AND ##from === l3
                } else {
                    ##goto_lst()                       //goto l4 AND ##from === l3
                }
            }
            l4: {
                console.log("l4");
                ##goto_end()                           //stop goto
            }
        }
    }

press ctrl+D

  • the code will be compiled to:

output

    function tst(...args) {
      ___βgoto_blk: {
        const ___βpcs = ["l0", "l1", "l2", "l3", "l4"];
        let ___βgoto_is_from = -1;
        let ___βdiscriminant = 0;

        ___βgoto_while: while (true) {
          ___βgoto_switch: switch (___βdiscriminant) {
            case 0:
              {
                console.log("l0");

                if (___βgoto_is_from === 2) {
                  ___βdiscriminant = 1;
                  ___βgoto_is_from = 0;
                  break ___βgoto_switch;
                } else {
                  ___βdiscriminant = 2;
                  ___βgoto_is_from = 0;
                  break ___βgoto_switch;
                }
              }

            case 1:
              {
                console.log("l1");
                ___βdiscriminant = 3;
                ___βgoto_is_from = 1;
                break ___βgoto_switch;
              }

            case 2:
              {
                console.log("l2");

                if (___βgoto_is_from === 3) {
                  ___βdiscriminant = 3;
                  ___βgoto_is_from = 2;
                  break ___βgoto_switch;
                } else {
                  ___βdiscriminant = 0;
                  ___βgoto_is_from = 2;
                  break ___βgoto_switch;
                }
              }

            case 3:
              {
                console.log("l3");

                if (___βgoto_is_from === 1) {
                  ___βdiscriminant = 2;
                  ___βgoto_is_from = 3;
                  break ___βgoto_switch;
                } else {
                  ___βdiscriminant = 4;
                  ___βgoto_is_from = 3;
                  break ___βgoto_switch;
                }
              }

            case 4:
              {
                console.log("l4");
                ___βdiscriminant = -1;
                ___βgoto_is_from = 4;
                break ___βgoto_while;
              }

            default:
              {
                break ___βgoto_while;
              }
          }
        }
      }
    }

test

    /* l0->l2->l0->l1->l3->l2->l3->l4->eof 
    > tst()
    l0
    l2
    l0
    l1
    l3
    l2
    l3
    l4
    */

LICENSE

  • ISC