1.0.1 • Published 4 years ago

nvlex-kw v1.0.1

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

nvlex-kw

  • nvlex-kw
  • to match keywords char-by-char ,used in char-stream-parser

install

  • npm install nvlex-kw

usage

const Keywords = require("nvlex-kw");

example

char-by-char

/*
Keywords.type
{ nomatch: 0, possible: 1, match: 2 }
*/
var keywords = new Keywords(['abc','ab','defg'])
/*
> keywords.ls()
d
de
def
defg <longest match>
a
ab <match>
abc <longest match>
>
*/
keywords.next('a')
/*

{ match: false, type: 1 }
Keywords.type.possible === 1
> keywords.curr
a
ab <match>
abc <longest match>
>
*/
keywords.next('b',false)
/*
{ match: true, type: 2 }
>
*/

keywords.prev()              //back for one
keywords.next('b',true)
/*
> keywords.next('b',true)
{ match: true, type: 2 }
>
*/

> keywords.next('a')
{ match: false, type: 1 }
> keywords.next('b')
{ match: false, type: 1 }
> keywords.next('c')
{ match: true, type: 2 }
>

> keywords.next('d')
{ match: false, type: 1 }
> keywords.next('e')
{ match: false, type: 1 }
> keywords.next('f')
{ match: false, type: 1 }
> keywords.next('g')
{ match: true, type: 2 }
>


> var keywords = new Keywords(['"','""','"""',"'","''","'''",'`'])
undefined
>
> keywords.next('"')
{ match: false, type: 1 }
> keywords.next('"')
{ match: false, type: 1 }
> keywords.next('"')
{ match: true, type: 2, rslt: '"""' }
>
>

whole match

> keywords.match("x")
{ match: false, type: 0 }
>
> keywords.match("a")
{ match: false, type: 1, possible: [ 'abc', 'ab' ] }
>
> keywords.match("ab")
{ match: true, type: 2 }
>
> keywords.match("abc")
{ match: true, type: 2 }
>
> keywords.match("d")
{ match: false, type: 1, possible: [ 'defg' ] }
>
> keywords.match("de")
{ match: false, type: 1, possible: [ 'defg' ] }
> keywords.match("def")
{ match: false, type: 1, possible: [ 'defg' ] }
>
> keywords.match("defg")
{ match: true, type: 2 }
>

LICENSE

  • ISC
1.0.1

4 years ago

1.0.0

4 years ago