nv-lex-tok-wchar
- nv-lex-tok-wchar
- to match keywords char-by-char ,used in char-stream-parser(for stage-0 using)
- a simple version of nv-lex-kw
install
- npm install nv-lex-tok-wchar
usage
const {DFLT_CFG,STATES,ESC,parse_from_src} = require("nv-lex-tok-wchar")
example
from_str
var chunk = `
a"bcd" %%ef%% """gh"""i
\\"ABC
/*
jk
lm
*/ <!--rrrsssttt-->
##`
const {DFLT_CFG,STATES,ESC,parse_from_src} = require("nv-lex-tok-wchar")
/*
> ESC
'\\'
>
> DFLT_CFG
[
"'", '"', '`', '·', '“',
'”', '‘', '’', '%%', '//',
'/*', '*/', '{-', '-}', '(*',
'*)', '%(', '%)', '#|', '|#',
'#=', '=#', "'''", '"""', '```',
'···', '“““', '”””', '‘‘‘', '’’’',
'###', '<!--', '-->', '<%--', '--%>',
'--[[', '--]]'
]
>
*/
var r = parse_from_src(chunk,DFLT_CFG,ESC)
> r.toks
[
'\n',
'a',
[ '"' ],
'b',
'c',
'd',
[ '"' ],
' ',
[ '%', '%' ],
'e',
'f',
[ '%', '%' ],
' ',
[ '"', '"', '"' ],
'g',
'h',
[ '"', '"', '"' ],
'i',
'\n',
Esc { esc: '\\', raw: '"' },
'A',
'B',
'C',
'\n',
[ '/', '*' ],
'\n',
'j',
'k',
'\n',
'l',
'm',
'\n',
[ '*', '/' ],
' ',
' ',
[ '<', '!', '-', '-' ],
'r',
'r',
'r',
's',
's',
's',
't',
't',
't',
[ '-', '-', '>' ],
'\n'
]
>
> r.lefted
[ '#', '#' ]
>
> r.mach
LongestMach {
cfg_tree: Root [1 %ee357756:1% ] {},
esc: '\\',
curr: Wchar [79 %ee357756:79% ] { wchar: '#' },
state: 1
}
> STATES
{
'0': 'init',
'1': 'possible',
'2': 'match',
'3': 'esc',
init: 0,
possible: 1,
match: 2,
esc: 3
}
>
> r.mach.curr.wlist_
[ '#', '#' ]
>
> r.mach.lefted_
[ '#', '#' ]
>
> r.mach.reset()
/*
> r.mach
LongestMach {
cfg_tree: Root [1 %ee357756:1% ] {},
esc: '\\',
curr: Root [1 %ee357756:1% ] {},
state: 0
}
> r.mach.cfg_tree.show()
《match》 【 ' 】
《possible》 【 ' ' 】
《longest match》 【 ' ' ' 】
《match》 【 " 】
《possible》 【 " " 】
《longest match》 【 " " " 】
《match》 【 ` 】
《possible》 【 ` ` 】
《longest match》 【 ` ` ` 】
《match》 【 · 】
《possible》 【 · · 】
《longest match》 【 · · · 】
《match》 【 “ 】
《possible》 【 “ “ 】
《longest match》 【 “ “ “ 】
《match》 【 ” 】
《possible》 【 ” ” 】
《longest match》 【 ” ” ” 】
《match》 【 ‘ 】
《possible》 【 ‘ ‘ 】
《longest match》 【 ‘ ‘ ‘ 】
《match》 【 ’ 】
《possible》 【 ’ ’ 】
《longest match》 【 ’ ’ ’ 】
《possible》 【 % 】
《longest match》 【 % % 】
《longest match》 【 % ( 】
《longest match》 【 % ) 】
《possible》 【 / 】
《longest match》 【 / / 】
《longest match》 【 / * 】
《possible》 【 * 】
《longest match》 【 * / 】
《longest match》 【 * ) 】
《possible》 【 { 】
《longest match》 【 { - 】
《possible》 【 - 】
《longest match》 【 - } 】
《possible》 【 - - 】
《longest match》 【 - - > 】
《possible》 【 - - % 】
《longest match》 【 - - % > 】
《possible》 【 - - [ 】
《longest match》 【 - - [ [ 】
《possible》 【 - - ] 】
《longest match》 【 - - ] ] 】
《possible》 【 ( 】
《longest match》 【 ( * 】
《possible》 【 # 】
《longest match》 【 # | 】
《longest match》 【 # = 】
《possible》 【 # # 】
《longest match》 【 # # # 】
《possible》 【 | 】
《longest match》 【 | # 】
《possible》 【 = 】
《longest match》 【 = # 】
《possible》 【 < 】
《possible》 【 < ! 】
《possible》 【 < ! - 】
《longest match》 【 < ! - - 】
《possible》 【 < % 】
《possible》 【 < % - 】
《longest match》 【 < % - - 】
*/
from toks
const {parse} = require("nv-lex-tok-wchar");
var toks = ['Begin',' ','Object',' ','End',' ','Object']
var cfg = [
['Begin',' ', 'Object'],
['End',' ', 'Object']
]
> parse(toks,cfg)
{
mach: LongestMach {
cfg_tree: Root [1 %a81b0249:1% ] {},
esc: '\\',
curr: Root [1 %a81b0249:1% ] {},
state: 0
},
toks: [ [ 'Begin', ' ', 'Object' ], ' ', [ 'End', ' ', 'Object' ] ],
lefted: undefined
}
METHODS
cfg-tree
cfg_tree.add_chain
cfg_tree.append_wchar
cfg_tree.constructor
cfg_tree.get_child
cfg_tree.is_epsilon
cfg_tree.is_wchar
cfg_tree.match_branches_
cfg_tree.show
mach
mach.lefted_ mach.reset
mach.input
mach.cfg_tree
mach.curr
mach.state
mach.esc
APIS
{
DFLT_CFG: [
"'", '"', '`', '·', '“',
'”', '‘', '’', '%%', '//',
'/*', '*/', '{-', '-}', '(*',
'*)', '%(', '%)', '#|', '|#',
'#=', '=#', "'''", '"""', '```',
'···', '“““', '”””', '‘‘‘', '’’’',
'###', '<!--', '-->', '<%--', '--%>',
'--[[', '--]]'
],
creat_match_state_tree: [Function: creat_tree],
_mach: {
ESC: '\\',
STATES: {
'0': 'init',
'1': 'possible',
'2': 'match',
'3': 'esc',
init: 0,
possible: 1,
match: 2,
esc: 3
},
_Mach: [class _Mach],
LongestMach: [class LongestMach extends _Mach],
FirstMach: [class FirstMach extends _Mach],
_gen: [GeneratorFunction: _gen],
gen_using_longest_match: [Function: gen_using_longest_match],
gen_using_first_match: [Function: gen_using_first_match],
is_esc: [Function: is_esc]
},
parse: [Function: parse],
parse_from_src: [Function: parse_from_src],
parse_from_file: [Function: parse_from_file],
STATES: {
'0': 'init',
'1': 'possible',
'2': 'match',
'3': 'esc',
init: 0,
possible: 1,
match: 2,
esc: 3
},
ESC: '\\',
is_esc: [Function: is_esc]
}
LICENSE