-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.js
49 lines (43 loc) · 1.02 KB
/
simple.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*!
* limon <https://github.com/limonjs/limon>
*
* Copyright (c) 2016 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
/* eslint-disable */
'use strict'
var limon = require('../index')
limon
.use(function (app) {
return function (ch, i, input) {
if (/\s/.test(ch)) {
this.tokens.push(['whitespace', ch, i])
return
}
if (/\W/.test(ch)) {
this.tokens.push(['symbol', ch, i])
return
}
if (/\d/.test(ch)) {
this.tokens.push(['digit', ch, i])
return
}
this.tokens.push(['letter', ch, i])
}
})
var tokens = limon.tokenize('a > (b + 2)')
console.log(tokens)
// =>
// [
// [ 'letter', 'a', 0 ],
// [ 'whitespace', ' ', 1 ],
// [ 'symbol', '>', 2 ],
// [ 'whitespace', ' ', 3 ],
// [ 'symbol', '(', 4 ],
// [ 'letter', 'b', 5 ],
// [ 'whitespace', ' ', 6 ],
// [ 'symbol', '+', 7 ],
// [ 'whitespace', ' ', 8 ],
// [ 'digit', '2', 9 ],
// [ 'symbol', ')', 10 ]
// ]