/
Stameskaaa
/
Server
Обзор
Документация
Войти
/
Stameskaaa
/
Server
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
node_modules/tokenizer/examples/json.js
38 строк
980 B
Stameskaaa
first
19 июн 2024, 15:02
19 июн 2024, 15:02
ac1472e
Код
Авторство
О чём код?
var Tokenizer = require('../lib/Tokenizer'); var t = new Tokenizer(); t.on('token', function(token, type) { console.log('%s(%s)', token, type); }); t.addRule(/^"([^"]|\\")*"$/, 'string'); t.addRule(/^"([^"]|\\")*$/, 'maybe-string'); // same as above without the ending " t.addRule(/^\d+(\.\d+)?$/, 'number'); t.addRule(/^\d+\.$/, 'maybe-float'); t.addRule(/^(true|false)$/, 'bool'); t.addRule(/^null$/, 'null'); t.addRule(/^\{$/, 'begin-object'); t.addRule(/^\}$/, 'end-object'); t.addRule(/^\[$/, 'begin-array'); t.addRule(/^\]$/, 'end-array'); t.addRule(/^:$/, 'end-label'); t.addRule(/^,$/, 'comma'); t.addRule(/^\w+$/, "symbol"); t.addRule(/^(\s)+$/, 'whitespace'); var o = { coucou: 'salut', complicated: "haha 안녕,; :! {fdf} ' \' \" ", nombre: 8, bool: false, gn: null, oo: { a: [ 'coucou', 888.3, false ] } } var str = JSON.stringify(o); console.log('parsing %s', str); t.write(str);