1.0.2 • Published 3 years ago

nv-macro-lexblk v1.0.2

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

nv-macro-lexblk

  • nv-macro-lexblk is a simple macro-tool, only two syntax
  • cli tool
  • use a simple syntax ##lexblk <blkname> <......> to define block in your script
  • use ##<blkname>() to insert it
  • lex block is always treated as "global defined" when compile
  • its slow, so only suited for pre-compile using

install

  • npm install nv-macro-lexblk -g

usage

    nv-macro-lexblk# node cli.js -h
    Usage: nv_lexblk [options]
    Options:
        -i, --input             input string ,default stdin
        -o, --output            output string,default stdout
        -c, --compile           compile the macro
        -m, --macro_name        `##${macro_name}` used in script,default is lexblk
        -h, --help              usage

    nv-macro-lexblk#
    nv-macro-lexblk#
    nv-macro-lexblk# node cli.js -M
        the default macro_name:  lexblk
        use it begin with two #:  ##lexblk(...)
    nv-macro-lexblk#
    nv-macro-lexblk#
    nv-macro-lexblk# node cli.js -S

        ......
            //define
            ##lexblk myfor for(let i=0;i<3;i++) { x= x+i}
            //use
            function tst1() {
                let x =1;
                ##myfor();
                return(x)
            }
        .....

example

    % nv_lexblk -c 

    ////the source code

    ////define blocks

    ##lexblk myfor for(let i=0;i<3;i++) {
        x = x +i
    }


    ##lexblk yourfor for(j=1;j<3;j++) {
        x = x *j
    }



    function tst1() {
        let x =1;
        ##myfor();                   //---use block
        ##yourfor();                 //---use block
        return(x)
    }
    function tst2() {
        let x =1;
        ##yourfor();                 //---use block
        ##myfor();                   //---use block
        return(x)
    }

    //-----PRESS  ctrl+D

    function tst1() {
      let x = 1;

      for (let i = 0; i < 3; i++) {
        x = x + i;
      }

      for (j = 1; j < 3; j++) {
        x = x * j;
      }

      return x;
    }

    function tst2() {
      let x = 1;

      for (j = 1; j < 3; j++) {
        x = x * j;
      }

      for (let i = 0; i < 3; i++) {
        x = x + i;
      }

      return x;
    }

LICENSE

  • ISC