1.0.1 • Published 3 years ago
nv-macro-ws v1.0.1
nv-macro-ws
- nv-macro-ws
- cli tool, unquote mixed-quoted string
install
- npm install nv-macro-ws -g
usage
Usage: nv_ws [options]
Options:
-i, --input input string ,default stdin
-o, --output output string,default stdout
-C, --CFG default config
-s, --str_with_quote output in str-with-quoteformat, default false
-a, --ary output in array-format, default false
-t, --tok output in tok-format, default false
-d, --indent_nonl enable indent
-h, --help usage
DEFAULT CFG
nv-macro-ws# node cli.js -C
{
qpairs: [
[ "'", "'" ], [ "'''", "'''" ],
[ '"', '"' ], [ '"""', '"""' ],
[ '`', '`' ], [ '%%', '%%' ],
[ '###', '###' ], [ '//', '\n' ],
[ '//', '�' ], [ '//', '�' ],
[ '/*', '*/' ], [ '<', '>' ],
[ '<!--', '-->' ], [ '{-', '-}' ],
[ '(*', '*)' ], [ '<%--', '--%>' ],
[ '%(', '%)' ], [ '#|', '|#' ],
[ '#=', '=#' ], [ '#if', '#endif' ],
[ '--[[', '--]]' ], [ '“', '”' ],
[ '‘', '’' ], [ '·', '·' ]
],
NL: [ '\n', '\r', '�', '�', '\r\n' ],
NONL: [
'\t', '\x0B', '\f', ' ',
' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ',
''
],
indent_nonl: false,
terminator: '',
esc: '\\'
}
example
//string-for-test:
`
a"bcd" %%ef%% """gh"""i
let a = 999;
/*
jk
lm
*/ #if nopq #endif <!--rrrsssttt-->
function tst(a,b) {
r = a+b;
return(r)
}
##
`
output str-with-quote
nv-macro-ws# node cli.js
a"bcd" %%ef%% """gh"""i
let a = 999;
/*
jk
lm
*/ #if nopq #endif <!--rrrsssttt-->
function tst(a,b) {
r = a+b;
return(r)
}
##
/////====>press ctrl+D
{
"toks": [
"a",
"\"bcd\"",
" ",
"%%ef%%",
" ",
"\"\"\"gh\"\"\"",
"i",
"\n",
" ",
"let",
" ",
"a",
" ",
"=",
" ",
"999;",
"\n",
"/*\njk\nlm\n*/",
" ",
"#if nopq #endif",
" ",
"<!--rrrsssttt-->",
"\n",
" ",
"function",
" ",
"tst(a,b)",
" ",
"{",
"\n",
" ",
"r",
" ",
"=",
" ",
"a+b;",
"\n",
" ",
"return(r)",
"\n",
" ",
"}",
"\n",
""
],
"lefted": [
[],
"##"
]
}
output array
- if array.length === 3 , its a quoted string left-q,str,right-q
- if array.length === 1 , it a raw string str OR newline@concated OR white-space@concated
nv-macro-ws# node cli.js -a
a"bcd" %%ef%% """gh"""i
let a = 999;
/*
jk
lm
*/ #if nopq #endif <!--rrrsssttt-->
function tst(a,b) {
r = a+b;
return(r)
}
##
/////====>press ctrl+D
{
"toks": [
[
"a"
],
[
"\"",
"bcd",
"\""
],
[
" "
],
[
"%%",
"ef",
"%%"
],
[
" "
],
[
"\"\"\"",
"gh",
"\"\"\""
],
[
"i"
],
[
"\n"
],
[
" "
],
[
"let"
],
[
" "
],
[
"a"
],
[
" "
],
[
"="
],
[
" "
],
[
"999;"
],
[
"\n"
],
[
"/*",
"\njk\nlm\n",
"*/"
],
[
" "
],
[
"#if",
" nopq ",
"#endif"
],
[
" "
],
[
"<!--",
"rrrsssttt",
"-->"
],
[
"\n"
],
[
" "
],
[
"function"
],
[
" "
],
[
"tst(a,b)"
],
[
" "
],
[
"{"
],
[
"\n"
],
[
" "
],
[
"r"
],
[
" "
],
[
"="
],
[
" "
],
[
"a+b;"
],
[
"\n"
],
[
" "
],
[
"return(r)"
],
[
"\n"
],
[
" "
],
[
"}"
],
[
"\n"
],
[
""
]
],
"lefted": [
[],
"##"
]
}
nv-macro-ws#
output toks
- if type === 10, it's a raw-string-tok
- if type === 12, it's a quote-but-treated-as raw-string-tok here ,(compare .q AND .lq/.rq)
- if type === 100, it's a quoted-string-tok (.lq,.rq,.q, .str; compare .q AND .lq/.rq will know if it's open OR close)
- if type === 102, it's a new-line
if type === 103, it's a white-space
nv-macro-ws# node cli.js -t a"bcd" %%ef%% """gh"""i let a = 999; /* jk lm */ #if nopq #endif <!--rrrsssttt--> function tst(a,b) { r = a+b; return(r) }
////===> press ctrl+D
{
"toks": [
{
"type": 10,
"raw": "a"
},
{
"type": 100,
"lq": "\"",
"rq": "\"",
"q": "\"",
"str": "bcd"
},
{
"type": 102,
"count": 1
},
{
"type": 100,
"lq": "%%",
"rq": "%%",
"q": "%%",
"str": "ef"
},
{
"type": 102,
"count": 1
},
{
"type": 100,
"lq": "\"\"\"",
"rq": "\"\"\"",
"q": "\"\"\"",
"str": "gh"
},
{
"type": 10,
"raw": "i"
},
{
"type": 103,
"count": 1
},
{
"type": 102,
"count": 4
},
{
"type": 10,
"raw": "let"
},
{
"type": 102,
"count": 1
},
{
"type": 10,
"raw": "a"
},
{
"type": 102,
"count": 1
},
{
"type": 10,
"raw": "="
},
{
"type": 102,
"count": 1
},
{
"type": 10,
"raw": "999;"
},
{
"type": 103,
"count": 1
},
{
"type": 100,
"lq": "/*",
"rq": "*/",
"q": "/*",
"str": "\njk\nlm\n"
},
{
"type": 102,
"count": 2
},
{
"type": 100,
"lq": "#if",
"rq": "#endif",
"q": "#if",
"str": " nopq "
},
{
"type": 102,
"count": 2
},
{
"type": 100,
"lq": "<!--",
"rq": "-->",
"q": "<!--",
"str": "rrrsssttt"
},
{
"type": 103,
"count": 1
},
{
"type": 102,
"count": 4
},
{
"type": 10,
"raw": "function"
},
{
"type": 102,
"count": 1
},
{
"type": 10,
"raw": "tst(a,b)"
},
{
"type": 102,
"count": 1
},
{
"type": 10,
"raw": "{"
},
{
"type": 103,
"count": 1
},
{
"type": 102,
"count": 8
},
{
"type": 10,
"raw": "r"
},
{
"type": 102,
"count": 1
},
{
"type": 10,
"raw": "="
},
{
"type": 102,
"count": 1
},
{
"type": 10,
"raw": "a+b;"
},
{
"type": 103,
"count": 1
},
{
"type": 102,
"count": 8
},
{
"type": 10,
"raw": "return(r)"
},
{
"type": 103,
"count": 1
},
{
"type": 102,
"count": 4
},
{
"type": 10,
"raw": "}"
},
{
"type": 103,
"count": 1
},
{
"type": 10,
"raw": ""
}
],
"lefted": [
[],
"##"
]
}
LICENSE
- ISC
1.0.1
3 years ago