-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.js
88 lines (78 loc) · 2.64 KB
/
bundle.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
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
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('arcsecond')) :
typeof define === 'function' && define.amd ? define(['exports', 'arcsecond'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pounceParser = {}, global.arcsecond));
}(this, (function (exports, arcsecond) { 'use strict';
const list = arcsecond.coroutine(function* () {
yield arcsecond.char('[');
yield arcsecond.optionalWhitespace;
const words = yield sepBySpace(word);
yield arcsecond.optionalWhitespace;
yield arcsecond.char(']');
return words;
});
const comicSwears = arcsecond.choice([
arcsecond.char('~'),
arcsecond.char('!'),
arcsecond.char('@'),
// char('#'),
arcsecond.char('$'),
arcsecond.char('%'),
arcsecond.char('^'),
arcsecond.char('&'),
arcsecond.char('*'),
arcsecond.char('_'),
arcsecond.char('-'),
arcsecond.char('+'),
arcsecond.char('='),
arcsecond.char('.'),
arcsecond.char('?'),
arcsecond.char('/'),
arcsecond.char('|'),
arcsecond.char('.'),
]);
const basicStr = arcsecond.sequenceOf([
arcsecond.optionalWhitespace,
arcsecond.many1(arcsecond.choice([
arcsecond.letter,
arcsecond.digit,
comicSwears
])).map(r => r.join(''))
]).map(r => r[1]);
const word = arcsecond.choice([
//tapParser(log(2)),
list,
basicStr,
]);
// util
const sepBySpace = valueParser => arcsecond.coroutine(function* () {
const results = [];
while (true) {
const value = yield arcsecond.either(valueParser);
if (value.isError) break;
results.push(value);
const sep = yield arcsecond.either(arcsecond.whitespace);
if (sep.isError) break;
}
return results.map(a => a.value);
});
const log = m1 => m2 => console.log(m1, m2);
const comment = arcsecond.sequenceOf([
arcsecond.char('#'),
// tapParser(log(1)),
arcsecond.many(arcsecond.anyCharExcept(arcsecond.char('\n'))),
arcsecond.tapParser(log(1)),
// choice([char('\n'), endOfInput]),
// tapParser(log(2)),
]).map(r => ([]));
const pounce = arcsecond.coroutine(function* () {
yield arcsecond.optionalWhitespace;
//const program = yield sepBySpace(word);
const program = yield arcsecond.many(arcsecond.choice([comment, sepBySpace(word)]));
yield arcsecond.optionalWhitespace;
return program[0];
});
// // console.log(JSON.stringify(pounce.run(' [ a] a2 [] [b* [-a -123 ] ] ')));
exports.pounce = pounce;
Object.defineProperty(exports, '__esModule', { value: true });
})));