nv-lex-tok-escape
- nv-lex-tok-escape handle escape in quoted-src-string
- auto recover of invalid \x \u \o
- its a simple version of nv-char-escape
install
- npm install nv-lex-tok-escape
usage
const {parse,parse_from_src} = require("nv-lex-tok-escape");
example
from_str
//content-of-quoted-source
var src = `b\\v@\\u0000@\\u0001\\u0002@\\\\@\\x00@\\x00\\x01@\\0\\01\\123@\\A@\\A\\B`
parse_from_src(src)
> parse_from_src(src)
[
'b', '\x0B', '@', '\x00',
'@', '\x01', '\x02', '@',
'\\', '@', '\x00', '@',
'\x00', '\x01', '@', '\x00',
'\x01', 'S', '@', 'A',
'@', 'A', 'B'
]
> '\123'
'S'
>
from toks
const lex_wchar = require("nv-lex-tok-wchar");
var r = lex_wchar.parse_from_src(src);
var toks = r.toks ;
> parse(toks)
[
'b', '\x0B', '@', '\x00',
'@', '\x01', '\x02', '@',
'\\', '@', '\x00', '@',
'\x00', '\x01', '@', '\x00',
'\x01', 'S', '@', 'A',
'@', 'A', 'B'
]
>
METHODS
Mach
mach.input(tok)
mach.lefted_
mach.cache
mach.state
Esc
esc.is_escc
esc.maybe_o
esc.maybe_u
esc.maybe_x
esc.should_eat
esc.stringify
esc.esc
esc.raw
APIS
{
consts: {
CHAR_UNESC_DICT: { b: '\b', f: '\f', n: '\n', r: '\r', t: '\t', v: '\x0B' },
CHAR_UNESC_MD: {
'\b': 'b',
'\f': 'f',
'\n': 'n',
'\r': 'r',
'\t': 't',
'\x0B': 'v'
},
CHAR_ESC_DICT: {
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\x0B': '\\v',
'\\': '\\\\'
},
ESC_EAT: { '\n': '', '\r': '', '�': '', '�': '' }
},
cmmn: {
Esc: [class Esc],
unescx: [Function: unescx],
unescu: [Function: unescu],
unesco: [Function: unesco]
},
_mach: {
STATES: {
'0': 'init',
'1': 'x',
'2': 'o',
'3': 'u',
init: 0,
x: 1,
o: 2,
u: 3
},
Mach: [class Mach],
gen: [GeneratorFunction: gen]
},
Mach: [class Mach],
parse: [Function: parse],
parse_from_src: [Function: parse_from_src]
}
LICENSE