forked from zaach/jsonlint
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathparse.js
More file actions
166 lines (138 loc) · 4.52 KB
/
parse.js
File metadata and controls
166 lines (138 loc) · 4.52 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const createSuite = require('./common/createSuite')
const chevrotainParse = require('./chevrotain/pure')
const chevrotainExtendedParse = require('./chevrotain/extended')
const { parse: pegjsParse } = require('./pegjs/pure')
const { parse: pegjsExtendedParse } = require('./pegjs/extended')
const { Parser: JisonParser } = require('./jison/pure').parser
const { Parser: JisonExtendedParser } = require('./jison/extended').parser
const { parse: jjuPureParse } = require('./jju/pure')
const { parse: jjuExtendedParse } = require('./jju/extended')
const { parse: jjuTokenisingParse } = require('./jju/tokenizing')
const jisonParser = new JisonParser()
const jisonExtendedParser = new JisonExtendedParser()
const handbuiltParse = require('./hand-built/pure')
const handbuiltExtendedParse = require('./hand-built/pure')
const astParse = require('json-to-ast')
const JSON5 = require('json5')
const JSON6 = require('json-6')
const { parse: parseWithComments } = require('comment-json')
const { parse: parseThis, tokenize: tokenizeThis } = require('..')
const myna = require('myna-parser')
require('./myna/pure')(myna)
const mynaParse = myna.parsers.json
const { Parser: NearleyParser, Grammar: NearleyGrammar } = require('nearley')
const nearleyJsonGrammar = require('./nearley/pure')
const nearleyParser = new NearleyParser(NearleyGrammar.fromCompiled(nearleyJsonGrammar))
const nearleyOrigin = nearleyParser.save()
const { parse: parseMomoa } = require("@humanwhocodes/momoa");
const parseJson = require("./ryan-grove/pure");
const pkg = require('../package')
const input = JSON.stringify(pkg, undefined, 2)
function parseBuiltIn () {
JSON.parse(input)
}
function parsePureChevrotain () {
chevrotainParse(input)
}
function parseExtendedChevrotain () {
chevrotainExtendedParse(input)
}
function parseHandbuilt () {
handbuiltParse(input)
}
function parseExtendedHandbuilt () {
handbuiltExtendedParse(input)
}
function parsePureJju () {
jjuPureParse(input)
}
function parseExtendedJju () {
jjuExtendedParse(input, { json5: true })
}
function parseTokenisableJju () {
jjuTokenisingParse(input, { json5: true })
}
function parseTokenisingJju () {
jjuTokenisingParse(input, {
tokenize: true,
json5: true
})
}
function parseCommentJson () {
parseWithComments(input)
}
function parseCurrentStandard () {
parseThis(input)
}
function parseCurrentExtended () {
parseThis(input, { mode: 'json5' })
}
function parseCurrentTokenising () {
tokenizeThis(input, { mode: 'json5' })
}
function parseNearley () {
nearleyParser.restore(nearleyOrigin)
nearleyParser.feed(input)
}
function parsePurePegjs () {
pegjsParse(input)
}
function parseExtendedPegjs () {
pegjsExtendedParse(input)
}
function parsePureJison () {
jisonParser.parse(input)
}
function parseExtendedJison () {
jisonExtendedParser.parse(input)
}
function parseJSON5 () {
JSON5.parse(input)
}
function parseJSON6 () {
JSON6.parse(input)
}
function parseAST () {
astParse(input, {
loc: true
})
}
function parseMyna () {
mynaParse(input)
}
function parseMomoaStandard () {
parseMomoa(input)
}
function parseMomoaExtended () {
parseMomoa(input, { mode: 'json5' })
}
function parseRyanGrove () {
parseJson(input)
}
createSuite(`Parsing JSON data ${input.length} characters long using`)
.add('the built-in parser', parseBuiltIn)
.add('the pure chevrotain parser', parsePureChevrotain)
.add('the extended chevrotain parser', parseExtendedChevrotain)
.add('the standard jsonlint parser', parseCurrentStandard)
.add('the extended jsonlint parser', parseCurrentExtended)
.add('the tokenising jsonlint parser', parseCurrentTokenising)
.add('the pure hand-built parser', parseHandbuilt)
.add('the extended hand-built parser', parseExtendedHandbuilt)
.add('the AST parser', parseAST)
.add('the Myna parser', parseMyna)
.add('the pure jju parser', parsePureJju)
.add('the extended jju parser', parseExtendedJju)
.add('the tokenisable jju parser', parseTokenisableJju)
.add('the tokenising jju parser', parseTokenisingJju)
.add('the comments-enabled parser', parseCommentJson)
.add('the pure pegjs parser', parsePurePegjs)
.add('the extended pegjs parser', parseExtendedPegjs)
.add('the pure jison parser', parsePureJison)
.add('the extended jison parser', parseExtendedJison)
.add('the JSON5 parser', parseJSON5)
.add('the JSON6 parser', parseJSON6)
.add('the Nearley parser', parseNearley)
.add('the standard Momoa parser', parseMomoaStandard)
.add('the extended Momoa parser', parseMomoaExtended)
.add('the Ryan Grove parser', parseRyanGrove)
.start()